Search in sources :

Example 91 with Policy

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;
}
Also used : Policy(org.apache.neethi.Policy) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap) SoapMessage(org.apache.cxf.binding.soap.SoapMessage)

Example 92 with Policy

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);
                }
            }
        }
    }
}
Also used : Policy(org.apache.neethi.Policy) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration)

Example 93 with Policy

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");
        }
    }
}
Also used : Policy(org.apache.neethi.Policy) Iterator(java.util.Iterator) List(java.util.List) OMElement(org.apache.axiom.om.OMElement) XmlPrimtiveAssertion(org.apache.neethi.builders.xml.XmlPrimtiveAssertion)

Example 94 with Policy

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;
}
Also used : Policy(org.apache.neethi.Policy) OMElement(org.apache.axiom.om.OMElement) Throttle(org.apache.synapse.commons.throttle.core.Throttle)

Example 95 with Policy

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;
}
Also used : Policy(org.apache.neethi.Policy) All(org.apache.neethi.All) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) DefaultSymmetricBinding(org.apache.cxf.ws.security.trust.DefaultSymmetricBinding) ExactlyOne(org.apache.neethi.ExactlyOne) AlgorithmSuite(org.apache.wss4j.policy.model.AlgorithmSuite) X509Token(org.apache.wss4j.policy.model.X509Token) Header(org.apache.wss4j.policy.model.Header) SignedParts(org.apache.wss4j.policy.model.SignedParts) ProtectionToken(org.apache.wss4j.policy.model.ProtectionToken)

Aggregations

Policy (org.apache.neethi.Policy)122 Test (org.junit.Test)47 Assertion (org.apache.neethi.Assertion)27 QName (javax.xml.namespace.QName)23 ArrayList (java.util.ArrayList)21 All (org.apache.neethi.All)18 ExactlyOne (org.apache.neethi.ExactlyOne)18 Message (org.apache.cxf.message.Message)15 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)14 Element (org.w3c.dom.Element)13 Bus (org.apache.cxf.Bus)12 PrimitiveAssertion (org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion)12 List (java.util.List)9 Interceptor (org.apache.cxf.interceptor.Interceptor)9 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)9 HashMap (java.util.HashMap)7 OMElement (org.apache.axiom.om.OMElement)7 MessageImpl (org.apache.cxf.message.MessageImpl)7 ReferenceResolver (org.apache.cxf.ws.policy.attachment.reference.ReferenceResolver)6 InputStream (java.io.InputStream)5