Search in sources :

Example 11 with AssertionInfo

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

the class PolicyBasedWSS4JInInterceptor method checkAsymmetricBinding.

private String checkAsymmetricBinding(AssertionInfoMap aim, String action, SoapMessage message, RequestData data) throws WSSecurityException {
    AssertionInfo ai = PolicyUtils.getFirstAssertionByLocalname(aim, SPConstants.ASYMMETRIC_BINDING);
    if (ai == null) {
        return action;
    }
    action = addToAction(action, "Signature", true);
    action = addToAction(action, "Encrypt", true);
    Object s = SecurityUtils.getSecurityPropertyValue(SecurityConstants.SIGNATURE_CRYPTO, message);
    if (s == null) {
        s = SecurityUtils.getSecurityPropertyValue(SecurityConstants.SIGNATURE_PROPERTIES, message);
    }
    Object e = SecurityUtils.getSecurityPropertyValue(SecurityConstants.ENCRYPT_CRYPTO, message);
    if (e == null) {
        e = SecurityUtils.getSecurityPropertyValue(SecurityConstants.ENCRYPT_PROPERTIES, message);
    }
    Crypto encrCrypto = getEncryptionCrypto(e, message, data);
    final Crypto signCrypto;
    if (e != null && e.equals(s)) {
        signCrypto = encrCrypto;
    } else {
        signCrypto = getSignatureCrypto(s, message, data);
    }
    final String signCryptoRefId = signCrypto != null ? "RefId-" + signCrypto.hashCode() : null;
    if (signCrypto != null) {
        message.put(ConfigurationConstants.DEC_PROP_REF_ID, signCryptoRefId);
        message.put(signCryptoRefId, signCrypto);
    }
    if (encrCrypto != null) {
        final String encCryptoRefId = "RefId-" + encrCrypto.hashCode();
        message.put(ConfigurationConstants.SIG_VER_PROP_REF_ID, encCryptoRefId);
        message.put(encCryptoRefId, encrCrypto);
    } else if (signCrypto != null) {
        message.put(ConfigurationConstants.SIG_VER_PROP_REF_ID, signCryptoRefId);
        message.put(signCryptoRefId, signCrypto);
    }
    return action;
}
Also used : AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) Crypto(org.apache.wss4j.common.crypto.Crypto)

Example 12 with AssertionInfo

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

the class SecureConversationInInterceptor method handleMessage.

public void handleMessage(SoapMessage message) throws Fault {
    final AssertionInfoMap aim = message.get(AssertionInfoMap.class);
    // extract Assertion information
    if (aim != null) {
        final Collection<AssertionInfo> ais = PolicyUtils.getAllAssertionsByLocalname(aim, SPConstants.SECURE_CONVERSATION_TOKEN);
        if (ais.isEmpty()) {
            return;
        }
        if (isRequestor(message)) {
            // client side should be checked on the way out
            for (AssertionInfo ai : ais) {
                ai.setAsserted(true);
            }
            assertPolicies(aim);
            Object s = message.getContextualProperty(SecurityConstants.STS_TOKEN_DO_CANCEL);
            if (s != null && (Boolean.TRUE.equals(s) || "true".equalsIgnoreCase(s.toString()))) {
                message.getInterceptorChain().add(SecureConversationCancelInterceptor.INSTANCE);
            }
            return;
        }
        String s = (String) message.get(SoapBindingConstants.SOAP_ACTION);
        if (s == null) {
            s = SoapActionInInterceptor.getSoapAction(message);
        }
        if (s != null) {
            handleMessageForAction(message, s, aim, ais);
        } else {
            // could not get an action, we have to delay until after the WS-A headers are read and
            // processed
            AbstractPhaseInterceptor<SoapMessage> post = new AbstractPhaseInterceptor<SoapMessage>(Phase.PRE_PROTOCOL) {

                public void handleMessage(SoapMessage message) throws Fault {
                    String s = (String) message.get(SoapBindingConstants.SOAP_ACTION);
                    if (s == null) {
                        s = SoapActionInInterceptor.getSoapAction(message);
                    }
                    handleMessageForAction(message, s, aim, ais);
                }
            };
            post.addAfter(MAPCodec.class.getName());
            post.addBefore(PolicyBasedWSS4JInInterceptor.class.getName());
            // need to drop to DOM version so we can setup the sec/conv stuff in advance
            message.put(SecurityConstants.ENABLE_STREAMING_SECURITY, Boolean.FALSE);
            message.getInterceptorChain().add(post);
        }
    }
}
Also used : AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) PolicyBasedWSS4JInInterceptor(org.apache.cxf.ws.security.wss4j.PolicyBasedWSS4JInInterceptor) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) MAPCodec(org.apache.cxf.ws.addressing.soap.MAPCodec) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap) SoapMessage(org.apache.cxf.binding.soap.SoapMessage)

Example 13 with AssertionInfo

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

the class SpnegoContextTokenInInterceptor method handleMessage.

public void handleMessage(SoapMessage message) throws Fault {
    AssertionInfoMap aim = message.get(AssertionInfoMap.class);
    // extract Assertion information
    if (aim != null) {
        Collection<AssertionInfo> ais = PolicyUtils.getAllAssertionsByLocalname(aim, SPConstants.SPNEGO_CONTEXT_TOKEN);
        if (ais.isEmpty()) {
            return;
        }
        if (isRequestor(message)) {
            // client side should be checked on the way out
            for (AssertionInfo ai : ais) {
                ai.setAsserted(true);
            }
            return;
        }
        String s = (String) message.get(SoapBindingConstants.SOAP_ACTION);
        if (s == null) {
            s = SoapActionInInterceptor.getSoapAction(message);
        }
        AddressingProperties inProps = (AddressingProperties) message.getContextualProperty(JAXWSAConstants.ADDRESSING_PROPERTIES_INBOUND);
        if (inProps != null && s == null) {
            // MS/WCF doesn't put a soap action out for this, must check the headers
            s = inProps.getAction().getValue();
        }
        if (s != null && s.contains("/RST/Issue") && (s.startsWith(STSUtils.WST_NS_05_02) || s.startsWith(STSUtils.WST_NS_05_12))) {
            Policy p = new Policy();
            ExactlyOne ea = new ExactlyOne();
            p.addPolicyComponent(ea);
            All all = new All();
            Assertion ass = NegotiationUtils.getAddressingPolicy(aim, false);
            all.addPolicyComponent(ass);
            ea.addPolicyComponent(all);
            // setup endpoint and forward to it.
            unmapSecurityProps(message);
            String ns = STSUtils.WST_NS_05_12;
            if (s.startsWith(STSUtils.WST_NS_05_02)) {
                ns = STSUtils.WST_NS_05_02;
            }
            NegotiationUtils.recalcEffectivePolicy(message, ns, p, new SpnegoSTSInvoker(), false);
        } else {
            message.getInterceptorChain().add(SpnegoContextTokenFinderInterceptor.INSTANCE);
        }
    }
}
Also used : Policy(org.apache.neethi.Policy) All(org.apache.neethi.All) AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) Assertion(org.apache.neethi.Assertion) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) ExactlyOne(org.apache.neethi.ExactlyOne) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 14 with AssertionInfo

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

the class SecureConversationOutInterceptor method handleMessage.

public void handleMessage(SoapMessage message) throws Fault {
    AssertionInfoMap aim = message.get(AssertionInfoMap.class);
    // extract Assertion information
    if (aim != null) {
        Collection<AssertionInfo> ais = PolicyUtils.getAllAssertionsByLocalname(aim, SPConstants.SECURE_CONVERSATION_TOKEN);
        if (ais.isEmpty()) {
            return;
        }
        if (isRequestor(message)) {
            SecureConversationToken itok = (SecureConversationToken) ais.iterator().next().getAssertion();
            try {
                SecurityToken tok = (SecurityToken) message.getContextualProperty(SecurityConstants.TOKEN);
                if (tok == null) {
                    String tokId = (String) message.getContextualProperty(SecurityConstants.TOKEN_ID);
                    if (tokId != null) {
                        tok = TokenStoreUtils.getTokenStore(message).getToken(tokId);
                    }
                }
                if (tok == null) {
                    tok = issueToken(message, aim, itok);
                } else {
                    tok = renewToken(message, aim, tok, itok);
                }
                if (tok != null) {
                    for (AssertionInfo ai : ais) {
                        ai.setAsserted(true);
                    }
                    message.getExchange().getEndpoint().put(SecurityConstants.TOKEN, tok);
                    message.getExchange().getEndpoint().put(SecurityConstants.TOKEN_ID, tok.getId());
                    message.getExchange().put(SecurityConstants.TOKEN_ID, tok.getId());
                    message.getExchange().put(SecurityConstants.TOKEN, tok);
                    TokenStoreUtils.getTokenStore(message).add(tok);
                }
                PolicyUtils.assertPolicy(aim, SPConstants.BOOTSTRAP_POLICY);
            } catch (TokenStoreException ex) {
                throw new Fault(ex);
            }
        } else {
            // server side should be checked on the way in
            for (AssertionInfo ai : ais) {
                ai.setAsserted(true);
            }
            PolicyUtils.assertPolicy(aim, SPConstants.BOOTSTRAP_POLICY);
        }
    }
}
Also used : SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) TokenStoreException(org.apache.cxf.ws.security.tokenstore.TokenStoreException) Fault(org.apache.cxf.interceptor.Fault) SecureConversationToken(org.apache.wss4j.policy.model.SecureConversationToken) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 15 with AssertionInfo

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

the class SecurityVerificationOutInterceptor method getSecuredPart.

private AssertionInfo getSecuredPart(AssertionInfoMap aim) {
    AssertionInfo assertion = PolicyUtils.getFirstAssertionByLocalname(aim, SPConstants.SIGNED_PARTS);
    if (assertion != null) {
        return assertion;
    }
    assertion = PolicyUtils.getFirstAssertionByLocalname(aim, SPConstants.SIGNED_ELEMENTS);
    if (assertion != null) {
        return assertion;
    }
    assertion = PolicyUtils.getFirstAssertionByLocalname(aim, SPConstants.ENCRYPTED_PARTS);
    if (assertion != null) {
        return assertion;
    }
    assertion = PolicyUtils.getFirstAssertionByLocalname(aim, SPConstants.ENCRYPTED_ELEMENTS);
    if (assertion != null) {
        return assertion;
    }
    assertion = PolicyUtils.getFirstAssertionByLocalname(aim, SPConstants.CONTENT_ENCRYPTED_ELEMENTS);
    if (assertion != null) {
        return assertion;
    }
    return null;
}
Also used : AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo)

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