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);
}
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);
}
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);
}
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);
}
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();
}
}
Aggregations