本文整理汇总了Java中org.apache.neethi.PolicyEngine类的典型用法代码示例。如果您正苦于以下问题:Java PolicyEngine类的具体用法?Java PolicyEngine怎么用?Java PolicyEngine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PolicyEngine类属于org.apache.neethi包,在下文中一共展示了PolicyEngine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSignOnlyPolicy
import org.apache.neethi.PolicyEngine; //导入依赖的package包/类
public static Policy getSignOnlyPolicy() throws IdentityException {
Policy policy;
try {
OMElement policyOM = AXIOMUtil.stringToOM(policyString);
PolicyEngine policyEngine = new PolicyEngine();
policy = policyEngine.getPolicy(policyOM);
} catch (Exception e) {
String msg = "error building policy from " + policyString;
log.error(msg);
throw IdentityException.error(msg, e);
}
return policy;
}
示例2: getSignOnlyPolicy
import org.apache.neethi.PolicyEngine; //导入依赖的package包/类
public static Policy getSignOnlyPolicy() throws RegistryException {
Policy policy;
try {
OMElement policyOM = AXIOMUtil.stringToOM(policyString);
policy = PolicyEngine.getPolicy(policyOM);
} catch (Exception e) {
String msg = "error building policy from " + policyString;
log.error(msg);
throw new RegistryException(msg, e);
}
return policy;
}
示例3: getPolicy
import org.apache.neethi.PolicyEngine; //导入依赖的package包/类
private static Policy getPolicy(String key, Registry registry)
throws DiscoveryException, RegistryException {
if (!registry.resourceExists(key)) {
throw new DiscoveryException("Policy resource " + key + " does not exist");
}
Resource policy = registry.get(key);
ByteArrayInputStream in = new ByteArrayInputStream((byte[]) policy.getContent());
try {
StAXOMBuilder builder = new StAXOMBuilder(in);
Policy secPolicy = PolicyEngine.getPolicy(builder.getDocumentElement());
policy.discard();
return secPolicy;
} catch (XMLStreamException e) {
policy.discard();
throw new DiscoveryException("Error while loading the policy from resource " + key, e);
}
}
示例4: readExternalGlobalPolicy
import org.apache.neethi.PolicyEngine; //导入依赖的package包/类
/**
* An external policy can be configured using a parameter in the axis2.xml which points to the
* absolute path of the policy file. This method reads the policy file and creates a
* PolicySubject.
*
* @param axisConfig - AxisConfiguration instance
* @return - PolicySubject instance if the file found. Otherwise null..
*/
public static PolicySubject readExternalGlobalPolicy(AxisConfiguration axisConfig) {
PolicySubject extPolicySubject = null;
// read the global throttle parameter from axisConfig
Parameter globalThrottlePolicyParam = axisConfig
.getParameter(ThrottleConstants.GLOBAL_THROTTLE_PATH_PARAM);
if (globalThrottlePolicyParam != null &&
!"".equals(globalThrottlePolicyParam.getValue())) {
// If the path found, try to read the file
String policyPath = (String) globalThrottlePolicyParam.getValue();
File policyFile = new File(policyPath);
if (policyFile.exists()) {
try {
// If the file exists, try to build the policy
Policy globalPolicy = PolicyEngine.getPolicy(new FileInputStream(policyFile));
extPolicySubject = new PolicySubject();
extPolicySubject.attachPolicy(globalPolicy);
} catch (FileNotFoundException e) {
log.error("Error while reading global policy file..", e);
}
}
}
return extPolicySubject;
}
示例5: handleSecurityProxy
import org.apache.neethi.PolicyEngine; //导入依赖的package包/类
/**
* Helper method to handle security policies.
*
* @param file deployment data file.
* @param axisService to be modified.
* @return true if security is enabled, false otherwise.
* @throws DataServiceFault
*/
private boolean handleSecurityProxy(DeploymentFileData file, AxisService axisService) throws DataServiceFault{
try {
boolean secEnabled = false;
StAXOMBuilder builder = new StAXOMBuilder(new FileInputStream(file.getFile().getAbsoluteFile()));
OMElement documentElement = builder.getDocumentElement();
OMElement enableSecElement= documentElement.getFirstChildWithName(new QName(DBSFields.ENABLESEC));
if (enableSecElement != null) {
secEnabled = true;
}
OMElement policyElement= documentElement.getFirstChildWithName(new QName(DBSFields.POLICY));
if (policyElement != null) {
String policyKey = policyElement.getAttributeValue(new QName(DBSFields.POLICY_KEY));
if (null == policyKey) {
throw new DataServiceFault("Policy key element should contain a policy key in " + file.getFile().getName());
}
Policy policy = PolicyEngine.getPolicy(DBUtils.getInputStreamFromPath(policyKey));
axisService.getPolicySubject().attachPolicy(policy);
}
return secEnabled;
}catch (Exception e) {
throw new DataServiceFault(e, "Error in processing security policy");
}
}
示例6: loadPolicy
import org.apache.neethi.PolicyEngine; //导入依赖的package包/类
private Policy loadPolicy(Resource resource) throws org.wso2.carbon.registry.api.RegistryException, XMLStreamException {
InputStream in = resource.getContentStream();
XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
xmlInputFactory.setProperty("javax.xml.stream.isSupportingExternalEntities", false);
XMLStreamReader parser = xmlInputFactory.createXMLStreamReader(in);
StAXOMBuilder builder = new StAXOMBuilder(parser);
OMElement policyElement = builder.getDocumentElement();
return PolicyEngine.getPolicy(policyElement);
}
示例7: applySecurity
import org.apache.neethi.PolicyEngine; //导入依赖的package包/类
public void applySecurity(String serviceName, String scenarioId, KerberosConfigData kerberosConfigurations)
throws SecurityConfigException {
if (kerberosConfigurations == null) {
log.error("Kerberos configurations provided are invalid.");
throw new SecurityConfigException("Kerberos configuration parameters are null. " +
"Please specify valid kerberos configurations.");
}
AxisService service = axisConfig.getServiceForActivation(serviceName);
if (service == null) {
throw new SecurityConfigException("nullService");
}
// Disable security if already a policy is applied
this.disableSecurityOnService(serviceName); //todo fix the method
OMElement policyElement = loadPolicyAsXML(scenarioId, null);
OMElement carbonSecConfigs = addUserParameters(policyElement, null, null, null, kerberosConfigurations,
false, null);
policyElement.addChild(buildRampartConfigXML(null, null, kerberosConfigurations));
Policy policy = PolicyEngine.getPolicy(policyElement);
//service.getPolicySubject().attachPolicy(policy);
try {
persistPolicy(service, policyElement, policy.getId());
applyPolicy(service, policy, carbonSecConfigs);
this.getPOXCache().remove(serviceName);
} catch (Exception e) {
throw new SecurityConfigException("Error while persisting policy in registry ", e);
}
}
示例8: loadPolicy
import org.apache.neethi.PolicyEngine; //导入依赖的package包/类
private Policy loadPolicy(Resource resource) throws org.wso2.carbon.registry.api.RegistryException,
XMLStreamException {
InputStream in = resource.getContentStream();
XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
XMLStreamReader parser = xmlInputFactory.createXMLStreamReader(in);
StAXOMBuilder builder = new StAXOMBuilder(parser);
OMElement policyElement = builder.getDocumentElement();
return PolicyEngine.getPolicy(policyElement);
}
示例9: getSecurityPolicy
import org.apache.neethi.PolicyEngine; //导入依赖的package包/类
public static Policy getSecurityPolicy() {
String policyString = " <wsp:Policy wsu:Id=\"UTOverTransport\" xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\"\n" +
" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">\n" +
" <wsp:ExactlyOne>\n" +
" <wsp:All>\n" +
" <sp:TransportBinding xmlns:sp=\"http://schemas.xmlsoap.org/ws/2005/07/securitypolicy\">\n" +
" <wsp:Policy>\n" +
" <sp:TransportToken>\n" +
" <wsp:Policy>\n" +
" <sp:HttpsToken RequireClientCertificate=\"true\"/>\n" +
" </wsp:Policy>\n" +
" </sp:TransportToken>\n" +
" <sp:AlgorithmSuite>\n" +
" <wsp:Policy>\n" +
" <sp:Basic256/>\n" +
" </wsp:Policy>\n" +
" </sp:AlgorithmSuite>\n" +
" <sp:Layout>\n" +
" <wsp:Policy>\n" +
" <sp:Lax/>\n" +
" </wsp:Policy>\n" +
" </sp:Layout>\n" +
" <sp:IncludeTimestamp/>\n" +
" </wsp:Policy>\n" +
" </sp:TransportBinding>\n" +
" </wsp:All>\n" +
" </wsp:ExactlyOne>\n" +
" </wsp:Policy>";
return PolicyEngine.getPolicy(new ByteArrayInputStream(policyString.getBytes()));
}
示例10: loadPolicy
import org.apache.neethi.PolicyEngine; //导入依赖的package包/类
private static Policy loadPolicy(String xmlPath, String clientKey, String userName)
throws Exception {
StAXOMBuilder builder = new StAXOMBuilder(xmlPath);
Policy policy = PolicyEngine.getPolicy(builder.getDocumentElement());
RampartConfig rc = new RampartConfig();
rc.setUser(userName);
rc.setUserCertAlias("wso2carbon");
rc.setEncryptionUser("wso2carbon");
rc.setPwCbClass(SecurityWithServiceDescriptorTest.class.getName());
CryptoConfig sigCryptoConfig = new CryptoConfig();
sigCryptoConfig.setProvider("org.apache.ws.security.components.crypto.Merlin");
Properties prop1 = new Properties();
prop1.put("org.apache.ws.security.crypto.merlin.keystore.type", "JKS");
prop1.put("org.apache.ws.security.crypto.merlin.file", clientKey);
prop1.put("org.apache.ws.security.crypto.merlin.keystore.password", "wso2carbon");
sigCryptoConfig.setProp(prop1);
CryptoConfig encrCryptoConfig = new CryptoConfig();
encrCryptoConfig.setProvider("org.apache.ws.security.components.crypto.Merlin");
Properties prop2 = new Properties();
prop2.put("org.apache.ws.security.crypto.merlin.keystore.type", "JKS");
prop2.put("org.apache.ws.security.crypto.merlin.file", clientKey);
prop2.put("org.apache.ws.security.crypto.merlin.keystore.password", "wso2carbon");
encrCryptoConfig.setProp(prop2);
rc.setSigCryptoConfig(sigCryptoConfig);
rc.setEncrCryptoConfig(encrCryptoConfig);
policy.addAssertion(rc);
return policy;
}
示例11: processPolicyElements
import org.apache.neethi.PolicyEngine; //导入依赖的package包/类
protected void processPolicyElements(Iterator policyElements,
PolicySubject policySubject) {
while (policyElements.hasNext()) {
Policy p = PolicyEngine
.getPolicy((OMElement) policyElements.next());
policySubject.attachPolicy(p);
}
}
示例12: processPolicyRefElements
import org.apache.neethi.PolicyEngine; //导入依赖的package包/类
protected void processPolicyRefElements(Iterator policyRefElements,
PolicySubject policySubject) {
while (policyRefElements.hasNext()) {
PolicyReference policyReference = PolicyEngine
.getPolicyReference((OMElement) policyRefElements.next());
policySubject.attachPolicyReference(policyReference);
}
}
示例13: getPolicyComponentFromOMElement
import org.apache.neethi.PolicyEngine; //导入依赖的package包/类
public static PolicyComponent getPolicyComponentFromOMElement(
OMElement policyComponent) throws IllegalArgumentException {
if (Constants.Q_ELEM_POLICY.equals(policyComponent.getQName())) {
return PolicyEngine.getPolicy(policyComponent);
} else if (policyComponent.getQName().equals(
new QName(Constants.URI_POLICY_NS, Constants.ELEM_POLICY_REF))) {
return PolicyEngine.getPolicyReference(policyComponent);
} else {
throw new IllegalArgumentException(
"Agrument is neither a <wsp:Policy> nor a <wsp:PolicyReference> element");
}
}
示例14: getPolicyFromOMElement
import org.apache.neethi.PolicyEngine; //导入依赖的package包/类
public static Policy getPolicyFromOMElement(OMElement policyElement) {
if (Constants.Q_ELEM_POLICY.equals(policyElement.getQName())) {
return PolicyEngine.getPolicy(policyElement);
} else {
throw new IllegalArgumentException(
"argument is not a <wsp:Policy ..> element");
}
}
示例15: getPolicyReferenceFromOMElement
import org.apache.neethi.PolicyEngine; //导入依赖的package包/类
public static PolicyReference getPolicyReferenceFromOMElement(
OMElement policyRefElement) {
if (Constants.URI_POLICY_NS.equals(policyRefElement.getNamespace()
.getNamespaceURI())
&& Constants.ELEM_POLICY_REF.equals(policyRefElement
.getLocalName())) {
return PolicyEngine.getPolicyReference(policyRefElement);
} else {
throw new IllegalArgumentException(
"argument is not a <wsp:PolicyReference> element");
}
}