Search in sources :

Example 66 with AssertionInfo

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

the class PolicyUtilsTest method testGetRMConfiguration.

@Test
public void testGetRMConfiguration() {
    RMConfiguration cfg = new RMConfiguration();
    cfg.setBaseRetransmissionInterval(Long.valueOf(3000));
    cfg.setExponentialBackoff(true);
    Message message = control.createMock(Message.class);
    EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(null);
    control.replay();
    assertSame(cfg, RMPolicyUtilities.getRMConfiguration(cfg, message));
    control.verify();
    control.reset();
    AssertionInfoMap aim = control.createMock(AssertionInfoMap.class);
    EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim);
    Collection<AssertionInfo> ais = new ArrayList<>();
    EasyMock.expect(aim.get(RM10Constants.RMASSERTION_QNAME)).andReturn(ais);
    control.replay();
    assertSame(cfg, RMPolicyUtilities.getRMConfiguration(cfg, message));
    control.verify();
    control.reset();
    RMAssertion b = new RMAssertion();
    BaseRetransmissionInterval bbri = new RMAssertion.BaseRetransmissionInterval();
    bbri.setMilliseconds(Long.valueOf(2000));
    b.setBaseRetransmissionInterval(bbri);
    JaxbAssertion<RMAssertion> assertion = new JaxbAssertion<>();
    assertion.setName(RM10Constants.RMASSERTION_QNAME);
    assertion.setData(b);
    AssertionInfo ai = new AssertionInfo(assertion);
    ais.add(ai);
    EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim);
    EasyMock.expect(aim.get(RM10Constants.RMASSERTION_QNAME)).andReturn(ais);
    control.replay();
    RMConfiguration cfg1 = RMPolicyUtilities.getRMConfiguration(cfg, message);
    assertNull(cfg1.getAcknowledgementInterval());
    assertNull(cfg1.getInactivityTimeout());
    assertEquals(2000L, cfg1.getBaseRetransmissionInterval().longValue());
    assertTrue(cfg1.isExponentialBackoff());
    control.verify();
}
Also used : AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) Message(org.apache.cxf.message.Message) RMAssertion(org.apache.cxf.ws.rmp.v200502.RMAssertion) BaseRetransmissionInterval(org.apache.cxf.ws.rmp.v200502.RMAssertion.BaseRetransmissionInterval) ArrayList(java.util.ArrayList) RMConfiguration(org.apache.cxf.ws.rm.RMConfiguration) JaxbAssertion(org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap) Test(org.junit.Test)

Example 67 with AssertionInfo

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

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

the class AbstractBindingBuilder method getEncryptedParts.

public List<WSEncryptionPart> getEncryptedParts() throws SOAPException {
    EncryptedParts parts = null;
    EncryptedElements elements = null;
    ContentEncryptedElements celements = null;
    Collection<AssertionInfo> ais = getAllAssertionsByLocalname(SPConstants.ENCRYPTED_PARTS);
    if (!ais.isEmpty()) {
        for (AssertionInfo ai : ais) {
            parts = (EncryptedParts) ai.getAssertion();
            ai.setAsserted(true);
        }
    }
    ais = getAllAssertionsByLocalname(SPConstants.ENCRYPTED_ELEMENTS);
    if (!ais.isEmpty()) {
        for (AssertionInfo ai : ais) {
            elements = (EncryptedElements) ai.getAssertion();
            ai.setAsserted(true);
        }
    }
    ais = getAllAssertionsByLocalname(SPConstants.CONTENT_ENCRYPTED_ELEMENTS);
    if (!ais.isEmpty()) {
        for (AssertionInfo ai : ais) {
            celements = (ContentEncryptedElements) ai.getAssertion();
            ai.setAsserted(true);
        }
    }
    if (parts == null && elements == null && celements == null) {
        return new ArrayList<>();
    }
    List<WSEncryptionPart> securedParts = new ArrayList<>();
    boolean isBody = false;
    if (parts != null) {
        isBody = parts.isBody();
        for (Header head : parts.getHeaders()) {
            WSEncryptionPart wep = new WSEncryptionPart(head.getName(), head.getNamespace(), "Header");
            securedParts.add(wep);
        }
        Attachments attachments = parts.getAttachments();
        if (attachments != null) {
            String encModifier = "Element";
            if (MessageUtils.getContextualBoolean(message, SecurityConstants.USE_ATTACHMENT_ENCRYPTION_CONTENT_ONLY_TRANSFORM, false)) {
                encModifier = "Content";
            }
            WSEncryptionPart wep = new WSEncryptionPart("cid:Attachments", encModifier);
            securedParts.add(wep);
        }
    }
    // the encrypted list to prevent duplication / errors in encryption.
    return getPartsAndElements(false, isBody, securedParts, elements == null ? null : elements.getXPaths(), celements == null ? null : celements.getXPaths());
}
Also used : ContentEncryptedElements(org.apache.wss4j.policy.model.ContentEncryptedElements) EncryptedElements(org.apache.wss4j.policy.model.EncryptedElements) EncryptedParts(org.apache.wss4j.policy.model.EncryptedParts) AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) WSEncryptionPart(org.apache.wss4j.common.WSEncryptionPart) SOAPHeader(javax.xml.soap.SOAPHeader) Header(org.apache.wss4j.policy.model.Header) WSSecHeader(org.apache.wss4j.dom.message.WSSecHeader) ContentEncryptedElements(org.apache.wss4j.policy.model.ContentEncryptedElements) ArrayList(java.util.ArrayList) Attachments(org.apache.wss4j.policy.model.Attachments)

Example 69 with AssertionInfo

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

the class AbstractStaxBindingHandler method configureLayout.

protected void configureLayout(AssertionInfoMap aim) {
    AssertionInfo ai = PolicyUtils.getFirstAssertionByLocalname(aim, SPConstants.LAYOUT);
    Layout layout = null;
    if (ai != null) {
        layout = (Layout) ai.getAssertion();
        ai.setAsserted(true);
    }
    if (layout != null && layout.getLayoutType() != null) {
        assertPolicy(new QName(layout.getName().getNamespaceURI(), layout.getLayoutType().name()));
    }
    if (!timestampAdded) {
        return;
    }
    boolean timestampLast = layout != null && layout.getLayoutType() == LayoutType.LaxTsLast;
    WSSConstants.Action actionToPerform = WSSConstants.TIMESTAMP;
    List<WSSConstants.Action> actionList = properties.getActions();
    if (timestampLast) {
        actionList.add(0, actionToPerform);
    } else {
        actionList.add(actionToPerform);
    }
}
Also used : AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) WSSConstants(org.apache.wss4j.stax.ext.WSSConstants) Layout(org.apache.wss4j.policy.model.Layout) QName(javax.xml.namespace.QName)

Example 70 with AssertionInfo

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

the class StaxTransportBindingHandler method handleNonEndorsingSupportingTokens.

/**
 * Handle the non-endorsing supporting tokens
 */
private void handleNonEndorsingSupportingTokens(AssertionInfoMap aim) throws Exception {
    Collection<AssertionInfo> ais;
    ais = PolicyUtils.getAllAssertionsByLocalname(aim, SPConstants.SIGNED_SUPPORTING_TOKENS);
    if (!ais.isEmpty()) {
        for (AssertionInfo ai : ais) {
            SupportingTokens sgndSuppTokens = (SupportingTokens) ai.getAssertion();
            if (sgndSuppTokens != null) {
                addSignedSupportingTokens(sgndSuppTokens);
            }
            ai.setAsserted(true);
        }
    }
    ais = PolicyUtils.getAllAssertionsByLocalname(aim, SPConstants.SIGNED_ENCRYPTED_SUPPORTING_TOKENS);
    if (!ais.isEmpty()) {
        for (AssertionInfo ai : ais) {
            SupportingTokens sgndSuppTokens = (SupportingTokens) ai.getAssertion();
            if (sgndSuppTokens != null) {
                addSignedSupportingTokens(sgndSuppTokens);
            }
            ai.setAsserted(true);
        }
    }
    ais = PolicyUtils.getAllAssertionsByLocalname(aim, SPConstants.ENCRYPTED_SUPPORTING_TOKENS);
    if (!ais.isEmpty()) {
        for (AssertionInfo ai : ais) {
            SupportingTokens encrSuppTokens = (SupportingTokens) ai.getAssertion();
            if (encrSuppTokens != null) {
                addSignedSupportingTokens(encrSuppTokens);
            }
            ai.setAsserted(true);
        }
    }
    ais = PolicyUtils.getAllAssertionsByLocalname(aim, SPConstants.SUPPORTING_TOKENS);
    if (!ais.isEmpty()) {
        for (AssertionInfo ai : ais) {
            SupportingTokens suppTokens = (SupportingTokens) ai.getAssertion();
            if (suppTokens != null && suppTokens.getTokens() != null && suppTokens.getTokens().size() > 0) {
                handleSupportingTokens(suppTokens, false, false);
            }
            ai.setAsserted(true);
        }
    }
}
Also used : SupportingTokens(org.apache.wss4j.policy.model.SupportingTokens) 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