Search in sources :

Example 56 with AssertionInfo

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

the class PolicyUtilsTest method testAssertServerPolicy.

void testAssertServerPolicy(boolean outbound) {
    Message message = control.createMock(Message.class);
    HTTPServerPolicy ep = new HTTPServerPolicy();
    HTTPServerPolicy mp = new HTTPServerPolicy();
    HTTPServerPolicy cmp = new HTTPServerPolicy();
    cmp.setReceiveTimeout(60000L);
    HTTPServerPolicy icmp = new HTTPServerPolicy();
    icmp.setSuppressClientSendErrors(true);
    AssertionInfo eai = getServerPolicyAssertionInfo(ep);
    AssertionInfo mai = getServerPolicyAssertionInfo(mp);
    AssertionInfo cmai = getServerPolicyAssertionInfo(cmp);
    AssertionInfo icmai = getServerPolicyAssertionInfo(icmp);
    Collection<AssertionInfo> ais = new ArrayList<>();
    ais.add(eai);
    ais.add(mai);
    ais.add(cmai);
    ais.add(icmai);
    AssertionInfoMap aim = new AssertionInfoMap(CastUtils.cast(Collections.EMPTY_LIST, PolicyAssertion.class));
    aim.put(new ServerPolicyCalculator().getDataClassName(), ais);
    EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim).atLeastOnce();
    Exchange ex = control.createMock(Exchange.class);
    EasyMock.expect(message.getExchange()).andReturn(ex).atLeastOnce();
    EasyMock.expect(ex.getOutMessage()).andReturn(outbound ? message : null).atLeastOnce();
    if (!outbound) {
        EasyMock.expect(ex.getOutFaultMessage()).andReturn(null).atLeastOnce();
    }
    control.replay();
    new PolicyDataEngineImpl(null).assertMessage(message, ep, new ServerPolicyCalculator());
    assertTrue(eai.isAsserted());
    assertTrue(mai.isAsserted());
    assertTrue(outbound ? cmai.isAsserted() : !cmai.isAsserted());
    assertTrue(outbound ? icmai.isAsserted() : !icmai.isAsserted());
    control.verify();
}
Also used : Exchange(org.apache.cxf.message.Exchange) PolicyAssertion(org.apache.cxf.ws.policy.PolicyAssertion) HTTPServerPolicy(org.apache.cxf.transports.http.configuration.HTTPServerPolicy) AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) Message(org.apache.cxf.message.Message) ArrayList(java.util.ArrayList) ServerPolicyCalculator(org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator) PolicyDataEngineImpl(org.apache.cxf.ws.policy.PolicyDataEngineImpl) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 57 with AssertionInfo

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

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

the class MTOMPolicyInterceptor method handleMessage.

public void handleMessage(Message message) throws Fault {
    AssertionInfoMap aim = message.get(AssertionInfoMap.class);
    // extract Assertion information
    if (aim != null) {
        Collection<AssertionInfo> ais = aim.get(MetadataConstants.MTOM_ASSERTION_QNAME);
        for (AssertionInfo ai : ais) {
            if (MessageUtils.isRequestor(message)) {
                // just turn on MTOM
                message.put(Message.MTOM_ENABLED, Boolean.TRUE);
                ai.setAsserted(true);
            } else {
                // set mtom enabled and assert the policy if we find an mtom request
                String contentType = (String) message.getExchange().getInMessage().get(Message.CONTENT_TYPE);
                if (contentType != null && contentType.contains("type=\"application/xop+xml\"")) {
                    ai.setAsserted(true);
                    message.put(Message.MTOM_ENABLED, Boolean.TRUE);
                }
            }
        }
    }
}
Also used : AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 59 with AssertionInfo

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

the class AbstractRMInterceptorTest method testAssertReliability.

@Test
public void testAssertReliability() {
    RMInterceptor interceptor = new RMInterceptor();
    Message message = control.createMock(Message.class);
    EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(null);
    AssertionInfoMap aim = control.createMock(AssertionInfoMap.class);
    Collection<AssertionInfo> ais = new ArrayList<>();
    EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim).times(2);
    PolicyAssertion a = control.createMock(PolicyAssertion.class);
    AssertionInfo ai = new AssertionInfo(a);
    EasyMock.expectLastCall();
    control.replay();
    interceptor.assertReliability(message);
    assertFalse(ai.isAsserted());
    aim.put(RM10Constants.RMASSERTION_QNAME, ais);
    interceptor.assertReliability(message);
    assertFalse(ai.isAsserted());
    ais.add(ai);
    interceptor.assertReliability(message);
}
Also used : PolicyAssertion(org.apache.cxf.ws.policy.PolicyAssertion) AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) Message(org.apache.cxf.message.Message) ArrayList(java.util.ArrayList) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap) Test(org.junit.Test)

Example 60 with AssertionInfo

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

the class NegotiationUtils method getAddressingPolicy.

static Assertion getAddressingPolicy(AssertionInfoMap aim, boolean optional) {
    Collection<AssertionInfo> lst = aim.get(MetadataConstants.USING_ADDRESSING_2004_QNAME);
    Assertion assertion = null;
    if (null != lst && !lst.isEmpty()) {
        assertion = lst.iterator().next().getAssertion();
    }
    if (assertion == null) {
        lst = aim.get(MetadataConstants.USING_ADDRESSING_2005_QNAME);
        if (null != lst && !lst.isEmpty()) {
            assertion = lst.iterator().next().getAssertion();
        }
    }
    if (assertion == null) {
        lst = aim.get(MetadataConstants.USING_ADDRESSING_2006_QNAME);
        if (null != lst && !lst.isEmpty()) {
            assertion = lst.iterator().next().getAssertion();
        }
    }
    if (assertion == null) {
        return new PrimitiveAssertion(MetadataConstants.USING_ADDRESSING_2006_QNAME, optional);
    } else if (optional) {
        return new PrimitiveAssertion(assertion.getName(), optional);
    }
    return assertion;
}
Also used : AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) Assertion(org.apache.neethi.Assertion)

Aggregations

AssertionInfo (org.apache.cxf.ws.policy.AssertionInfo)99 AssertionInfoMap (org.apache.cxf.ws.policy.AssertionInfoMap)45 QName (javax.xml.namespace.QName)21 SupportingTokens (org.apache.wss4j.policy.model.SupportingTokens)14 ArrayList (java.util.ArrayList)12 AbstractToken (org.apache.wss4j.policy.model.AbstractToken)12 SamlToken (org.apache.wss4j.policy.model.SamlToken)12 IssuedToken (org.apache.wss4j.policy.model.IssuedToken)10 UsernameToken (org.apache.wss4j.policy.model.UsernameToken)10 KerberosToken (org.apache.wss4j.policy.model.KerberosToken)9 SecurityContextToken (org.apache.wss4j.policy.model.SecurityContextToken)9 X509Token (org.apache.wss4j.policy.model.X509Token)9 Element (org.w3c.dom.Element)9 PolicyException (org.apache.cxf.ws.policy.PolicyException)8 KeyValueToken (org.apache.wss4j.policy.model.KeyValueToken)8 Header (org.apache.wss4j.policy.model.Header)7 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)6 Message (org.apache.cxf.message.Message)6 WSSecurityEngineResult (org.apache.wss4j.dom.engine.WSSecurityEngineResult)6 TLSSessionInfo (org.apache.cxf.security.transport.TLSSessionInfo)5