Search in sources :

Example 1 with STSTokenOutInterceptor

use of org.apache.cxf.ws.security.policy.interceptors.STSTokenOutInterceptor in project cxf by apache.

the class STSTokenOutInterceptorTest method testBasicAsymmetricBinding.

@Test
public void testBasicAsymmetricBinding() throws Exception {
    Bus bus = BusFactory.getThreadDefaultBus();
    STSAuthParams authParams = new STSAuthParams(AuthMode.X509_ASSYMETRIC, null, "org.apache.cxf.systest.sts.common.CommonCallbackHandler", "mystskey", "clientKeystore.properties");
    STSTokenOutInterceptor interceptor = new STSTokenOutInterceptor(authParams, "http://localhost:" + STSPORT2 + STS_X509_WSDL_LOCATION_RELATIVE, bus);
    MessageImpl message = prepareMessage(bus, null, SERVICE_ENDPOINT_ASSYMETRIC);
    interceptor.handleMessage(message);
    SecurityToken token = (SecurityToken) message.getExchange().get(SecurityConstants.TOKEN);
    validateSecurityToken(token);
}
Also used : SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) Bus(org.apache.cxf.Bus) STSTokenOutInterceptor(org.apache.cxf.ws.security.policy.interceptors.STSTokenOutInterceptor) STSAuthParams(org.apache.cxf.ws.security.trust.STSAuthParams) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 2 with STSTokenOutInterceptor

use of org.apache.cxf.ws.security.policy.interceptors.STSTokenOutInterceptor in project cxf by apache.

the class STSTokenOutInterceptorTest method testSTSClientAsymmetricBinding.

@Test
public void testSTSClientAsymmetricBinding() throws Exception {
    Bus bus = BusFactory.getThreadDefaultBus();
    STSClient stsClient = initStsClientAsymmeticBinding(bus);
    STSTokenOutInterceptor interceptor = new STSTokenOutInterceptor(stsClient);
    MessageImpl message = prepareMessage(bus, null, SERVICE_ENDPOINT_ASSYMETRIC);
    interceptor.handleMessage(message);
    SecurityToken token = (SecurityToken) message.getExchange().get(SecurityConstants.TOKEN);
    validateSecurityToken(token);
}
Also used : SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) Bus(org.apache.cxf.Bus) 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 3 with STSTokenOutInterceptor

use of org.apache.cxf.ws.security.policy.interceptors.STSTokenOutInterceptor in project cxf by apache.

the class JaxrsJWTTest method testSuccessfulInvocation.

@org.junit.Test
public void testSuccessfulInvocation() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = JaxrsJWTTest.class.getResource("cxf-client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    final String address = "https://localhost:" + PORT + "/doubleit/services/doubleit-rs";
    final int numToDouble = 25;
    List<Object> providers = Collections.singletonList(new JwtOutFilter());
    WebClient client = WebClient.create(address, providers);
    client.type("text/plain").accept("text/plain");
    STSClient stsClient = getSTSClient(JWT_TOKEN_TYPE, bus);
    STSTokenOutInterceptor stsInterceptor = new STSTokenOutInterceptor(Phase.PRE_LOGICAL, stsClient, new TokenRequestParams());
    stsInterceptor.getBefore().add(JwtOutFilter.class.getName());
    WebClient.getConfig(client).getOutInterceptors().add(stsInterceptor);
    int resp = client.post(numToDouble, Integer.class);
    org.junit.Assert.assertEquals(2 * numToDouble, resp);
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) STSClient(org.apache.cxf.ws.security.trust.STSClient) STSTokenOutInterceptor(org.apache.cxf.ws.security.policy.interceptors.STSTokenOutInterceptor) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) TokenRequestParams(org.apache.cxf.ws.security.trust.STSTokenRetriever.TokenRequestParams) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Example 4 with STSTokenOutInterceptor

use of org.apache.cxf.ws.security.policy.interceptors.STSTokenOutInterceptor 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 5 with STSTokenOutInterceptor

use of org.apache.cxf.ws.security.policy.interceptors.STSTokenOutInterceptor 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)

Aggregations

Bus (org.apache.cxf.Bus)5 STSTokenOutInterceptor (org.apache.cxf.ws.security.policy.interceptors.STSTokenOutInterceptor)5 MessageImpl (org.apache.cxf.message.MessageImpl)4 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)4 STSClient (org.apache.cxf.ws.security.trust.STSClient)4 Test (org.junit.Test)4 TLSClientParameters (org.apache.cxf.configuration.jsse.TLSClientParameters)2 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)2 STSAuthParams (org.apache.cxf.ws.security.trust.STSAuthParams)2 URL (java.net.URL)1 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)1 WebClient (org.apache.cxf.jaxrs.client.WebClient)1 TokenRequestParams (org.apache.cxf.ws.security.trust.STSTokenRetriever.TokenRequestParams)1