Search in sources :

Example 71 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.

the class STSTokenOutInterceptorTest method testSTSClientTransportBinding.

@Test
public void testSTSClientTransportBinding() throws Exception {
    // Setup HttpsURLConnection to get STS WSDL
    configureDefaultHttpsConnection();
    Bus bus = BusFactory.getThreadDefaultBus();
    STSClient stsClient = initStsClientTransportBinding(bus);
    STSTokenOutInterceptor interceptor = new STSTokenOutInterceptor(stsClient);
    TLSClientParameters tlsParams = prepareTLSParams();
    ((HTTPConduit) stsClient.getClient().getConduit()).setTlsClientParameters(tlsParams);
    MessageImpl message = prepareMessage(bus, null, SERVICE_ENDPOINT_TRANSPORT);
    interceptor.handleMessage(message);
    SecurityToken token = (SecurityToken) message.getExchange().get(SecurityConstants.TOKEN);
    validateSecurityToken(token);
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) Bus(org.apache.cxf.Bus) TLSClientParameters(org.apache.cxf.configuration.jsse.TLSClientParameters) STSClient(org.apache.cxf.ws.security.trust.STSClient) STSTokenOutInterceptor(org.apache.cxf.ws.security.policy.interceptors.STSTokenOutInterceptor) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 72 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.

the class STSTokenOutInterceptorTest method testBasicTransportBinding.

@Test
public void testBasicTransportBinding() throws Exception {
    // Setup HttpsURLConnection to get STS WSDL
    configureDefaultHttpsConnection();
    Bus bus = BusFactory.getThreadDefaultBus();
    STSAuthParams authParams = new STSAuthParams(AuthMode.UT_TRANSPORT, "alice", "org.apache.cxf.systest.sts.common.CommonCallbackHandler", null, null);
    STSTokenOutInterceptor interceptor = new STSTokenOutInterceptor(authParams, "https://localhost:" + STSPORT + STS_TRANSPORT_WSDL_LOCATION_RELATIVE, bus);
    TLSClientParameters tlsParams = prepareTLSParams();
    STSClient stsClient = interceptor.getSTSClient();
    ((HTTPConduit) stsClient.getClient().getConduit()).setTlsClientParameters(tlsParams);
    MessageImpl message = prepareMessage(bus, null, SERVICE_ENDPOINT_TRANSPORT);
    interceptor.handleMessage(message);
    SecurityToken token = (SecurityToken) message.getExchange().get(SecurityConstants.TOKEN);
    validateSecurityToken(token);
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) Bus(org.apache.cxf.Bus) TLSClientParameters(org.apache.cxf.configuration.jsse.TLSClientParameters) STSTokenOutInterceptor(org.apache.cxf.ws.security.policy.interceptors.STSTokenOutInterceptor) STSClient(org.apache.cxf.ws.security.trust.STSClient) STSAuthParams(org.apache.cxf.ws.security.trust.STSAuthParams) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 73 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.

the class STSTokenRetrieverTest method testSTSTransportBinding.

@Test
public void testSTSTransportBinding() throws Exception {
    // Setup HttpsURLConnection to get STS WSDL
    configureDefaultHttpsConnection();
    Bus bus = BusFactory.getThreadDefaultBus();
    STSClient stsClient = initStsClientTransportBinding(bus);
    TLSClientParameters tlsParams = prepareTLSParams();
    ((HTTPConduit) stsClient.getClient().getConduit()).setTlsClientParameters(tlsParams);
    MessageImpl message = prepareMessage(bus, stsClient, SERVICE_ENDPOINT_TRANSPORT);
    STSTokenRetriever.TokenRequestParams params = new STSTokenRetriever.TokenRequestParams();
    SecurityToken token = STSTokenRetriever.getToken(message, params);
    validateSecurityToken(token);
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) Bus(org.apache.cxf.Bus) TLSClientParameters(org.apache.cxf.configuration.jsse.TLSClientParameters) STSClient(org.apache.cxf.ws.security.trust.STSClient) STSTokenRetriever(org.apache.cxf.ws.security.trust.STSTokenRetriever) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 74 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.

the class TransportBindingTest method testSAML2ViaCode.

@org.junit.Test
public void testSAML2ViaCode() throws Exception {
    URL wsdl = TransportBindingTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItTransportSAML2Port");
    DoubleItPortType transportSaml2Port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(transportSaml2Port, test.getPort());
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(transportSaml2Port);
    }
    // TLS configuration
    TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    final KeyStore ts = KeyStore.getInstance("JKS");
    try (InputStream trustStore = ClassLoaderUtils.getResourceAsStream("keys/clientstore.jks", TransportBindingTest.class)) {
        ts.load(trustStore, "cspass".toCharArray());
    }
    tmf.init(ts);
    kmf.init(ts, "ckpass".toCharArray());
    TLSClientParameters tlsParams = new TLSClientParameters();
    tlsParams.setTrustManagers(tmf.getTrustManagers());
    tlsParams.setKeyManagers(kmf.getKeyManagers());
    tlsParams.setDisableCNCheck(true);
    Client client = ClientProxy.getClient(transportSaml2Port);
    HTTPConduit http = (HTTPConduit) client.getConduit();
    http.setTlsClientParameters(tlsParams);
    // STSClient configuration
    Bus clientBus = BusFactory.newInstance().createBus();
    STSClient stsClient = new STSClient(clientBus);
    // Use a local WSDL or else we run into problems retrieving the WSDL over HTTPS
    // due to lack of TLS config when creating the client
    URL stsWsdl = TransportBindingTest.class.getResource("../deployment/ws-trust-1.4-service.wsdl");
    stsClient.setWsdlLocation(stsWsdl.toString());
    stsClient.setServiceName("{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}SecurityTokenService");
    stsClient.setEndpointName("{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}Transport_Port");
    Map<String, Object> props = new HashMap<>();
    props.put("security.username", "alice");
    props.put("security.callback-handler", "org.apache.cxf.systest.sts.common.CommonCallbackHandler");
    props.put("security.sts.token.username", "myclientkey");
    props.put("security.sts.token.properties", "clientKeystore.properties");
    props.put("security.sts.token.usecert", "false");
    stsClient.setProperties(props);
    ((BindingProvider) transportSaml2Port).getRequestContext().put("security.sts.client", stsClient);
    // Update ports + HTTPS configuration for the STSClient
    updateAddressPort(stsClient.getClient(), test.getStsPort());
    ((HTTPConduit) stsClient.getClient().getConduit()).setTlsClientParameters(tlsParams);
    doubleIt(transportSaml2Port, 25);
    ((java.io.Closeable) transportSaml2Port).close();
    clientBus.shutdown(true);
}
Also used : TLSClientParameters(org.apache.cxf.configuration.jsse.TLSClientParameters) Bus(org.apache.cxf.Bus) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) InputStream(java.io.InputStream) Service(javax.xml.ws.Service) KeyStore(java.security.KeyStore) URL(java.net.URL) KeyManagerFactory(javax.net.ssl.KeyManagerFactory) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) STSClient(org.apache.cxf.ws.security.trust.STSClient) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) STSClient(org.apache.cxf.ws.security.trust.STSClient) Client(org.apache.cxf.endpoint.Client)

Example 75 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.

the class ClientServerTest method testBasicAuth.

@Test
public void testBasicAuth() throws Exception {
    Service service = Service.create(serviceName);
    service.addPort(fakePortName, "http://schemas.xmlsoap.org/soap/", "http://localhost:" + PORT + "/SoapContext/SoapPort");
    Greeter greeter = service.getPort(fakePortName, Greeter.class);
    try {
        // try the jaxws way
        BindingProvider bp = (BindingProvider) greeter;
        bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "BJ");
        bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "pswd");
        String s = greeter.greetMe("secure");
        assertEquals("Hello BJ", s);
        bp.getRequestContext().remove(BindingProvider.USERNAME_PROPERTY);
        bp.getRequestContext().remove(BindingProvider.PASSWORD_PROPERTY);
        // try setting on the conduit directly
        Client client = ClientProxy.getClient(greeter);
        HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
        AuthorizationPolicy policy = new AuthorizationPolicy();
        policy.setUserName("BJ2");
        policy.setPassword("pswd");
        httpConduit.setAuthorization(policy);
        s = greeter.greetMe("secure");
        assertEquals("Hello BJ2", s);
    } catch (UndeclaredThrowableException ex) {
        throw (Exception) ex.getCause();
    }
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) Greeter(org.apache.hello_world_soap_http.Greeter) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SOAPService(org.apache.hello_world_soap_http.SOAPService) Service(javax.xml.ws.Service) ExecutorService(java.util.concurrent.ExecutorService) BindingProvider(javax.xml.ws.BindingProvider) Client(org.apache.cxf.endpoint.Client) SOAPServiceMultiPortTypeTest(org.apache.hello_world_soap_http.SOAPServiceMultiPortTypeTest) SOAPServiceBogusAddressTest(org.apache.hello_world_soap_http.SOAPServiceBogusAddressTest) Test(org.junit.Test)

Aggregations

HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)125 Client (org.apache.cxf.endpoint.Client)52 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)47 Test (org.junit.Test)42 URL (java.net.URL)35 Bus (org.apache.cxf.Bus)32 TLSClientParameters (org.apache.cxf.configuration.jsse.TLSClientParameters)32 QName (javax.xml.namespace.QName)22 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)20 Service (javax.xml.ws.Service)16 KeyStore (java.security.KeyStore)15 AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)15 Greeter (org.apache.hello_world.Greeter)14 SOAPService (org.apache.hello_world.services.SOAPService)14 TrustManager (javax.net.ssl.TrustManager)13 IOException (java.io.IOException)12 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)11 InputStream (java.io.InputStream)8 X509TrustManager (javax.net.ssl.X509TrustManager)8 BindingProvider (javax.xml.ws.BindingProvider)8