Search in sources :

Example 6 with Assertion

use of org.apache.neethi.Assertion in project cxf by apache.

the class SHA512PolicyLoader method getAlgorithmSuite.

public AlgorithmSuite getAlgorithmSuite(Bus bus, SPConstants.SPVersion version, Policy nestedPolicy) {
    AssertionBuilderRegistry reg = bus.getExtension(AssertionBuilderRegistry.class);
    if (reg != null) {
        String ns = "http://cxf.apache.org/custom/security-policy";
        final Map<QName, Assertion> assertions = new HashMap<>();
        QName qName = new QName(ns, "Basic128RsaSha512");
        assertions.put(qName, new PrimitiveAssertion(qName));
        reg.registerBuilder(new PrimitiveAssertionBuilder(assertions.keySet()) {

            public Assertion build(Element element, AssertionBuilderFactory fact) {
                if (XMLPrimitiveAssertionBuilder.isOptional(element) || XMLPrimitiveAssertionBuilder.isIgnorable(element)) {
                    return super.build(element, fact);
                }
                QName q = new QName(element.getNamespaceURI(), element.getLocalName());
                return assertions.get(q);
            }
        });
    }
    return new SHA512AlgorithmSuite(version, nestedPolicy);
}
Also used : AssertionBuilderRegistry(org.apache.cxf.ws.policy.AssertionBuilderRegistry) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) Element(org.w3c.dom.Element) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) Assertion(org.apache.neethi.Assertion) AbstractSecurityAssertion(org.apache.wss4j.policy.model.AbstractSecurityAssertion) AssertionBuilderFactory(org.apache.neethi.AssertionBuilderFactory) PrimitiveAssertionBuilder(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertionBuilder) XMLPrimitiveAssertionBuilder(org.apache.neethi.builders.xml.XMLPrimitiveAssertionBuilder)

Example 7 with Assertion

use of org.apache.neethi.Assertion in project cxf by apache.

the class AddressingAssertionBuilder method build.

public Assertion build(Element elem, AssertionBuilderFactory factory) {
    String localName = elem.getLocalName();
    QName qn = new QName(elem.getNamespaceURI(), localName);
    boolean optional = false;
    Attr attribute = PolicyConstants.findOptionalAttribute(elem);
    if (attribute != null) {
        optional = Boolean.valueOf(attribute.getValue());
    }
    if (MetadataConstants.ADDRESSING_ASSERTION_QNAME.equals(qn) || MetadataConstants.ADDRESSING_ASSERTION_QNAME_0705.equals(qn)) {
        Assertion nap = new XMLPrimitiveAssertionBuilder() {

            public Assertion newPrimitiveAssertion(Element element, Map<QName, String> mp) {
                return new PrimitiveAssertion(MetadataConstants.ADDRESSING_ASSERTION_QNAME, isOptional(element), isIgnorable(element), mp);
            }

            public Assertion newPolicyContainingAssertion(Element element, Map<QName, String> mp, Policy policy) {
                return new PolicyContainingPrimitiveAssertion(MetadataConstants.ADDRESSING_ASSERTION_QNAME, isOptional(element), isIgnorable(element), mp, policy);
            }
        }.build(elem, factory);
        if (!(nap instanceof PolicyContainingPrimitiveAssertion || nap instanceof org.apache.neethi.builders.PrimitiveAssertion)) {
            // this happens when neethi fails to recognize the specified addressing policy element
            LOG.warning("Unable to recognize the addressing policy");
        }
        return nap;
    } else if (MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME.equals(qn) || MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME_0705.equals(qn)) {
        return new PrimitiveAssertion(MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME, optional);
    } else if (MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME.getLocalPart().equals(localName) || MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME_0705.getLocalPart().equals(localName)) {
        return new PrimitiveAssertion(MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME, optional);
    }
    return null;
}
Also used : Policy(org.apache.neethi.Policy) QName(javax.xml.namespace.QName) PolicyContainingPrimitiveAssertion(org.apache.neethi.builders.PolicyContainingPrimitiveAssertion) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) Element(org.w3c.dom.Element) PolicyContainingPrimitiveAssertion(org.apache.neethi.builders.PolicyContainingPrimitiveAssertion) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) Assertion(org.apache.neethi.Assertion) Attr(org.w3c.dom.Attr) XMLPrimitiveAssertionBuilder(org.apache.neethi.builders.xml.XMLPrimitiveAssertionBuilder) PolicyContainingPrimitiveAssertion(org.apache.neethi.builders.PolicyContainingPrimitiveAssertion)

Example 8 with Assertion

use of org.apache.neethi.Assertion in project cxf by apache.

the class RSPAssertionBuilder method build.

/**
 * @see org.apache.neethi.builders.AssertionBuilder#build(org.w3c.dom.Element,
 *  org.apache.neethi.AssertionBuilderFactory)
 */
public Assertion build(Element elem, AssertionBuilderFactory factory) throws IllegalArgumentException {
    Assertion assertion = null;
    if (RSP_NAMESPACE.equals(elem.getNamespaceURI()) && CONFORMANT_NAME.equals(elem.getLocalName())) {
        boolean optional = XMLPrimitiveAssertionBuilder.isOptional(elem);
        assertion = new PrimitiveAssertion(CONFORMANT_QNAME, optional);
    }
    return assertion;
}
Also used : PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) Assertion(org.apache.neethi.Assertion)

Example 9 with Assertion

use of org.apache.neethi.Assertion in project cxf by apache.

the class MC11AssertionBuilder method build.

/**
 * @see org.apache.neethi.builders.AssertionBuilder#build(org.w3c.dom.Element,
 *  org.apache.neethi.AssertionBuilderFactory)
 */
public Assertion build(Element elem, AssertionBuilderFactory factory) throws IllegalArgumentException {
    Assertion assertion = null;
    if (WSMC_NAMESPACE.equals(elem.getNamespaceURI()) && MCSUPPORTED_NAME.equals(elem.getLocalName())) {
        boolean optional = XMLPrimitiveAssertionBuilder.isOptional(elem);
        assertion = new PrimitiveAssertion(MCSUPPORTED_QNAME, optional);
    }
    return assertion;
}
Also used : PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) Assertion(org.apache.neethi.Assertion)

Example 10 with Assertion

use of org.apache.neethi.Assertion in project cxf by apache.

the class PolicyLoggingInterceptor method handleMessage.

public void handleMessage(Message message) throws Fault {
    EndpointInfo ei = message.getExchange().getEndpoint().getEndpointInfo();
    BindingOperationInfo boi = message.getExchange().getBindingOperationInfo();
    LOG.fine("Getting effective server request policy for endpoint " + ei + " and binding operation " + boi);
    EffectivePolicy ep = bus.getExtension(PolicyEngine.class).getEffectiveServerRequestPolicy(ei, boi, message);
    for (Iterator<List<Assertion>> it = ep.getPolicy().getAlternatives(); it.hasNext(); ) {
        Collection<Assertion> as = it.next();
        LOG.fine("Checking alternative with " + as.size() + " assertions.");
        for (Assertion a : as) {
            LOG.fine("Assertion: " + a.getClass().getName());
            HTTPServerPolicy p = (JaxbAssertion.cast(a, HTTPServerPolicy.class)).getData();
            LOG.fine("server policy: " + ServerPolicyCalculator.toString(p));
        }
    }
}
Also used : EffectivePolicy(org.apache.cxf.ws.policy.EffectivePolicy) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) HTTPServerPolicy(org.apache.cxf.transports.http.configuration.HTTPServerPolicy) JaxbAssertion(org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion) Assertion(org.apache.neethi.Assertion) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) List(java.util.List)

Aggregations

Assertion (org.apache.neethi.Assertion)64 Policy (org.apache.neethi.Policy)27 Message (org.apache.cxf.message.Message)25 Test (org.junit.Test)25 ArrayList (java.util.ArrayList)23 QName (javax.xml.namespace.QName)21 Interceptor (org.apache.cxf.interceptor.Interceptor)19 PrimitiveAssertion (org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion)19 PolicyContainingAssertion (org.apache.neethi.PolicyContainingAssertion)9 Element (org.w3c.dom.Element)9 MessageImpl (org.apache.cxf.message.MessageImpl)7 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)7 All (org.apache.neethi.All)7 ExactlyOne (org.apache.neethi.ExactlyOne)7 Bus (org.apache.cxf.Bus)6 InterceptorChain (org.apache.cxf.interceptor.InterceptorChain)6 PolicyEngine (org.apache.cxf.ws.policy.PolicyEngine)6 PolicyContainingPrimitiveAssertion (org.apache.neethi.builders.PolicyContainingPrimitiveAssertion)6 XMLPrimitiveAssertionBuilder (org.apache.neethi.builders.xml.XMLPrimitiveAssertionBuilder)6 List (java.util.List)5