Search in sources :

Example 1 with AsymmetricBinding

use of org.apache.wss4j.policy.model.AsymmetricBinding in project cxf by apache.

the class PolicyBasedWSS4JStaxOutInterceptor method configureProperties.

@Override
protected void configureProperties(SoapMessage msg, OutboundSecurityContext outboundSecurityContext, WSSSecurityProperties securityProperties) throws WSSecurityException {
    AssertionInfoMap aim = msg.get(AssertionInfoMap.class);
    AssertionInfo asymAis = PolicyUtils.getFirstAssertionByLocalname(aim, SPConstants.ASYMMETRIC_BINDING);
    if (asymAis != null) {
        checkAsymmetricBinding(msg, securityProperties);
        asymAis.setAsserted(true);
    }
    AssertionInfo symAis = PolicyUtils.getFirstAssertionByLocalname(aim, SPConstants.SYMMETRIC_BINDING);
    if (symAis != null) {
        checkSymmetricBinding(msg, securityProperties);
        symAis.setAsserted(true);
    }
    AssertionInfo transAis = PolicyUtils.getFirstAssertionByLocalname(aim, SPConstants.TRANSPORT_BINDING);
    if (transAis != null) {
        checkTransportBinding(msg, securityProperties);
        transAis.setAsserted(true);
    }
    super.configureProperties(msg, outboundSecurityContext, securityProperties);
    if (transAis != null) {
        TransportBinding binding = (TransportBinding) transAis.getAssertion();
        new StaxTransportBindingHandler(securityProperties, msg, binding, outboundSecurityContext).handleBinding();
    } else if (asymAis != null) {
        AsymmetricBinding binding = (AsymmetricBinding) asymAis.getAssertion();
        new StaxAsymmetricBindingHandler(securityProperties, msg, binding, outboundSecurityContext).handleBinding();
    } else if (symAis != null) {
        SymmetricBinding binding = (SymmetricBinding) symAis.getAssertion();
        new StaxSymmetricBindingHandler(securityProperties, msg, binding, outboundSecurityContext).handleBinding();
    } else {
        // Fall back to Transport Binding
        new StaxTransportBindingHandler(securityProperties, msg, null, outboundSecurityContext).handleBinding();
    }
}
Also used : SymmetricBinding(org.apache.wss4j.policy.model.SymmetricBinding) AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) AsymmetricBinding(org.apache.wss4j.policy.model.AsymmetricBinding) StaxSymmetricBindingHandler(org.apache.cxf.ws.security.wss4j.policyhandlers.StaxSymmetricBindingHandler) StaxTransportBindingHandler(org.apache.cxf.ws.security.wss4j.policyhandlers.StaxTransportBindingHandler) StaxAsymmetricBindingHandler(org.apache.cxf.ws.security.wss4j.policyhandlers.StaxAsymmetricBindingHandler) TransportBinding(org.apache.wss4j.policy.model.TransportBinding) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 2 with AsymmetricBinding

use of org.apache.wss4j.policy.model.AsymmetricBinding in project cxf by apache.

the class AsymmetricBindingPolicyValidator method validatePolicies.

/**
 * Validate policies.
 */
public void validatePolicies(PolicyValidatorParameters parameters, Collection<AssertionInfo> ais) {
    boolean hasDerivedKeys = parameters.getResults().getActionResults().containsKey(WSConstants.DKT);
    for (AssertionInfo ai : ais) {
        AsymmetricBinding binding = (AsymmetricBinding) ai.getAssertion();
        ai.setAsserted(true);
        // Check the protection order
        if (!checkProtectionOrder(binding, parameters.getAssertionInfoMap(), ai, parameters.getResults().getResults())) {
            continue;
        }
        // Check various properties of the binding
        if (!checkProperties(binding, ai, parameters.getAssertionInfoMap(), parameters.getResults(), parameters.getSignedResults(), parameters.getMessage())) {
            continue;
        }
        // Check various tokens of the binding
        if (!checkTokens(binding, ai, parameters.getAssertionInfoMap(), hasDerivedKeys, parameters.getSignedResults(), parameters.getEncryptedResults())) {
            continue;
        }
    }
}
Also used : AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) AsymmetricBinding(org.apache.wss4j.policy.model.AsymmetricBinding)

Example 3 with AsymmetricBinding

use of org.apache.wss4j.policy.model.AsymmetricBinding in project cxf by apache.

the class CustomPolicyAlgorithmsTest method testSHA256AsymSigAlgorithm.

@Test
public void testSHA256AsymSigAlgorithm() throws Exception {
    final String rsaSha2SigMethod = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256";
    String policyName = "signed_elements_policy.xml";
    Policy policy = policyBuilder.getPolicy(this.getResourceAsStream(policyName));
    AssertionInfoMap aim = new AssertionInfoMap(policy);
    AssertionInfo assertInfo = aim.get(SP12Constants.ASYMMETRIC_BINDING).iterator().next();
    AsymmetricBinding binding = (AsymmetricBinding) assertInfo.getAssertion();
    // set Signature Algorithm to RSA SHA-256
    binding.getAlgorithmSuite().setAsymmetricSignature(rsaSha2SigMethod);
    String sigMethod = binding.getAlgorithmSuite().getAsymmetricSignature();
    assertNotNull(sigMethod);
    assertEquals(rsaSha2SigMethod, sigMethod);
}
Also used : Policy(org.apache.neethi.Policy) AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) AsymmetricBinding(org.apache.wss4j.policy.model.AsymmetricBinding) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap) Test(org.junit.Test)

Aggregations

AssertionInfo (org.apache.cxf.ws.policy.AssertionInfo)3 AsymmetricBinding (org.apache.wss4j.policy.model.AsymmetricBinding)3 AssertionInfoMap (org.apache.cxf.ws.policy.AssertionInfoMap)2 StaxAsymmetricBindingHandler (org.apache.cxf.ws.security.wss4j.policyhandlers.StaxAsymmetricBindingHandler)1 StaxSymmetricBindingHandler (org.apache.cxf.ws.security.wss4j.policyhandlers.StaxSymmetricBindingHandler)1 StaxTransportBindingHandler (org.apache.cxf.ws.security.wss4j.policyhandlers.StaxTransportBindingHandler)1 Policy (org.apache.neethi.Policy)1 SymmetricBinding (org.apache.wss4j.policy.model.SymmetricBinding)1 TransportBinding (org.apache.wss4j.policy.model.TransportBinding)1 Test (org.junit.Test)1