use of org.apache.neethi.Policy in project cxf by apache.
the class SecurityVerificationOutTest method coachMessage.
private SoapMessage coachMessage(String policyName) throws IOException, ParserConfigurationException, SAXException {
Policy policy = policyBuilder.getPolicy(this.getResourceAsStream(policyName));
AssertionInfoMap aim = new AssertionInfoMap(policy);
SoapMessage message = control.createMock(SoapMessage.class);
EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE);
EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim);
return message;
}
use of org.apache.neethi.Policy in project wso2-synapse by wso2.
the class ThrottleModule method init.
/**
* initialize the module
*/
public void init(ConfigurationContext configContext, AxisModule module) throws AxisFault {
this.configctx = configContext;
initDefaultPolicy();
initDefaultThrottle();
Throttle throttle;
ThrottleObserver observer = new ThrottleObserver(configctx, defaultThrottle);
AxisConfiguration axisConfiguration = configctx.getAxisConfiguration();
axisConfiguration.addObservers(observer);
/**
* Global policy can be configured through the axis2.xml as well. If it is configured, we
* give priority to that policy over the one coming from the module.xml.
* This is done to allow user to modify the global policy without editing the module.xml
* of the throttle module.
*/
PolicySubject policySubject = ThrottleEnguageUtils.readExternalGlobalPolicy(axisConfiguration);
if (policySubject == null) {
policySubject = module.getPolicySubject();
}
if (policySubject != null) {
List list = new ArrayList(policySubject.getAttachedPolicyComponents());
Policy policy = PolicyUtil.getMergedPolicy(list, null);
if (policy != null) {
try {
throttle = ThrottleFactory.createModuleThrottle(policy);
} catch (ThrottleException e) {
log.error("Error was occurred when initiating throttle" + " module " + e.getMessage());
log.info("Throttling will occur using default module policy");
String id = policy.getId();
policySubject.detachPolicyComponent(id);
defaultPolicy.setId(id);
policySubject.attachPolicy(defaultPolicy);
throttle = defaultThrottle;
}
if (throttle != null) {
Map throttles = (Map) configctx.getPropertyNonReplicable(ThrottleConstants.THROTTLES_MAP);
if (throttles == null) {
throttles = new HashMap();
configctx.setNonReplicableProperty(ThrottleConstants.THROTTLES_MAP, throttles);
}
throttle.setId(ThrottleConstants.GLOBAL_THROTTLE_ID);
throttles.put(ThrottleConstants.GLOBAL_THROTTLE_KEY, throttle);
ConcurrentAccessController cac = throttle.getConcurrentAccessController();
if (cac != null) {
String cacKey = ThrottleConstants.THROTTLE_PROPERTY_PREFIX + ThrottleConstants.GLOBAL_THROTTLE_ID + ThrottleConstants.CAC_SUFFIX;
configctx.setProperty(cacKey, cac);
}
}
}
}
}
use of org.apache.neethi.Policy in project wso2-synapse by wso2.
the class ThrottleFactory method fillCallerConfiguration.
/**
* Fills the caller configuration information based on given policy
*
* @param policy Policy instance
* @param callerConfiguration Caller configuration instance
* @throws ThrottleException
*/
private static void fillCallerConfiguration(Policy policy, CallerConfiguration callerConfiguration) throws ThrottleException {
List list = policy.getPolicyComponents();
for (Iterator iterator = list.iterator(); iterator.hasNext(); ) {
Object object = iterator.next();
XmlPrimtiveAssertion primitiveAssertion = (XmlPrimtiveAssertion) object;
OMElement element = primitiveAssertion.getValue();
// Name of the policy assertion
String name = element.getLocalName();
if (name.equals(ThrottleConstants.ALLOW_PARAMETER_NAME)) {
callerConfiguration.setAccessState(ThrottleConstants.ACCESS_ALLOWED);
} else if (name.equals(ThrottleConstants.DENY_PARAMETER_NAME)) {
callerConfiguration.setAccessState(ThrottleConstants.ACCESS_DENIED);
} else if (name.equals(ThrottleConstants.CONTROL_PARAMETER_NAME)) {
callerConfiguration.setAccessState(ThrottleConstants.ACCESS_CONTROLLED);
OMElement controlElement = primitiveAssertion.getValue();
if (controlElement == null) {
handleException("Invalid throttle configuration - " + "Control assertion cannot be empty");
}
Policy controlPolicy = PolicyEngine.getPolicy(controlElement);
if (controlPolicy != null) {
fillControlConfiguration(controlPolicy, callerConfiguration);
} else {
handleException("Invalid throttle configuration - " + "Cannot create a policy object(Control Assertion ) " + "form given policy file ");
}
} else {
handleException("Invalid Throttle" + " Policy configuration");
}
}
}
use of org.apache.neethi.Policy in project wso2-synapse by wso2.
the class ThrottleTestFactory method getThrottle.
public static Throttle getThrottle(String policyStr) throws Exception {
OMElement policyOM = createOMElement(policyStr);
Policy policy = PolicyEngine.getPolicy(policyOM);
Throttle throttle = ThrottleFactory.createModuleThrottle(policy);
return throttle;
}
use of org.apache.neethi.Policy in project cxf by apache.
the class WSSCUnitTest method createSymmetricBindingPolicy.
// mock up a SymmetricBinding policy to talk to the STS
private Policy createSymmetricBindingPolicy() {
// Add Addressing policy
Policy p = new Policy();
ExactlyOne ea = new ExactlyOne();
p.addPolicyComponent(ea);
All all = new All();
all.addPolicyComponent(new PrimitiveAssertion(MetadataConstants.USING_ADDRESSING_2006_QNAME, false));
ea.addPolicyComponent(all);
// X509 Token
final X509Token x509Token = new X509Token(SPConstants.SPVersion.SP12, SPConstants.IncludeTokenType.INCLUDE_TOKEN_NEVER, null, null, null, new Policy());
Policy x509Policy = new Policy();
ExactlyOne x509PolicyEa = new ExactlyOne();
x509Policy.addPolicyComponent(x509PolicyEa);
All x509PolicyAll = new All();
x509PolicyAll.addPolicyComponent(x509Token);
x509PolicyEa.addPolicyComponent(x509PolicyAll);
// AlgorithmSuite
Policy algSuitePolicy = new Policy();
ExactlyOne algSuitePolicyEa = new ExactlyOne();
algSuitePolicy.addPolicyComponent(algSuitePolicyEa);
All algSuitePolicyAll = new All();
algSuitePolicyAll.addAssertion(new PrimitiveAssertion(new QName(SP12Constants.SP_NS, SPConstants.ALGO_SUITE_BASIC128)));
algSuitePolicyEa.addPolicyComponent(algSuitePolicyAll);
AlgorithmSuite algorithmSuite = new AlgorithmSuite(SPConstants.SPVersion.SP12, algSuitePolicy);
// Symmetric Binding
Policy bindingPolicy = new Policy();
ExactlyOne bindingPolicyEa = new ExactlyOne();
bindingPolicy.addPolicyComponent(bindingPolicyEa);
All bindingPolicyAll = new All();
bindingPolicyAll.addPolicyComponent(new ProtectionToken(SPConstants.SPVersion.SP12, x509Policy));
bindingPolicyAll.addPolicyComponent(algorithmSuite);
bindingPolicyAll.addAssertion(new PrimitiveAssertion(SP12Constants.INCLUDE_TIMESTAMP));
bindingPolicyAll.addAssertion(new PrimitiveAssertion(SP12Constants.ONLY_SIGN_ENTIRE_HEADERS_AND_BODY));
bindingPolicyEa.addPolicyComponent(bindingPolicyAll);
DefaultSymmetricBinding binding = new DefaultSymmetricBinding(SPConstants.SPVersion.SP12, bindingPolicy);
binding.setOnlySignEntireHeadersAndBody(true);
binding.setProtectTokens(false);
all.addPolicyComponent(binding);
List<Header> headers = new ArrayList<>();
SignedParts signedParts = new SignedParts(SPConstants.SPVersion.SP12, true, null, headers, false);
all.addPolicyComponent(signedParts);
return p;
}
Aggregations