use of org.apache.cxf.ws.security.trust.STSClient in project cxf by apache.
the class Soap12Test method requestSecurityToken.
private SecurityToken requestSecurityToken(String tokenType, String keyType, Element supportingToken, Bus bus, String endpointAddress, String context) throws Exception {
STSClient stsClient = new STSClient(bus);
stsClient.setWsdlLocation("https://localhost:" + STSPORT + "/SecurityTokenService/TransportSoap12?wsdl");
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_Soap12_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(SecurityConstants.ENCRYPT_PROPERTIES, "clientKeystore.properties");
properties.put(SecurityConstants.ENCRYPT_USERNAME, "mystskey");
if (PUBLIC_KEY_KEYTYPE.equals(keyType)) {
properties.put(SecurityConstants.STS_TOKEN_USERNAME, "myclientkey");
properties.put(SecurityConstants.STS_TOKEN_PROPERTIES, "clientKeystore.properties");
stsClient.setUseCertificateForConfirmationKeyInfo(true);
}
if (supportingToken != null) {
stsClient.setOnBehalfOf(supportingToken);
}
if (context != null) {
stsClient.setContext(context);
}
stsClient.setProperties(properties);
stsClient.setTokenType(tokenType);
stsClient.setKeyType(keyType);
stsClient.setAddressingNamespace("http://www.w3.org/2005/08/addressing");
return stsClient.requestSecurityToken(endpointAddress);
}
use of org.apache.cxf.ws.security.trust.STSClient in project cxf by apache.
the class AsymmetricBindingTest method testUsernameTokenSAML1Encrypted.
@org.junit.Test
public void testUsernameTokenSAML1Encrypted() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = AsymmetricBindingTest.class.getResource("cxf-client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = AsymmetricBindingTest.class.getResource("DoubleIt.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItAsymmetricSAML1EncryptedPort");
DoubleItPortType asymmetricSaml1EncryptedPort = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(asymmetricSaml1EncryptedPort, test.getPort());
TokenTestUtils.updateSTSPort((BindingProvider) asymmetricSaml1EncryptedPort, test.getStsPort());
if (test.isStreaming()) {
SecurityTestUtil.enableStreaming(asymmetricSaml1EncryptedPort);
}
// Set the X509Certificate manually on the STSClient (just to test that we can)
BindingProvider bindingProvider = (BindingProvider) asymmetricSaml1EncryptedPort;
STSClient stsClient = (STSClient) bindingProvider.getRequestContext().get(SecurityConstants.STS_CLIENT);
if (stsClient == null) {
stsClient = (STSClient) bindingProvider.getRequestContext().get("ws-" + SecurityConstants.STS_CLIENT);
}
Crypto crypto = CryptoFactory.getInstance("clientKeystore.properties");
CryptoType cryptoType = new CryptoType(CryptoType.TYPE.ALIAS);
cryptoType.setAlias("myclientkey");
X509Certificate[] certs = crypto.getX509Certificates(cryptoType);
stsClient.setUseKeyCertificate(certs[0]);
doubleIt(asymmetricSaml1EncryptedPort, 40);
((java.io.Closeable) asymmetricSaml1EncryptedPort).close();
bus.shutdown(true);
}
use of org.apache.cxf.ws.security.trust.STSClient in project cxf by apache.
the class TokenTestUtils method verifyToken.
public static void verifyToken(DoubleItPortType port) throws Exception {
Client client = ClientProxy.getClient(port);
Endpoint ep = client.getEndpoint();
String id = (String) ep.get(SecurityConstants.TOKEN_ID);
TokenStore store = (TokenStore) ep.getEndpointInfo().getProperty(TokenStore.class.getName());
org.apache.cxf.ws.security.tokenstore.SecurityToken tok = store.getToken(id);
assertNotNull(tok);
STSClient sts = (STSClient) ep.get(SecurityConstants.STS_CLIENT);
if (sts == null) {
sts = (STSClient) ep.get("ws-" + SecurityConstants.STS_CLIENT);
}
List<SecurityToken> validTokens = sts.validateSecurityToken(tok);
assertTrue(validTokens != null && !validTokens.isEmpty());
// mess with the token a bit to force it to fail to validate
Element e = tok.getToken();
Element e2 = DOMUtils.getFirstChildWithName(e, e.getNamespaceURI(), "Conditions");
String nb = e2.getAttributeNS(null, "NotBefore");
String noa = e2.getAttributeNS(null, "NotOnOrAfter");
nb = "2010" + nb.substring(4);
noa = "2010" + noa.substring(4);
e2.setAttributeNS(null, "NotBefore", nb);
e2.setAttributeNS(null, "NotOnOrAfter", noa);
try {
sts.validateSecurityToken(tok);
fail("Failure expected on an invalid token");
} catch (org.apache.cxf.ws.security.trust.TrustException ex) {
// expected
}
}
use of org.apache.cxf.ws.security.trust.STSClient in project cxf by apache.
the class SAMLDelegationTest method requestSecurityToken.
private SecurityToken requestSecurityToken(String tokenType, String keyType, Element supportingToken, Bus bus, String endpointAddress, boolean onBehalfOf, String wsdlPort) throws Exception {
STSClient stsClient = new STSClient(bus);
String port = STSPORT;
stsClient.setWsdlLocation("https://localhost:" + port + "/SecurityTokenService/Transport?wsdl");
stsClient.setServiceName("{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}SecurityTokenService");
if (wsdlPort != null) {
stsClient.setEndpointName("{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}" + wsdlPort);
} else {
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(SecurityConstants.IS_BSP_COMPLIANT, "false");
if (PUBLIC_KEY_KEYTYPE.equals(keyType)) {
properties.put(SecurityConstants.STS_TOKEN_USERNAME, "myclientkey");
properties.put(SecurityConstants.STS_TOKEN_PROPERTIES, "clientKeystore.properties");
stsClient.setUseCertificateForConfirmationKeyInfo(true);
}
if (supportingToken != null) {
if (onBehalfOf) {
stsClient.setOnBehalfOf(supportingToken);
} else {
stsClient.setActAs(supportingToken);
}
}
stsClient.setProperties(properties);
stsClient.setTokenType(tokenType);
stsClient.setKeyType(keyType);
return stsClient.requestSecurityToken(endpointAddress);
}
use of org.apache.cxf.ws.security.trust.STSClient in project cxf by apache.
the class IntermediaryCachingPortTypeImpl method doubleIt.
public int doubleIt(int numberToDouble) {
if (transportPort == null) {
// Re-use the same proxy
URL wsdl = IntermediaryCachingPortTypeImpl.class.getResource("DoubleIt.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItTransportSAML2Port");
transportPort = service.getPort(portQName, DoubleItPortType.class);
try {
updateAddressPort(transportPort, IntermediaryTransformationCachingTest.PORT2);
} catch (Exception ex) {
ex.printStackTrace();
}
if ("standalone".equals(System.getProperty("sts.deployment"))) {
Map<String, Object> context = ((BindingProvider) transportPort).getRequestContext();
STSClient stsClient = (STSClient) context.get(SecurityConstants.STS_CLIENT);
if (stsClient == null) {
stsClient = (STSClient) context.get("ws-" + SecurityConstants.STS_CLIENT);
}
if (stsClient != null) {
String location = stsClient.getWsdlLocation();
if (location.contains("8080")) {
stsClient.setWsdlLocation(location.replace("8080", IntermediaryTransformationCachingTest.STSPORT2));
} else if (location.contains("8443")) {
stsClient.setWsdlLocation(location.replace("8443", IntermediaryTransformationCachingTest.STSPORT));
}
}
}
}
Principal pr = wsc.getUserPrincipal();
Assert.assertNotNull("Principal must not be null", pr);
Assert.assertNotNull("Principal.getName() must not return null", pr.getName());
// Disable the STSClient after the second invocation
if (i > 1) {
BindingProvider p = (BindingProvider) transportPort;
STSClient stsClient = new STSClient(null);
stsClient.setOnBehalfOf(new ReceivedTokenCallbackHandler());
p.getRequestContext().put(SecurityConstants.STS_CLIENT, stsClient);
}
i++;
return transportPort.doubleIt(numberToDouble);
}
Aggregations