use of org.apache.cxf.ws.security.trust.STSClient in project cxf by apache.
the class WSSCTest method testSecureConversation.
@Test
public void testSecureConversation() throws Exception {
final wssec.wssc.IPingService port = svc.getPort(new QName("http://WSSec/wssc", test.prefix), wssec.wssc.IPingService.class);
if (PORT2.equals(test.port) || STAX_PORT2.equals(test.port)) {
((BindingProvider) port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "https://localhost:" + test.port + "/" + test.prefix);
} else {
((BindingProvider) port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + test.port + "/" + test.prefix);
}
if (test.prefix.charAt(0) == '_') {
// MS would like the _ versions to send a cancel
((BindingProvider) port).getRequestContext().put(SecurityConstants.STS_TOKEN_DO_CANCEL, Boolean.TRUE);
}
if (test.streaming) {
((BindingProvider) port).getRequestContext().put(SecurityConstants.ENABLE_STREAMING_SECURITY, "true");
((BindingProvider) port).getResponseContext().put(SecurityConstants.ENABLE_STREAMING_SECURITY, "true");
}
if (test.clearAction) {
AbstractPhaseInterceptor<Message> clearActionInterceptor = new AbstractPhaseInterceptor<Message>(Phase.POST_LOGICAL) {
public void handleMessage(Message message) throws Fault {
STSClient client = STSUtils.getClient(message, "sct");
client.getOutInterceptors().add(this);
message.put(SecurityConstants.STS_CLIENT, client);
String s = (String) message.get(SoapBindingConstants.SOAP_ACTION);
if (s == null) {
s = SoapActionInInterceptor.getSoapAction(message);
}
if (s != null && s.contains("RST/SCT")) {
message.put(SoapBindingConstants.SOAP_ACTION, "");
}
}
};
clearActionInterceptor.addBefore(SoapPreProtocolOutInterceptor.class.getName());
((Client) port).getOutInterceptors().add(clearActionInterceptor);
}
wssec.wssc.PingRequest params = new wssec.wssc.PingRequest();
org.xmlsoap.ping.Ping ping = new org.xmlsoap.ping.Ping();
ping.setOrigin("CXF");
ping.setScenario("Scenario5");
ping.setText("ping");
params.setPing(ping);
try {
wssec.wssc.PingResponse output = port.ping(params);
assertEquals(OUT, output.getPingResponse().getText());
} catch (Exception ex) {
throw new Exception("Error doing " + test.prefix, ex);
}
((java.io.Closeable) port).close();
}
use of org.apache.cxf.ws.security.trust.STSClient in project cxf by apache.
the class WSSCUnitTest method testIssueUnitTest.
@Test
public void testIssueUnitTest() throws Exception {
if (test.isStreaming()) {
return;
}
SpringBusFactory bf = new SpringBusFactory();
URL busFile = WSSCUnitTest.class.getResource("client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
STSClient stsClient = new STSClient(bus);
stsClient.setSecureConv(true);
stsClient.setLocation("https://localhost:" + PORT + "/" + "DoubleItTransport");
// Add Addressing policy
Policy p = new Policy();
ExactlyOne ea = new ExactlyOne();
p.addPolicyComponent(ea);
All all = new All();
all.addPolicyComponent(new PrimitiveAssertion(MetadataConstants.USING_ADDRESSING_2006_QNAME, false));
ea.addPolicyComponent(all);
stsClient.setPolicy(p);
stsClient.requestSecurityToken("http://localhost:" + PORT + "/" + "DoubleItTransport");
}
use of org.apache.cxf.ws.security.trust.STSClient in project wildfly by wildfly.
the class WSTrustTestUtils method setupWsseAndSTSClientNoCallbackHandler.
/**
* A PASSWORD is provided in place of the ClientCallbackHandler in the
* STSClient. A USERNAME and PASSWORD is required by CXF in the msg.
*
* @param proxy
* @param bus
* @param stsWsdlLocation
* @param stsService
* @param stsPort
* @see org.apache.cxf.ws.security.SecurityConstants#PASSWORD
*/
public static void setupWsseAndSTSClientNoCallbackHandler(ServiceIface proxy, Bus bus, String stsWsdlLocation, QName stsService, QName stsPort) {
Map<String, Object> ctx = ((BindingProvider) proxy).getRequestContext();
setServiceContextAttributes(ctx);
STSClient stsClient = new STSClient(bus);
if (stsWsdlLocation != null) {
stsClient.setWsdlLocation(stsWsdlLocation);
stsClient.setServiceQName(stsService);
stsClient.setEndpointQName(stsPort);
}
Map<String, Object> props = stsClient.getProperties();
props.put(SecurityConstants.USERNAME, "alice");
props.put(SecurityConstants.PASSWORD, "clarinet");
props.put(SecurityConstants.ENCRYPT_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("META-INF/clientKeystore.properties"));
props.put(SecurityConstants.ENCRYPT_USERNAME, "mystskey");
props.put(SecurityConstants.STS_TOKEN_USERNAME, "myclientkey");
props.put(SecurityConstants.STS_TOKEN_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("META-INF/clientKeystore.properties"));
props.put(SecurityConstants.STS_TOKEN_USE_CERT_FOR_KEYINFO, "true");
ctx.put(SecurityConstants.STS_CLIENT, stsClient);
}
use of org.apache.cxf.ws.security.trust.STSClient in project wildfly by wildfly.
the class WSTrustTestUtils method setupWsseAndSTSClientOnBehalfOf.
/**
* Request a security token that allows it to act on the behalf of somebody else.
*
* @param proxy
* @param bus
*/
public static void setupWsseAndSTSClientOnBehalfOf(BindingProvider proxy, Bus bus) {
Map<String, Object> ctx = proxy.getRequestContext();
ctx.put(SecurityConstants.CALLBACK_HANDLER, new ClientCallbackHandler());
ctx.put(SecurityConstants.ENCRYPT_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("META-INF/clientKeystore.properties"));
ctx.put(SecurityConstants.ENCRYPT_USERNAME, "myactaskey");
ctx.put(SecurityConstants.SIGNATURE_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("META-INF/clientKeystore.properties"));
ctx.put(SecurityConstants.SIGNATURE_USERNAME, "myclientkey");
ctx.put(SecurityConstants.USERNAME, "alice");
ctx.put(SecurityConstants.PASSWORD, "clarinet");
STSClient stsClient = new STSClient(bus);
stsClient.setOnBehalfOf(new UsernameTokenCallbackHandler());
Map<String, Object> props = stsClient.getProperties();
props.put(SecurityConstants.CALLBACK_HANDLER, new ClientCallbackHandler());
props.put(SecurityConstants.ENCRYPT_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("META-INF/clientKeystore.properties"));
props.put(SecurityConstants.ENCRYPT_USERNAME, "mystskey");
props.put(SecurityConstants.STS_TOKEN_USERNAME, "myclientkey");
props.put(SecurityConstants.STS_TOKEN_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("META-INF/clientKeystore.properties"));
props.put(SecurityConstants.STS_TOKEN_USE_CERT_FOR_KEYINFO, "true");
ctx.put(SecurityConstants.STS_CLIENT, stsClient);
}
use of org.apache.cxf.ws.security.trust.STSClient in project wildfly by wildfly.
the class WSTrustTestUtils method setupWsseAndSTSClientBearer.
public static void setupWsseAndSTSClientBearer(BindingProvider proxy, Bus bus) {
Map<String, Object> ctx = proxy.getRequestContext();
STSClient stsClient = new STSClient(bus);
ctx.put(SecurityConstants.CALLBACK_HANDLER, new ClientCallbackHandler());
ctx.put(SecurityConstants.SIGNATURE_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("META-INF/clientKeystore.properties"));
ctx.put(SecurityConstants.ENCRYPT_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("META-INF/clientKeystore.properties"));
ctx.put(SecurityConstants.SIGNATURE_USERNAME, "myclientkey");
ctx.put(SecurityConstants.ENCRYPT_USERNAME, "myservicekey");
ctx.put(appendIssuedTokenSuffix(SecurityConstants.USERNAME), "alice");
ctx.put(appendIssuedTokenSuffix(SecurityConstants.CALLBACK_HANDLER), new ClientCallbackHandler());
ctx.put(appendIssuedTokenSuffix(SecurityConstants.ENCRYPT_PROPERTIES), Thread.currentThread().getContextClassLoader().getResource("META-INF/clientKeystore.properties"));
ctx.put(appendIssuedTokenSuffix(SecurityConstants.ENCRYPT_USERNAME), "mystskey");
ctx.put(appendIssuedTokenSuffix(SecurityConstants.STS_TOKEN_USERNAME), "myclientkey");
ctx.put(appendIssuedTokenSuffix(SecurityConstants.STS_TOKEN_PROPERTIES), Thread.currentThread().getContextClassLoader().getResource("META-INF/clientKeystore.properties"));
ctx.put(appendIssuedTokenSuffix(SecurityConstants.STS_TOKEN_USE_CERT_FOR_KEYINFO), "true");
ctx.put(SecurityConstants.STS_CLIENT, stsClient);
}
Aggregations