use of org.apache.cxf.ws.security.trust.STSClient in project ddf by codice.
the class StsIssueTest method requestSecurityToken.
private SecurityToken requestSecurityToken(String tokenType, String keyType, Element supportingToken, Bus bus, String endpointAddress, String wsdlLocation, String endpointName, Element claims) {
STSClient stsClient = new STSClient(bus);
stsClient.setWsdlLocation(wsdlLocation);
stsClient.setEndpointName(endpointName);
stsClient.setServiceName("{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}SecurityTokenService");
Map<String, Object> properties = new HashMap<String, Object>();
// XXX - Not sure how this is used - doesn't show up in the payload. -
// Should this be "client"?
// properties.put(SecurityConstants.USERNAME, "kcwire");
// properties
// .put(SecurityConstants.CALLBACK_HANDLER,
// "org.apache.cxf.ws.security.trust.delegation.WSSUsernameCallbackHandler");
properties.put(SecurityConstants.IS_BSP_COMPLIANT, "false");
// }
if (supportingToken != null) {
stsClient.setOnBehalfOf(supportingToken);
}
stsClient.setClaims(claims);
stsClient.setProperties(properties);
stsClient.setTokenType(tokenType);
stsClient.setKeyType(keyType);
SecurityToken token = null;
try {
token = stsClient.requestSecurityToken(endpointAddress);
} catch (Exception e) {
LOGGER.info("Error requesting the SecurityToken.", e);
}
return token;
}
use of org.apache.cxf.ws.security.trust.STSClient in project cxf by apache.
the class WSSCUnitTest method testIssueAndRenewUnitTest.
@Test
public void testIssueAndRenewUnitTest() 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("http://localhost:" + PORT2 + "/" + "DoubleItSymmetric");
stsClient.setPolicy(createSymmetricBindingPolicy());
Map<String, Object> properties = new HashMap<>();
properties.put(SecurityConstants.ENCRYPT_USERNAME, "bob");
TokenCallbackHandler callbackHandler = new TokenCallbackHandler();
properties.put(SecurityConstants.CALLBACK_HANDLER, callbackHandler);
properties.put(SecurityConstants.SIGNATURE_PROPERTIES, "alice.properties");
properties.put(SecurityConstants.ENCRYPT_PROPERTIES, "bob.properties");
stsClient.setProperties(properties);
SecurityToken securityToken = stsClient.requestSecurityToken("http://localhost:" + PORT2 + "/" + "DoubleItSymmetric");
assertNotNull(securityToken);
callbackHandler.setSecurityToken(securityToken);
assertNotNull(stsClient.renewSecurityToken(securityToken));
}
use of org.apache.cxf.ws.security.trust.STSClient in project cxf by apache.
the class WSSCUnitTest method testIssueAndCancelUnitTest.
@Test
public void testIssueAndCancelUnitTest() 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("http://localhost:" + PORT2 + "/" + "DoubleItSymmetric");
stsClient.setPolicy(createSymmetricBindingPolicy());
Map<String, Object> properties = new HashMap<>();
properties.put(SecurityConstants.ENCRYPT_USERNAME, "bob");
TokenCallbackHandler callbackHandler = new TokenCallbackHandler();
properties.put(SecurityConstants.CALLBACK_HANDLER, callbackHandler);
properties.put(SecurityConstants.SIGNATURE_PROPERTIES, "alice.properties");
properties.put(SecurityConstants.ENCRYPT_PROPERTIES, "bob.properties");
stsClient.setProperties(properties);
SecurityToken securityToken = stsClient.requestSecurityToken("http://localhost:" + PORT2 + "/" + "DoubleItSymmetric");
assertNotNull(securityToken);
callbackHandler.setSecurityToken(securityToken);
assertTrue(stsClient.cancelSecurityToken(securityToken));
}
use of org.apache.cxf.ws.security.trust.STSClient in project cxf by apache.
the class WSSCUnitTest method testEndorsingSecureConverationViaCode.
@Test
public void testEndorsingSecureConverationViaCode() throws Exception {
URL wsdl = WSSCUnitTest.class.getResource("DoubleItWSSC.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItTransportPort");
DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(port, test.getPort());
if (test.isStreaming()) {
SecurityTestUtil.enableStreaming(port);
}
// TLS configuration
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
final KeyStore ts = KeyStore.getInstance("JKS");
try (InputStream trustStore = ClassLoaderUtils.getResourceAsStream("keys/Truststore.jks", WSSCUnitTest.class)) {
ts.load(trustStore, "password".toCharArray());
}
tmf.init(ts);
TLSClientParameters tlsParams = new TLSClientParameters();
tlsParams.setTrustManagers(tmf.getTrustManagers());
tlsParams.setDisableCNCheck(true);
Client client = ClientProxy.getClient(port);
HTTPConduit http = (HTTPConduit) client.getConduit();
http.setTlsClientParameters(tlsParams);
// STSClient configuration
Bus clientBus = BusFactory.newInstance().createBus();
STSClient stsClient = new STSClient(clientBus);
stsClient.setTlsClientParameters(tlsParams);
((BindingProvider) port).getRequestContext().put("security.sts.client", stsClient);
assertEquals(50, port.doubleIt(25));
((java.io.Closeable) port).close();
}
use of org.apache.cxf.ws.security.trust.STSClient in project cxf by apache.
the class SecureConversationOutInterceptor method renewToken.
private SecurityToken renewToken(SoapMessage message, AssertionInfoMap aim, SecurityToken tok, SecureConversationToken itok) {
if (!tok.isExpired()) {
return tok;
}
// Remove the old token
message.getExchange().getEndpoint().remove(SecurityConstants.TOKEN);
message.getExchange().getEndpoint().remove(SecurityConstants.TOKEN_ID);
message.getExchange().remove(SecurityConstants.TOKEN_ID);
message.getExchange().remove(SecurityConstants.TOKEN);
TokenStoreUtils.getTokenStore(message).remove(tok.getId());
STSClient client = STSUtils.getClient(message, "sct");
AddressingProperties maps = (AddressingProperties) message.get("javax.xml.ws.addressing.context.outbound");
if (maps == null) {
maps = (AddressingProperties) message.get("javax.xml.ws.addressing.context");
} else if (maps.getAction().getValue().endsWith("Renew")) {
return tok;
}
synchronized (client) {
try {
SecureConversationTokenInterceptorProvider.setupClient(client, message, aim, itok, true);
String s = message.getContextualProperty(Message.ENDPOINT_ADDRESS).toString();
client.setLocation(s);
Map<String, Object> ctx = client.getRequestContext();
ctx.put(SecurityConstants.TOKEN_ID, tok.getId());
if (maps != null) {
client.setAddressingNamespace(maps.getNamespaceURI());
}
return client.renewSecurityToken(tok);
} catch (RuntimeException ex) {
LOG.log(Level.WARNING, "Error renewing a token", ex);
boolean issueAfterFailedRenew = MessageUtils.getContextualBoolean(message, SecurityConstants.STS_ISSUE_AFTER_FAILED_RENEW, true);
if (issueAfterFailedRenew) {
// Perhaps the STS does not support renewing, so try to issue a new token
return issueToken(message, aim, itok);
}
throw ex;
} catch (Exception ex) {
LOG.log(Level.WARNING, "Error renewing a token", ex);
boolean issueAfterFailedRenew = MessageUtils.getContextualBoolean(message, SecurityConstants.STS_ISSUE_AFTER_FAILED_RENEW, true);
if (issueAfterFailedRenew) {
// Perhaps the STS does not support renewing, so try to issue a new token
return issueToken(message, aim, itok);
}
throw new Fault(ex);
} finally {
client.setTrust((Trust10) null);
client.setTrust((Trust13) null);
client.setTemplate(null);
client.setLocation(null);
client.setAddressingNamespace(null);
}
}
}
Aggregations