Search in sources :

Example 51 with AssertionInfoMap

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

the class PolicyUtilsTest method testAssertServerPolicy.

void testAssertServerPolicy(boolean outbound) {
    Message message = control.createMock(Message.class);
    HTTPServerPolicy ep = new HTTPServerPolicy();
    HTTPServerPolicy mp = new HTTPServerPolicy();
    HTTPServerPolicy cmp = new HTTPServerPolicy();
    cmp.setReceiveTimeout(60000L);
    HTTPServerPolicy icmp = new HTTPServerPolicy();
    icmp.setSuppressClientSendErrors(true);
    AssertionInfo eai = getServerPolicyAssertionInfo(ep);
    AssertionInfo mai = getServerPolicyAssertionInfo(mp);
    AssertionInfo cmai = getServerPolicyAssertionInfo(cmp);
    AssertionInfo icmai = getServerPolicyAssertionInfo(icmp);
    Collection<AssertionInfo> ais = new ArrayList<>();
    ais.add(eai);
    ais.add(mai);
    ais.add(cmai);
    ais.add(icmai);
    AssertionInfoMap aim = new AssertionInfoMap(CastUtils.cast(Collections.EMPTY_LIST, PolicyAssertion.class));
    aim.put(new ServerPolicyCalculator().getDataClassName(), ais);
    EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim).atLeastOnce();
    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();
    new PolicyDataEngineImpl(null).assertMessage(message, ep, new ServerPolicyCalculator());
    assertTrue(eai.isAsserted());
    assertTrue(mai.isAsserted());
    assertTrue(outbound ? cmai.isAsserted() : !cmai.isAsserted());
    assertTrue(outbound ? icmai.isAsserted() : !icmai.isAsserted());
    control.verify();
}
Also used : Exchange(org.apache.cxf.message.Exchange) PolicyAssertion(org.apache.cxf.ws.policy.PolicyAssertion) HTTPServerPolicy(org.apache.cxf.transports.http.configuration.HTTPServerPolicy) AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) Message(org.apache.cxf.message.Message) ArrayList(java.util.ArrayList) ServerPolicyCalculator(org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator) PolicyDataEngineImpl(org.apache.cxf.ws.policy.PolicyDataEngineImpl) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 52 with AssertionInfoMap

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

the class MTOMPolicyInterceptor method handleMessage.

public void handleMessage(Message message) throws Fault {
    AssertionInfoMap aim = message.get(AssertionInfoMap.class);
    // extract Assertion information
    if (aim != null) {
        Collection<AssertionInfo> ais = aim.get(MetadataConstants.MTOM_ASSERTION_QNAME);
        for (AssertionInfo ai : ais) {
            if (MessageUtils.isRequestor(message)) {
                // just turn on MTOM
                message.put(Message.MTOM_ENABLED, Boolean.TRUE);
                ai.setAsserted(true);
            } else {
                // set mtom enabled and assert the policy if we find an mtom request
                String contentType = (String) message.getExchange().getInMessage().get(Message.CONTENT_TYPE);
                if (contentType != null && contentType.contains("type=\"application/xop+xml\"")) {
                    ai.setAsserted(true);
                    message.put(Message.MTOM_ENABLED, Boolean.TRUE);
                }
            }
        }
    }
}
Also used : AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 53 with AssertionInfoMap

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

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

the class NegotiationUtils method recalcEffectivePolicy.

static void recalcEffectivePolicy(SoapMessage message, String namespace, Policy policy, Invoker invoker, boolean secConv) {
    Exchange ex = message.getExchange();
    Bus bus = ex.getBus();
    PolicyEngine pe = bus.getExtension(PolicyEngine.class);
    if (null == pe) {
        return;
    }
    Destination destination = ex.getDestination();
    try {
        Endpoint endpoint = message.getExchange().getEndpoint();
        TokenStore store = TokenStoreUtils.getTokenStore(message);
        if (secConv) {
            endpoint = STSUtils.createSCEndpoint(bus, namespace, endpoint.getEndpointInfo().getTransportId(), destination.getAddress().getAddress().getValue(), message.getVersion().getBindingId(), policy);
        } else {
            endpoint = STSUtils.createSTSEndpoint(bus, namespace, endpoint.getEndpointInfo().getTransportId(), destination.getAddress().getAddress().getValue(), message.getVersion().getBindingId(), policy, null);
        }
        endpoint.getEndpointInfo().setProperty(TokenStore.class.getName(), store);
        message.getExchange().put(TokenStore.class.getName(), store);
        EndpointPolicy ep = pe.getServerEndpointPolicy(endpoint.getEndpointInfo(), destination, message);
        List<Interceptor<? extends Message>> interceptors = ep.getInterceptors(message);
        message.getInterceptorChain().add(interceptors);
        Collection<Assertion> assertions = ep.getVocabulary(message);
        if (null != assertions) {
            message.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
        }
        endpoint.getService().setInvoker(invoker);
        ex.put(Endpoint.class, endpoint);
        ex.put(Service.class, endpoint.getService());
        ex.put(org.apache.cxf.binding.Binding.class, endpoint.getBinding());
        ex.remove(BindingOperationInfo.class);
        message.put(MAPAggregator.ACTION_VERIFIED, Boolean.TRUE);
    } catch (Exception exc) {
        throw new Fault(exc);
    }
}
Also used : Bus(org.apache.cxf.Bus) Destination(org.apache.cxf.transport.Destination) Message(org.apache.cxf.message.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) Assertion(org.apache.neethi.Assertion) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) Fault(org.apache.cxf.interceptor.Fault) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) TokenStoreException(org.apache.cxf.ws.security.tokenstore.TokenStoreException) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap) Exchange(org.apache.cxf.message.Exchange) EndpointPolicy(org.apache.cxf.ws.policy.EndpointPolicy) Endpoint(org.apache.cxf.endpoint.Endpoint) TokenStore(org.apache.cxf.ws.security.tokenstore.TokenStore) Interceptor(org.apache.cxf.interceptor.Interceptor)

Example 55 with AssertionInfoMap

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

the class SecurityVerificationOutInterceptor method handleMessage.

/**
 * Checks if some security assertions are specified without binding assertion and cannot be fulfilled.
 * Throw PolicyException in this case
 *
 * @param message
 * @throws PolicyException if assertions are specified without binding
 */
public void handleMessage(SoapMessage message) throws Fault {
    if (MessageUtils.isRequestor(message)) {
        AssertionInfoMap aim = message.get(AssertionInfoMap.class);
        if (aim != null && PolicyUtils.getSecurityBinding(aim) == null) {
            AssertionInfo assertion = getSecuredPart(aim);
            if (assertion != null) {
                String error = String.format("%s assertion cannot be fulfilled without binding. " + "At least one binding assertion (%s, %s, %s) must be specified in policy.", assertion.getAssertion().getName(), SP12Constants.TRANSPORT_BINDING.getLocalPart(), SP12Constants.ASYMMETRIC_BINDING.getLocalPart(), SP12Constants.SYMMETRIC_BINDING.getLocalPart());
                assertion.setNotAsserted(error);
                LOG.severe(error);
                throw new PolicyException(assertion);
            }
        }
    }
}
Also used : AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) PolicyException(org.apache.cxf.ws.policy.PolicyException) 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)12 Message (org.apache.cxf.message.Message)10 ArrayList (java.util.ArrayList)9 PolicyException (org.apache.cxf.ws.policy.PolicyException)7 Fault (org.apache.cxf.interceptor.Fault)6 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)6 Element (org.w3c.dom.Element)6 Exchange (org.apache.cxf.message.Exchange)5 TokenStoreException (org.apache.cxf.ws.security.tokenstore.TokenStoreException)5 Policy (org.apache.neethi.Policy)5 Message (org.apache.cxf.common.i18n.Message)4 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)4 SamlAssertionWrapper (org.apache.wss4j.common.saml.SamlAssertionWrapper)4 SOAPException (javax.xml.soap.SOAPException)3 Header (org.apache.cxf.headers.Header)3 PolicyAssertion (org.apache.cxf.ws.policy.PolicyAssertion)3 WSSecUsernameToken (org.apache.wss4j.dom.message.WSSecUsernameToken)3