Search in sources :

Example 56 with AssertionInfoMap

use of org.apache.cxf.ws.policy.AssertionInfoMap in project cxf by apache.

the class MAPAggregatorImpl method assertAddressing.

/**
 * Asserts all Addressing assertions for the current message, regardless their nested
 * Policies.
 * @param message the current message
 */
private void assertAddressing(Message message, EndpointReferenceType replyTo, EndpointReferenceType faultTo) {
    AssertionInfoMap aim = message.get(AssertionInfoMap.class);
    if (null == aim) {
        return;
    }
    if (faultTo == null) {
        faultTo = replyTo;
    }
    boolean anonReply = ContextUtils.isGenericAddress(replyTo);
    boolean anonFault = ContextUtils.isGenericAddress(faultTo);
    boolean onlyAnonymous = anonReply && anonFault;
    boolean hasAnonymous = anonReply || anonFault;
    QName[] types = new QName[] { MetadataConstants.ADDRESSING_ASSERTION_QNAME, MetadataConstants.USING_ADDRESSING_2004_QNAME, MetadataConstants.USING_ADDRESSING_2005_QNAME, MetadataConstants.USING_ADDRESSING_2006_QNAME };
    for (QName type : types) {
        assertAssertion(aim, type);
        // ADDRESSING_ASSERTION is normalized, so check only the default namespace
        if (type.equals(MetadataConstants.ADDRESSING_ASSERTION_QNAME)) {
            if (onlyAnonymous) {
                assertAssertion(aim, MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME);
            } else if (!hasAnonymous) {
                assertAssertion(aim, MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME);
            }
        }
    }
    if (!MessageUtils.isRequestor(message) && !MessageUtils.isOutbound(message)) {
        // need to throw an appropriate fault for these
        Collection<AssertionInfo> aicNonAnon = aim.getAssertionInfo(MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME);
        Collection<AssertionInfo> aicNonAnon2 = aim.getAssertionInfo(MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME_0705);
        Collection<AssertionInfo> aicAnon = aim.getAssertionInfo(MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME);
        Collection<AssertionInfo> aicAnon2 = aim.getAssertionInfo(MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME_0705);
        boolean hasAnon = (aicAnon != null && !aicAnon.isEmpty()) || (aicAnon2 != null && !aicAnon2.isEmpty());
        boolean hasNonAnon = (aicNonAnon != null && !aicNonAnon.isEmpty()) || (aicNonAnon2 != null && !aicNonAnon2.isEmpty());
        if (hasAnonymous && hasNonAnon && !hasAnon) {
            message.put(FaultMode.class, FaultMode.UNCHECKED_APPLICATION_FAULT);
            if (isSOAP12(message)) {
                SoapFault soap12Fault = new SoapFault("Found anonymous address but non-anonymous required", Soap12.getInstance().getSender());
                soap12Fault.addSubCode(new QName(Names.WSA_NAMESPACE_NAME, "OnlyNonAnonymousAddressSupported"));
                throw soap12Fault;
            }
            throw new SoapFault("Found anonymous address but non-anonymous required", new QName(Names.WSA_NAMESPACE_NAME, "OnlyNonAnonymousAddressSupported"));
        } else if (!onlyAnonymous && !hasNonAnon && hasAnon) {
            message.put(FaultMode.class, FaultMode.UNCHECKED_APPLICATION_FAULT);
            if (isSOAP12(message)) {
                SoapFault soap12Fault = new SoapFault("Found non-anonymous address but only anonymous supported", Soap12.getInstance().getSender());
                soap12Fault.addSubCode(new QName(Names.WSA_NAMESPACE_NAME, "OnlyAnonymousAddressSupported"));
                throw soap12Fault;
            }
            throw new SoapFault("Found non-anonymous address but only anonymous supported", new QName(Names.WSA_NAMESPACE_NAME, "OnlyAnonymousAddressSupported"));
        }
    }
}
Also used : FaultMode(org.apache.cxf.message.FaultMode) AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) SoapFault(org.apache.cxf.binding.soap.SoapFault) QName(javax.xml.namespace.QName) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 57 with AssertionInfoMap

use of org.apache.cxf.ws.policy.AssertionInfoMap in project cxf by apache.

the class MAPAggregatorImpl method handleMessage.

/**
 * Invoked for normal processing of inbound and outbound messages.
 *
 * @param message the current message
 */
public void handleMessage(Message message) {
    if (!MessageUtils.getContextualBoolean(message, ADDRESSING_DISABLED, false)) {
        mediate(message, ContextUtils.isFault(message));
    } else {
        // addressing is completely disabled manually, we need to assert the
        // assertions as the user is in control of those
        AssertionInfoMap aim = message.get(AssertionInfoMap.class);
        if (null == aim) {
            return;
        }
        QName[] types = new QName[] { MetadataConstants.ADDRESSING_ASSERTION_QNAME, MetadataConstants.USING_ADDRESSING_2004_QNAME, MetadataConstants.USING_ADDRESSING_2005_QNAME, MetadataConstants.USING_ADDRESSING_2006_QNAME, MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME, MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME, MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME_0705, MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME_0705 };
        for (QName type : types) {
            assertAssertion(aim, type);
        }
    }
}
Also used : QName(javax.xml.namespace.QName) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 58 with AssertionInfoMap

use of org.apache.cxf.ws.policy.AssertionInfoMap in project cxf by apache.

the class PluggablePolicyValidatorTest method runInInterceptorAndValidate.

private void runInInterceptorAndValidate(String document, String policyDocument, List<QName> assertedInAssertions, List<QName> notAssertedInAssertions, List<CoverageType> types, Map<QName, SecurityPolicyValidator> validators) throws Exception {
    final Policy policy = this.policyBuilder.getPolicy(this.readDocument(policyDocument).getDocumentElement());
    final Document doc = this.readDocument(document);
    final AssertionInfoMap aim = new AssertionInfoMap(policy);
    this.runInInterceptorAndValidateWss(doc, aim, types, validators);
    try {
        aim.checkEffectivePolicy(policy);
    } catch (PolicyException e) {
    // Expected but not relevant
    } finally {
        if (assertedInAssertions != null) {
            for (QName assertionType : assertedInAssertions) {
                Collection<AssertionInfo> ais = aim.get(assertionType);
                assertNotNull(ais);
                for (AssertionInfo ai : ais) {
                    checkAssertion(aim, assertionType, ai, true);
                }
            }
        }
        if (notAssertedInAssertions != null) {
            for (QName assertionType : notAssertedInAssertions) {
                Collection<AssertionInfo> ais = aim.get(assertionType);
                assertNotNull(ais);
                for (AssertionInfo ai : ais) {
                    checkAssertion(aim, assertionType, ai, false);
                }
            }
        }
    }
}
Also used : Policy(org.apache.neethi.Policy) AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) PolicyException(org.apache.cxf.ws.policy.PolicyException) QName(javax.xml.namespace.QName) Document(org.w3c.dom.Document) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 59 with AssertionInfoMap

use of org.apache.cxf.ws.policy.AssertionInfoMap 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 60 with AssertionInfoMap

use of org.apache.cxf.ws.policy.AssertionInfoMap in project cxf by apache.

the class AbstractPolicySecurityTest method runInInterceptorAndValidate.

protected void runInInterceptorAndValidate(Document document, Policy policy, List<QName> assertedInAssertions, List<QName> notAssertedInAssertions, List<CoverageType> types) throws Exception {
    final AssertionInfoMap aim = new AssertionInfoMap(policy);
    this.runInInterceptorAndValidateWss(document, aim, types);
    try {
        aim.checkEffectivePolicy(policy);
    } catch (PolicyException e) {
    // Expected but not relevant
    } finally {
        if (assertedInAssertions != null) {
            for (QName assertionType : assertedInAssertions) {
                Collection<AssertionInfo> ais = aim.get(assertionType);
                assertNotNull(ais);
                for (AssertionInfo ai : ais) {
                    checkAssertion(aim, assertionType, ai, true);
                }
            }
        }
        if (notAssertedInAssertions != null) {
            for (QName assertionType : notAssertedInAssertions) {
                Collection<AssertionInfo> ais = aim.get(assertionType);
                assertNotNull(ais);
                for (AssertionInfo ai : ais) {
                    checkAssertion(aim, assertionType, ai, false);
                }
            }
        }
    }
}
Also used : AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) PolicyException(org.apache.cxf.ws.policy.PolicyException) QName(javax.xml.namespace.QName) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Aggregations

AssertionInfoMap (org.apache.cxf.ws.policy.AssertionInfoMap)65 AssertionInfo (org.apache.cxf.ws.policy.AssertionInfo)44 QName (javax.xml.namespace.QName)15 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)12 Message (org.apache.cxf.message.Message)10 ArrayList (java.util.ArrayList)9 PolicyException (org.apache.cxf.ws.policy.PolicyException)7 Fault (org.apache.cxf.interceptor.Fault)6 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)6 Element (org.w3c.dom.Element)6 Exchange (org.apache.cxf.message.Exchange)5 TokenStoreException (org.apache.cxf.ws.security.tokenstore.TokenStoreException)5 Policy (org.apache.neethi.Policy)5 Message (org.apache.cxf.common.i18n.Message)4 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)4 SamlAssertionWrapper (org.apache.wss4j.common.saml.SamlAssertionWrapper)4 SOAPException (javax.xml.soap.SOAPException)3 Header (org.apache.cxf.headers.Header)3 PolicyAssertion (org.apache.cxf.ws.policy.PolicyAssertion)3 WSSecUsernameToken (org.apache.wss4j.dom.message.WSSecUsernameToken)3