Search in sources :

Example 1 with AssertionInfoMap

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

the class OpenAMSessionTokenClientInterceptor method assertTokens.

/**
     * Called to assert the relevant tokens. Asserting tokens means asserting that the corresponding policy has been
     * satisfied. This method is called inbound on the client side. This method will assert that the OpenAMSessionAssertion
     * has been satisfied, and also the SupportingToken policy (the OpenAMSessionToken policy always defines a SupportingToken),
     * and, if TLS is being used in the invocation, that the TransportPolicy has also been satisfied, as the OpenAMSessionToken
     * SecurityPolicy binding is always deployed as part of an unprotected binding (i.e. a 'bare' OpenAMSessionToken), or
     * as part of the Transport binding. Note that a TransportToken is the token manifestation of a TransportPolicy binding,
     * so asserting the TransportToken will assert the TransportPolicy.
     * @param message The SoapMessage defining the invocation.
     * @return The OpenAMSessionAssertion corresponding to the OpenAMSessionToken SecurityPolicy element protecting
     * soap-sts instances.
     */
@Override
protected Token assertTokens(SoapMessage message) {
    AssertionInfoMap aim = message.get(AssertionInfoMap.class);
    Collection<AssertionInfo> ais = aim.getAssertionInfo(AMSTSConstants.AM_SESSION_TOKEN_ASSERTION_QNAME);
    Token token = null;
    for (AssertionInfo ai : ais) {
        token = (Token) ai.getAssertion();
        ai.setAsserted(true);
    }
    ais = aim.getAssertionInfo(SP12Constants.SUPPORTING_TOKENS);
    for (AssertionInfo ai : ais) {
        ai.setAsserted(true);
    }
    /*
        On the server-side, isTLSinUse is used to determine a tls invocation. On the client side, pulling the
        "http.scheme" and comparing it to https seems to be the approved approach:
        @see org.apache.cxf.ws.security.policy.interceptors.HttpsTokenInterceptorProvider
         */
    if (isTLSInUse(message)) {
        /*
            if TLS is in use, then the tokens are signed by TLS. So instead of having the transport binding reference
            a SupportingToken element, a SignedSupportingToken could be specified.
             */
        ais = aim.getAssertionInfo(SP12Constants.SIGNED_SUPPORTING_TOKENS);
        for (AssertionInfo ai : ais) {
            ai.setAsserted(true);
        }
        /*
            this should be asserted by the cxf TransportBindingHandler or TransportBinding or TransportToken, but
            it is not, resulting in the following messages, logged as FINE:
            An exception was thrown when verifying that the effective policy for this request was satisfied.
            However, this exception will not result in a fault.  The exception raised is: org.apache.cxf.ws.policy.PolicyException:
            These policy alternatives can not be satisfied:{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}TransportToken
            Asserting the TRANSPORT_TOKEN makes this message go away. I know that the OpenAMSessionToken will be deployed in
            either a 'bare' SecurityPolicy binding, or under the Transport binding, so if TLS is in use, the TRANSPORT_TOKEN
            can be asserted.
             */
        ais = aim.getAssertionInfo(SP12Constants.TRANSPORT_TOKEN);
        for (AssertionInfo ai : ais) {
            ai.setAsserted(true);
        }
    }
    return token;
}
Also used : AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) Token(org.apache.cxf.ws.security.policy.model.Token) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 2 with AssertionInfoMap

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

the class OpenAMSessionTokenServerInterceptor method assertTokens.

/**
     * Called to assert the relevant tokens. Asserting tokens means asserting that the corresponding policy has been
     * satisfied. This method is called outbound on the server-side, and inbound on the client side. It is also called from
     * processTokenAbove, following successful token validation. This method will assert that the OpenAMSessionAssertion
     * has been satisfied, and also the SupportingToken policy (the OpenAMSessionToken policy always defines a SupportingToken),
     * and, if TLS is being used in the invocation, that the TransportPolicy has also been satisfied, as the OpenAMSessionToken
     * SecurityPolicy binding is always deployed as part of an unprotected binding (i.e. a 'bare' OpenAMSessionToken), or
     * as part of the Transport binding. Note that a TransportToken is the token manifestation of a TransportPolicy binding,
     * so asserting the TransportToken will assert the TransportPolicy.
     * @param message The SoapMessage defining the invocation.
     * @return The OpenAMSessionAssertion corresponding to the OpenAMSessionToken SecurityPolicy element protecting
     * soap-sts instances.
     */
@Override
protected Token assertTokens(SoapMessage message) {
    AssertionInfoMap aim = message.get(AssertionInfoMap.class);
    Collection<AssertionInfo> ais = aim.getAssertionInfo(AMSTSConstants.AM_SESSION_TOKEN_ASSERTION_QNAME);
    Token token = null;
    for (AssertionInfo ai : ais) {
        token = (Token) ai.getAssertion();
        ai.setAsserted(true);
    }
    ais = aim.getAssertionInfo(SP12Constants.SUPPORTING_TOKENS);
    for (AssertionInfo ai : ais) {
        ai.setAsserted(true);
    }
    if (isTLSInUse(message)) {
        /*
            if TLS is in use, then the tokens are signed by TLS. So instead of having the transport binding reference
            a SupportingToken element, a SignedSupportingToken could be specified.
             */
        ais = aim.getAssertionInfo(SP12Constants.SIGNED_SUPPORTING_TOKENS);
        for (AssertionInfo ai : ais) {
            ai.setAsserted(true);
        }
        /*
            this should be asserted by the cxf TransportBindingHandler or TransportBinding or TransportToken, but
            it is not, resulting in the following messages, logged as FINE:
            An exception was thrown when verifying that the effective policy for this request was satisfied.
            However, this exception will not result in a fault.  The exception raised is: org.apache.cxf.ws.policy.PolicyException:
            These policy alternatives can not be satisfied:{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}TransportToken
            Asserting the TRANSPORT_TOKEN makes this message go away. I know that the OpenAMSessionToken will be deployed in
            either a 'bare' SecurityPolicy binding, or under the Transport binding, so if TLS is in use, the TRANSPORT_TOKEN
            can be asserted.
            Note that this message is a bug - see
            http://cxf.547215.n5.nabble.com/Custom-SecurityPolicy-Assertions-and-the-Symmetric-binding-td5754879.html#a5755303
            for details. I will continue to assert the TRANSPORT_TOKEN to prevent these messages.
             */
        ais = aim.getAssertionInfo(SP12Constants.TRANSPORT_TOKEN);
        for (AssertionInfo ai : ais) {
            ai.setAsserted(true);
        }
    }
    return token;
}
Also used : AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) Token(org.apache.cxf.ws.security.policy.model.Token) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 3 with AssertionInfoMap

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

the class XRMAuthPolicyInterceptor method handleMessage.

public void handleMessage(SoapMessage message) throws Fault {
    AssertionInfoMap aim = message.get(AssertionInfoMap.class);
    if (null == aim) {
        return;
    }
    QName qname = new QName("http://schemas.microsoft.com/xrm/2011/Contracts/Services", "AuthenticationPolicy", "ms-xrm");
    Collection<AssertionInfo> ais = 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) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 4 with AssertionInfoMap

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

the class GuestInterceptor method internalHandleMessage.

private void internalHandleMessage(SoapMessage message, SOAPMessage soapMessage) throws Fault {
    //Check if security header exists; if not, execute GuestInterceptor logic
    String actor = (String) getOption(WSHandlerConstants.ACTOR);
    if (actor == null) {
        actor = (String) message.getContextualProperty(SecurityConstants.ACTOR);
    }
    Element existingSecurityHeader = null;
    try {
        LOGGER.debug("Checking for security header.");
        existingSecurityHeader = WSSecurityUtil.getSecurityHeader(soapMessage.getSOAPPart(), actor);
    } catch (WSSecurityException e1) {
        LOGGER.debug("Issue with getting security header", e1);
    }
    if (existingSecurityHeader != null) {
        LOGGER.debug("SOAP message contains security header, no action taken by the GuestInterceptor.");
        return;
    }
    LOGGER.debug("Current request has no security header, continuing with GuestInterceptor");
    AssertionInfoMap assertionInfoMap = message.get(AssertionInfoMap.class);
    boolean hasAddressingAssertion = assertionInfoMap.entrySet().stream().flatMap(p -> p.getValue().stream()).filter(info -> MetadataConstants.ADDRESSING_ASSERTION_QNAME.equals(info.getAssertion().getName())).findFirst().isPresent();
    if (hasAddressingAssertion) {
        createAddressing(message, soapMessage);
    }
    LOGGER.debug("Creating guest security token.");
    HttpServletRequest request = (HttpServletRequest) message.get(AbstractHTTPDestination.HTTP_REQUEST);
    SecurityToken securityToken = createSecurityToken(request.getRemoteAddr());
    message.put(SecurityConstants.TOKEN, securityToken);
    if (!MessageUtils.isRequestor(message)) {
        try {
            message.put(Message.REQUESTOR_ROLE, true);
            policyBasedWss4jOutInterceptor.handleMessage(message);
        } finally {
            message.remove(Message.REQUESTOR_ROLE);
        }
    } else {
        policyBasedWss4jOutInterceptor.handleMessage(message);
    }
}
Also used : WSSecurityUtil(org.apache.wss4j.dom.util.WSSecurityUtil) StringUtils(org.apache.commons.lang.StringUtils) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) MetadataConstants(org.apache.cxf.ws.addressing.policy.MetadataConstants) SOAPException(javax.xml.soap.SOAPException) STSClientConfiguration(ddf.security.sts.client.configuration.STSClientConfiguration) LoggerFactory(org.slf4j.LoggerFactory) XMLUtils(org.codice.ddf.platform.util.XMLUtils) SoapBindingConstants(org.apache.cxf.binding.soap.SoapBindingConstants) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) AbstractHTTPDestination(org.apache.cxf.transport.http.AbstractHTTPDestination) SOAPElement(javax.xml.soap.SOAPElement) HttpServletRequest(javax.servlet.http.HttpServletRequest) WSS4JInInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap) Fault(org.apache.cxf.interceptor.Fault) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) PolicyBasedWSS4JInInterceptor(org.apache.cxf.ws.security.wss4j.PolicyBasedWSS4JInInterceptor) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) EncryptionService(ddf.security.encryption.EncryptionService) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) Phase(org.apache.cxf.phase.Phase) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) ContextPolicyManager(org.codice.ddf.security.policy.context.ContextPolicyManager) PolicyBasedWSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.PolicyBasedWSS4JOutInterceptor) SecurityAssertion(ddf.security.assertion.SecurityAssertion) Logger(org.slf4j.Logger) Security(org.codice.ddf.security.common.Security) Message(org.apache.cxf.message.Message) WSHandlerConstants(org.apache.wss4j.dom.handler.WSHandlerConstants) Set(java.util.Set) Subject(ddf.security.Subject) UUID(java.util.UUID) SecurityConstants(org.apache.cxf.ws.security.SecurityConstants) TimeUnit(java.util.concurrent.TimeUnit) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) Element(org.w3c.dom.Element) MessageUtils(org.apache.cxf.message.MessageUtils) AbstractWSS4JInterceptor(org.apache.cxf.ws.security.wss4j.AbstractWSS4JInterceptor) CacheBuilder(com.google.common.cache.CacheBuilder) SOAPMessage(javax.xml.soap.SOAPMessage) Cache(com.google.common.cache.Cache) SecurityManager(ddf.security.service.SecurityManager) SOAPFactory(javax.xml.soap.SOAPFactory) HttpServletRequest(javax.servlet.http.HttpServletRequest) SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) SOAPElement(javax.xml.soap.SOAPElement) Element(org.w3c.dom.Element) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 5 with AssertionInfoMap

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

the class MAPAggregatorImpl method assertAddressing.

/**
 * If the isRequestor(message) == true and isAddressRequired() == false
 * Assert all the wsa related assertion to true
 *
 * @param message the current message
 */
private void assertAddressing(Message message) {
    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 };
    for (QName type : types) {
        assertAssertion(aim, type);
        // ADDRESSING_ASSERTION is normalized, so check only the default namespace
        if (type.equals(MetadataConstants.ADDRESSING_ASSERTION_QNAME)) {
            assertAssertion(aim, MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME);
            assertAssertion(aim, MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME);
        }
    }
}
Also used : 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)11 Message (org.apache.cxf.message.Message)10 ArrayList (java.util.ArrayList)9 PolicyException (org.apache.cxf.ws.policy.PolicyException)7 Element (org.w3c.dom.Element)6 Exchange (org.apache.cxf.message.Exchange)5 Policy (org.apache.neethi.Policy)5 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)5 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)4 SamlAssertionWrapper (org.apache.wss4j.common.saml.SamlAssertionWrapper)4 Message (org.apache.cxf.common.i18n.Message)3 Header (org.apache.cxf.headers.Header)3 PolicyAssertion (org.apache.cxf.ws.policy.PolicyAssertion)3 WSSecUsernameToken (org.apache.wss4j.dom.message.WSSecUsernameToken)3 UsernameToken (org.apache.wss4j.policy.model.UsernameToken)3 Test (org.junit.Test)3 IOException (java.io.IOException)2