Search in sources :

Example 26 with Bus

use of org.apache.cxf.Bus in project ddf by codice.

the class MetricsOutInterceptorTest method testHandleMessageWithOneWayClientMessage.

/**
     * Test method for
     * {@link ddf.metrics.interceptor.MetricsOutInterceptor#handleMessage(org.apache.cxf.message.Message)}
     * .
     *
     * @throws InterruptedException
     */
@Test
public void testHandleMessageWithOneWayClientMessage() {
    // Setup
    MetricsOutInterceptor outInterceptor = new MetricsOutInterceptor();
    Message mockMessage = mock(Message.class);
    Exchange ex = new ExchangeImpl();
    Bus mockBus = mock(Bus.class);
    InterceptorChain mockIc = mock(InterceptorChain.class);
    ex.put(Bus.class, mockBus);
    ex.setOneWay(true);
    when(mockBus.getId()).thenReturn("bus_id");
    when(mockMessage.getExchange()).thenReturn(ex);
    when(mockMessage.get(Message.PARTIAL_RESPONSE_MESSAGE)).thenReturn("false");
    when(mockMessage.get(Message.REQUESTOR_ROLE)).thenReturn(true);
    when(mockMessage.getInterceptorChain()).thenReturn(mockIc);
    // Perform test
    outInterceptor.handleMessage(mockMessage);
    // validate that LatencyTimeRecorder.beginHandling was called once
    verify(mockMessage, times(1)).getInterceptorChain();
}
Also used : Exchange(org.apache.cxf.message.Exchange) Bus(org.apache.cxf.Bus) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) Message(org.apache.cxf.message.Message) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 27 with Bus

use of org.apache.cxf.Bus in project ddf by codice.

the class MetricsOutInterceptorTest method testHandleMessageWithTwoWayClientMessageWithoutLatencyTimeRecorder.

/**
     * Test method for
     * {@link ddf.metrics.interceptor.MetricsOutInterceptor#handleMessage(org.apache.cxf.message.Message)}
     * .
     *
     * @throws InterruptedException
     */
@Test
public void testHandleMessageWithTwoWayClientMessageWithoutLatencyTimeRecorder() {
    // Setup
    MetricsOutInterceptor outInterceptor = new MetricsOutInterceptor();
    Message mockMessage = mock(Message.class);
    Exchange ex = new ExchangeImpl();
    Bus mockBus = mock(Bus.class);
    ex.put(Bus.class, mockBus);
    when(mockBus.getId()).thenReturn("bus_id");
    when(mockMessage.getExchange()).thenReturn(ex);
    when(mockMessage.get(Message.PARTIAL_RESPONSE_MESSAGE)).thenReturn("false");
    when(mockMessage.get(Message.REQUESTOR_ROLE)).thenReturn(true);
    // Perform test
    outInterceptor.handleMessage(mockMessage);
    // validate that an instance of LatencyTimeRecorder was put onto the
    // exchange
    assertThat(ex.get(LatencyTimeRecorder.class), instanceOf(LatencyTimeRecorder.class));
}
Also used : Exchange(org.apache.cxf.message.Exchange) Bus(org.apache.cxf.Bus) Message(org.apache.cxf.message.Message) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 28 with Bus

use of org.apache.cxf.Bus in project ddf by codice.

the class SecureProxyServiceFactoryImpl method configureProxyFactoryProperties.

/**
     * Configures the JaxWsProxyFactoryBean with the properties that have been set for the particular source.
     */
protected void configureProxyFactoryProperties(JaxWsProxyFactoryBean clientFactory, SecurityToken token, WebServiceProperties wsp) {
    String signaturePropertiesPath = stsClientConfig.getSignatureProperties();
    String encryptionPropertiesPath = stsClientConfig.getEncryptionProperties();
    String stsPropertiesPath = stsClientConfig.getTokenProperties();
    LOGGER.debug("Configuring proxy factory properties");
    if (wsp.endpointAddress != null) {
        LOGGER.debug("Configuring JaxWsProxyFactoryBean");
        Bus bus = clientFactory.getBus();
        if (bus == null) {
            LOGGER.debug("Getting CXF thread default bus.");
            bus = BusFactory.getThreadDefaultBus();
        }
        clientFactory.setWsdlURL(wsp.endpointWsdlURL);
        clientFactory.setAddress(wsp.endpointAddress);
        clientFactory.setServiceName(wsp.serviceName);
        clientFactory.setEndpointName(wsp.endpointName);
        clientFactory.setServiceClass(wsp.serviceClass);
        LOGGER.debug("Configuring STS Client");
        HashMap<String, Object> properties = new HashMap<>();
        STSClient stsClient = configureSTSClient(bus);
        LOGGER.debug("Setting STSClient");
        properties.put(SecurityConstants.STS_CLIENT, stsClient);
        if (token != null && token.getToken() != null) {
            LOGGER.debug("Setting incoming SAML assertion to outgoing federated client");
            properties.put(SecurityConstants.TOKEN, token);
        }
        if (signaturePropertiesPath != null && !signaturePropertiesPath.isEmpty()) {
            LOGGER.debug("Setting signature properties: {}", signaturePropertiesPath);
            Properties signatureProperties = PropertiesLoader.loadProperties(signaturePropertiesPath);
            properties.put(SecurityConstants.SIGNATURE_PROPERTIES, signatureProperties);
        }
        if (stsPropertiesPath != null && !stsPropertiesPath.isEmpty()) {
            LOGGER.debug("Setting sts properties: {}", stsPropertiesPath);
            Properties stsProperties = PropertiesLoader.loadProperties(stsPropertiesPath);
            properties.put(SecurityConstants.STS_TOKEN_PROPERTIES, stsProperties);
        }
        if (encryptionPropertiesPath != null && !encryptionPropertiesPath.isEmpty()) {
            LOGGER.debug("Setting encryption properties: {}", encryptionPropertiesPath);
            Properties encryptionProperties = PropertiesLoader.loadProperties(encryptionPropertiesPath);
            properties.put(SecurityConstants.ENCRYPT_PROPERTIES, encryptionProperties);
        }
        properties.put(SecurityConstants.DISABLE_STS_CLIENT_WSMEX_CALL_USING_EPR_ADDRESS, Boolean.TRUE.toString());
        clientFactory.setProperties(properties);
    }
    LOGGER.debug("Finished configuring proxy factory properties");
}
Also used : Bus(org.apache.cxf.Bus) STSClient(org.apache.cxf.ws.security.trust.STSClient) HashMap(java.util.HashMap) Properties(java.util.Properties)

Example 29 with Bus

use of org.apache.cxf.Bus in project cas by apereo.

the class SecurityTokenServiceClientBuilder method buildClientForSecurityTokenRequests.

/**
     * Build client for security token requests.
     *
     * @param service the rp
     * @return the security token service client
     */
public SecurityTokenServiceClient buildClientForSecurityTokenRequests(final WSFederationRegisteredService service) {
    final Bus cxfBus = BusFactory.getDefaultBus();
    final SecurityTokenServiceClient sts = new SecurityTokenServiceClient(cxfBus);
    sts.setAddressingNamespace(StringUtils.defaultIfBlank(service.getAddressingNamespace(), WSFederationConstants.HTTP_WWW_W3_ORG_2005_08_ADDRESSING));
    sts.setTokenType(StringUtils.defaultIfBlank(service.getTokenType(), WSConstants.WSS_SAML2_TOKEN_TYPE));
    sts.setKeyType(WSFederationConstants.HTTP_DOCS_OASIS_OPEN_ORG_WS_SX_WS_TRUST_200512_BEARER);
    sts.setWsdlLocation(prepareWsdlLocation(service));
    if (StringUtils.isNotBlank(service.getPolicyNamespace())) {
        sts.setWspNamespace(service.getPolicyNamespace());
    }
    final String namespace = StringUtils.defaultIfBlank(service.getNamespace(), WSFederationConstants.HTTP_DOCS_OASIS_OPEN_ORG_WS_SX_WS_TRUST_200512);
    sts.setServiceQName(new QName(namespace, StringUtils.defaultIfBlank(service.getWsdlService(), WSFederationConstants.SECURITY_TOKEN_SERVICE)));
    sts.setEndpointQName(new QName(namespace, service.getWsdlEndpoint()));
    sts.getProperties().putAll(new HashMap<>());
    return sts;
}
Also used : Bus(org.apache.cxf.Bus) QName(javax.xml.namespace.QName)

Example 30 with Bus

use of org.apache.cxf.Bus in project camel by apache.

the class WSSecurityRouteTest method testUsernameToken.

@Test
public void testUsernameToken() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = WSSecurityRouteTest.class.getResource("../client/wssec.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    GreeterService gs = new GreeterService();
    Greeter greeter = gs.getGreeterUsernameTokenPort();
    ((BindingProvider) greeter).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + CXFTestSupport.getPort2() + "/WSSecurityRouteTest/GreeterUsernameTokenPort");
    assertEquals("Get a wrong response", "Hello Security", greeter.greetMe("Security"));
}
Also used : Bus(org.apache.cxf.Bus) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) Greeter(org.apache.camel.hello_world_soap_http.Greeter) GreeterService(org.apache.camel.hello_world_soap_http.GreeterService) URL(java.net.URL) Test(org.junit.Test)

Aggregations

Bus (org.apache.cxf.Bus)57 Test (org.junit.Test)31 URL (java.net.URL)19 QName (javax.xml.namespace.QName)15 Service (javax.xml.ws.Service)12 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)11 Exchange (org.apache.cxf.message.Exchange)9 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)9 Message (org.apache.cxf.message.Message)9 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)9 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)9 WrapThreadContextClassLoader (org.jboss.as.test.integration.ws.WrapThreadContextClassLoader)9 ServiceIface (org.jboss.as.test.integration.ws.wsse.trust.service.ServiceIface)7 IOException (java.io.IOException)6 ActAsServiceIface (org.jboss.as.test.integration.ws.wsse.trust.actas.ActAsServiceIface)6 OnBehalfOfServiceIface (org.jboss.as.test.integration.ws.wsse.trust.onbehalfof.OnBehalfOfServiceIface)6 CamelContext (org.apache.camel.CamelContext)4 Message (org.apache.camel.Message)4 Greeter (org.apache.camel.hello_world_soap_http.Greeter)4 GreeterService (org.apache.camel.hello_world_soap_http.GreeterService)4