use of org.apache.cxf.ws.security.trust.STSClient in project cxf by apache.
the class TemplateTest method testSendSAML1ToSAML2PublicKey.
@org.junit.Test
public void testSendSAML1ToSAML2PublicKey() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = TemplateTest.class.getResource("cxf-client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = TemplateTest.class.getResource("DoubleItNoTemplate.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItTransportSAML2PublicKeyPort");
DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(port, test.getPort());
// Setup STSClient
STSClient stsClient = createSTSClient(bus);
stsClient.setKeyType("http://docs.oasis-open.org/ws-sx/ws-trust/200512/PublicKey");
stsClient.setTokenType("http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1");
String wsdlLocation = "https://localhost:" + test.getStsPort() + "/SecurityTokenService/Transport?wsdl";
stsClient.setWsdlLocation(wsdlLocation);
((BindingProvider) port).getRequestContext().put(SecurityConstants.STS_CLIENT, stsClient);
if (test.isStreaming()) {
SecurityTestUtil.enableStreaming(port);
}
try {
doubleIt(port, 25);
fail("Failure expected on sending a SAML 1.1 token");
} catch (Exception ex) {
// expected
}
((java.io.Closeable) port).close();
bus.shutdown(true);
}
use of org.apache.cxf.ws.security.trust.STSClient in project cxf by apache.
the class TransportBindingTest method testSAML2DispatchLocation.
@org.junit.Test
public void testSAML2DispatchLocation() throws Exception {
// Needed to prevent test failure using IBM JDK
if ("IBM Corporation".equals(System.getProperty("java.vendor"))) {
System.setProperty("https.protocols", "TLSv1");
}
SpringBusFactory bf = new SpringBusFactory();
URL busFile = TransportBindingTest.class.getResource("cxf-client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = TransportBindingTest.class.getResource("DoubleIt.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItTransportSAML2Port");
Dispatch<DOMSource> dispatch = service.createDispatch(portQName, DOMSource.class, Service.Mode.PAYLOAD);
updateAddressPort(dispatch, test.getPort());
// Setup STSClient
STSClient stsClient = createDispatchSTSClient(bus);
String location = "https://localhost:" + test.getStsPort() + "/SecurityTokenService/Transport";
stsClient.setLocation(location);
stsClient.setPolicy("classpath:/org/apache/cxf/systest/sts/issuer/sts-transport-policy.xml");
// Creating a DOMSource Object for the request
DOMSource request = createDOMRequest();
// Make a successful request
Client client = ((DispatchImpl<DOMSource>) dispatch).getClient();
client.getRequestContext().put(SecurityConstants.USERNAME, "alice");
client.getRequestContext().put(SecurityConstants.STS_CLIENT, stsClient);
if (test.isStreaming()) {
client.getRequestContext().put(SecurityConstants.ENABLE_STREAMING_SECURITY, "true");
client.getResponseContext().put(SecurityConstants.ENABLE_STREAMING_SECURITY, "true");
}
DOMSource response = dispatch.invoke(request);
assertNotNull(response);
bus.shutdown(true);
}
use of org.apache.cxf.ws.security.trust.STSClient in project cxf by apache.
the class TransportBindingTest method createDispatchSTSClient.
private STSClient createDispatchSTSClient(Bus bus) {
STSClient stsClient = new STSClient(bus);
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> properties = new HashMap<>();
properties.put(SecurityConstants.USERNAME, "alice");
properties.put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.sts.common.CommonCallbackHandler");
properties.put("ws-security.sts.token.username", "myclientkey");
properties.put("ws-security.sts.token.properties", "clientKeystore.properties");
properties.put("ws-security.sts.token.usecert", "true");
stsClient.setProperties(properties);
return stsClient;
}
use of org.apache.cxf.ws.security.trust.STSClient in project cxf by apache.
the class TransportBindingTest method testSAML2Dispatch.
@org.junit.Test
public void testSAML2Dispatch() throws Exception {
// Needed to prevent test failure using IBM JDK
if ("IBM Corporation".equals(System.getProperty("java.vendor"))) {
System.setProperty("https.protocols", "TLSv1");
}
SpringBusFactory bf = new SpringBusFactory();
URL busFile = TransportBindingTest.class.getResource("cxf-client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = TransportBindingTest.class.getResource("DoubleIt.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItTransportSAML2Port");
Dispatch<DOMSource> dispatch = service.createDispatch(portQName, DOMSource.class, Service.Mode.PAYLOAD);
updateAddressPort(dispatch, test.getPort());
// Setup STSClient
STSClient stsClient = createDispatchSTSClient(bus);
String wsdlLocation = "https://localhost:" + test.getStsPort() + "/SecurityTokenService/Transport?wsdl";
stsClient.setWsdlLocation(wsdlLocation);
// Creating a DOMSource Object for the request
DOMSource request = createDOMRequest();
// Make a successful request
Client client = ((DispatchImpl<DOMSource>) dispatch).getClient();
client.getRequestContext().put(SecurityConstants.USERNAME, "alice");
client.getRequestContext().put(SecurityConstants.STS_CLIENT, stsClient);
if (test.isStreaming()) {
client.getRequestContext().put(SecurityConstants.ENABLE_STREAMING_SECURITY, "true");
client.getResponseContext().put(SecurityConstants.ENABLE_STREAMING_SECURITY, "true");
}
DOMSource response = dispatch.invoke(request);
assertNotNull(response);
bus.shutdown(true);
}
use of org.apache.cxf.ws.security.trust.STSClient in project cxf by apache.
the class SecurityTestUtil method updateSTSPort.
public static void updateSTSPort(BindingProvider p, String port) {
STSClient stsClient = (STSClient) p.getRequestContext().get(org.apache.cxf.rt.security.SecurityConstants.STS_CLIENT);
if (stsClient != null) {
String location = stsClient.getWsdlLocation();
if (location != null && location.contains("8080")) {
stsClient.setWsdlLocation(location.replace("8080", port));
} else if (location != null && location.contains("8443")) {
stsClient.setWsdlLocation(location.replace("8443", port));
}
}
stsClient = (STSClient) p.getRequestContext().get(org.apache.cxf.rt.security.SecurityConstants.STS_CLIENT + ".sct");
if (stsClient != null) {
String location = stsClient.getWsdlLocation();
if (location.contains("8080")) {
stsClient.setWsdlLocation(location.replace("8080", port));
} else if (location.contains("8443")) {
stsClient.setWsdlLocation(location.replace("8443", port));
}
}
}
Aggregations