Search in sources :

Example 51 with AssertionInfo

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

the class AbstractRMInterceptor method assertReliability.

/**
 * Asserts all RMAssertion assertions for the current message, regardless their attributes
 * (if there is more than one we have ensured that they are all supported by considering
 * e.g. the minimum acknowledgment interval).
 * @param message the current message
 */
void assertReliability(Message message) {
    AssertionInfoMap aim = message.get(AssertionInfoMap.class);
    Collection<AssertionInfo> ais = RMPolicyUtilities.collectRMAssertions(aim);
    for (AssertionInfo ai : ais) {
        ai.setAsserted(true);
    }
}
Also used : AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 52 with AssertionInfo

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

the class AbstractPolicySecurityTest method runOutInterceptorAndValidate.

protected Document runOutInterceptorAndValidate(SoapMessage msg, Policy policy, AssertionInfoMap aim, List<QName> assertedOutAssertions, List<QName> notAssertedOutAssertions) throws Exception {
    if (msg.getExchange().getEndpoint() != null && msg.getExchange().getEndpoint().getEndpointInfo().getProperty(TokenStore.class.getName()) == null) {
        msg.put(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE, new MemoryTokenStore());
    }
    this.getOutInterceptor().handleMessage(msg);
    try {
        aim.checkEffectivePolicy(policy);
    } catch (PolicyException e) {
    // Expected but not relevant
    } finally {
        if (assertedOutAssertions != null) {
            for (QName assertionType : assertedOutAssertions) {
                Collection<AssertionInfo> ais = aim.get(assertionType);
                assertNotNull(ais);
                for (AssertionInfo ai : ais) {
                    checkAssertion(aim, assertionType, ai, true);
                }
            }
        }
        if (notAssertedOutAssertions != null) {
            for (QName assertionType : notAssertedOutAssertions) {
                Collection<AssertionInfo> ais = aim.get(assertionType);
                assertNotNull(ais);
                for (AssertionInfo ai : ais) {
                    checkAssertion(aim, assertionType, ai, false);
                }
            }
        }
    }
    return msg.getContent(SOAPMessage.class).getSOAPPart();
}
Also used : MemoryTokenStore(org.apache.cxf.ws.security.tokenstore.MemoryTokenStore) AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) PolicyException(org.apache.cxf.ws.policy.PolicyException) QName(javax.xml.namespace.QName) TokenStore(org.apache.cxf.ws.security.tokenstore.TokenStore) MemoryTokenStore(org.apache.cxf.ws.security.tokenstore.MemoryTokenStore) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 53 with AssertionInfo

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

the class AbstractPolicySecurityTest method checkAssertion.

protected void checkAssertion(AssertionInfoMap aim, QName name, AssertionInfo inf, boolean asserted) {
    boolean pass = true;
    Collection<AssertionInfo> ail = aim.getAssertionInfo(name);
    for (AssertionInfo ai : ail) {
        if (ai.getAssertion().equal(inf.getAssertion()) && !ai.isAsserted() && !inf.getAssertion().isOptional()) {
            pass = false;
        }
    }
    if (asserted) {
        assertTrue(name + " policy erroneously failed.", pass);
    } else {
        assertFalse(name + " policy erroneously asserted.", pass);
    }
}
Also used : AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo)

Example 54 with AssertionInfo

use of org.apache.cxf.ws.policy.AssertionInfo in project tdi-studio-se by Talend.

the class WspPolicyInterceptor method handleMessage.

public void handleMessage(SoapMessage message) throws Fault {
    AssertionInfoMap aim = (AssertionInfoMap) message.get(AssertionInfoMap.class);
    if (null == aim) {
        return;
    }
    QName qname = QNamesCollection.POLICY_WSP;
    Collection<AssertionInfo> ais = (Collection<AssertionInfo>) aim.get(qname);
    if ((null == ais) || (ais.size() == 0)) {
        return;
    }
    for (AssertionInfo ai : ais) {
        ai.setAsserted(true);
    }
}
Also used : AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) QName(javax.xml.namespace.QName) Collection(java.util.Collection) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 55 with AssertionInfo

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

the class PolicyUtilsTest method testAssertClientPolicy.

void testAssertClientPolicy(boolean outbound) {
    Message message = control.createMock(Message.class);
    HTTPClientPolicy ep = new HTTPClientPolicy();
    HTTPClientPolicy cmp = new HTTPClientPolicy();
    cmp.setConnectionTimeout(60000L);
    HTTPClientPolicy icmp = new HTTPClientPolicy();
    icmp.setAllowChunking(false);
    AssertionInfo eai = getClientPolicyAssertionInfo(ep);
    AssertionInfo cmai = getClientPolicyAssertionInfo(cmp);
    AssertionInfo icmai = getClientPolicyAssertionInfo(icmp);
    AssertionInfoMap aim = new AssertionInfoMap(CastUtils.cast(Collections.EMPTY_LIST, PolicyAssertion.class));
    Collection<AssertionInfo> ais = new ArrayList<>();
    ais.add(eai);
    ais.add(cmai);
    ais.add(icmai);
    aim.put(new ClientPolicyCalculator().getDataClassName(), ais);
    EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim);
    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();
    PolicyDataEngine pde = new PolicyDataEngineImpl(null);
    pde.assertMessage(message, ep, new ClientPolicyCalculator());
    assertTrue(eai.isAsserted());
    assertTrue(cmai.isAsserted());
    assertTrue(icmai.isAsserted());
    control.verify();
}
Also used : Exchange(org.apache.cxf.message.Exchange) PolicyAssertion(org.apache.cxf.ws.policy.PolicyAssertion) AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) Message(org.apache.cxf.message.Message) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) ArrayList(java.util.ArrayList) PolicyDataEngine(org.apache.cxf.policy.PolicyDataEngine) PolicyDataEngineImpl(org.apache.cxf.ws.policy.PolicyDataEngineImpl) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap) ClientPolicyCalculator(org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator)

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