use of org.apache.cxf.ws.security.trust.STSClient in project cxf by apache.
the class SecureConversationOutInterceptor method issueToken.
private SecurityToken issueToken(SoapMessage message, AssertionInfoMap aim, SecureConversationToken itok) {
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");
}
synchronized (client) {
try {
String s = SecureConversationTokenInterceptorProvider.setupClient(client, message, aim, itok, false);
if (maps != null) {
client.setAddressingNamespace(maps.getNamespaceURI());
}
SecurityToken tok = client.requestSecurityToken(s);
String tokenType = tok.getTokenType();
tok.setTokenType(tokenType);
if (tokenType == null || "".equals(tokenType)) {
tok.setTokenType(WSS4JConstants.WSC_SCT);
}
return tok;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new Fault(e);
} finally {
client.setTrust((Trust10) null);
client.setTrust((Trust13) null);
client.setTemplate(null);
client.setLocation(null);
client.setAddressingNamespace(null);
}
}
}
use of org.apache.cxf.ws.security.trust.STSClient in project cxf by apache.
the class SpnegoContextTokenOutInterceptor method issueToken.
private SecurityToken issueToken(SoapMessage message, AssertionInfoMap aim) {
//
// Get a SPNEGO token
//
String jaasContext = (String) message.getContextualProperty(SecurityConstants.KERBEROS_JAAS_CONTEXT_NAME);
String kerberosSpn = (String) message.getContextualProperty(SecurityConstants.KERBEROS_SPN);
SpnegoTokenContext spnegoToken = new SpnegoTokenContext();
Object spnegoClientAction = message.getContextualProperty(SecurityConstants.SPNEGO_CLIENT_ACTION);
if (spnegoClientAction instanceof SpnegoClientAction) {
spnegoToken.setSpnegoClientAction((SpnegoClientAction) spnegoClientAction);
}
try {
CallbackHandler callbackHandler = SecurityUtils.getCallbackHandler(SecurityUtils.getSecurityPropertyValue(SecurityConstants.CALLBACK_HANDLER, message));
spnegoToken.retrieveServiceTicket(jaasContext, callbackHandler, kerberosSpn);
} catch (Exception e) {
throw new Fault(e);
}
//
// Now initiate WS-Trust exchange
//
STSClient client = STSUtils.getClient(message, "spnego");
AddressingProperties maps = (AddressingProperties) message.get("javax.xml.ws.addressing.context.outbound");
if (maps == null) {
maps = (AddressingProperties) message.get("javax.xml.ws.addressing.context");
}
synchronized (client) {
try {
String s = SpnegoTokenInterceptorProvider.setupClient(client, message, aim);
if (maps != null) {
client.setAddressingNamespace(maps.getNamespaceURI());
}
SecurityToken tok = client.requestSecurityToken(s, Base64.getMimeEncoder().encodeToString(spnegoToken.getToken()));
byte[] wrappedTok = spnegoToken.unwrapKey(tok.getSecret());
tok.setSecret(wrappedTok);
spnegoToken.clear();
return tok;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new Fault(e);
} finally {
client.setTrust((Trust10) null);
client.setTrust((Trust13) null);
client.setTemplate(null);
client.setLocation(null);
client.setAddressingNamespace(null);
}
}
}
use of org.apache.cxf.ws.security.trust.STSClient in project cxf by apache.
the class STSClientTest method testConfigureViaEPR.
@Test
public void testConfigureViaEPR() throws Exception {
final Set<Class<?>> addressingClasses = new HashSet<Class<?>>();
addressingClasses.add(org.apache.cxf.ws.addressing.wsdl.ObjectFactory.class);
addressingClasses.add(org.apache.cxf.ws.addressing.ObjectFactory.class);
JAXBContext ctx = JAXBContextCache.getCachedContextAndSchemas(addressingClasses, null, null, null, true).getContext();
Unmarshaller um = ctx.createUnmarshaller();
InputStream inStream = getClass().getResourceAsStream("epr.xml");
JAXBElement<?> el = (JAXBElement<?>) um.unmarshal(inStream);
EndpointReferenceType ref = (EndpointReferenceType) el.getValue();
Bus bus = BusFactory.getThreadDefaultBus();
STSClient client = new STSClient(bus);
client.configureViaEPR(ref, false);
assertEquals("http://localhost:8080/jaxws-samples-wsse-policy-trust-sts/SecurityTokenService?wsdl", client.getWsdlLocation());
assertEquals(new QName("http://docs.oasis-open.org/ws-sx/ws-trust/200512/", "SecurityTokenService"), client.getServiceQName());
assertEquals(new QName("http://docs.oasis-open.org/ws-sx/ws-trust/200512/", "UT_Port"), client.getEndpointQName());
}
use of org.apache.cxf.ws.security.trust.STSClient in project cxf by apache.
the class STSUnitTest method requestSecurityToken.
private SecurityToken requestSecurityToken(String tokenType, String keyType, Bus bus, String endpointAddress) throws Exception {
STSClient stsClient = new STSClient(bus);
stsClient.setWsdlLocation(endpointAddress + "?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/}X509_Port");
stsClient.setEnableAppliesTo(false);
Map<String, Object> properties = new HashMap<>();
properties.put(SecurityConstants.USERNAME, "alice");
properties.put(SecurityConstants.CALLBACK_HANDLER, new CommonCallbackHandler());
properties.put(SecurityConstants.SIGNATURE_USERNAME, "myclientkey");
properties.put(SecurityConstants.SIGNATURE_PROPERTIES, "clientKeystore.properties");
properties.put(SecurityConstants.ENCRYPT_USERNAME, "mystskey");
properties.put(SecurityConstants.ENCRYPT_PROPERTIES, "clientKeystore.properties");
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 CachingTest method testSTSClientCaching.
// @Ignore'd because failing too often on slow Jenkins machines
@org.junit.Test
@org.junit.Ignore
public void testSTSClientCaching() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = CachingTest.class.getResource("cxf-client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = CachingTest.class.getResource("DoubleIt.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItTransportSAML1Port");
DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
((BindingProvider) port).getRequestContext().put("thread.local.request.context", "true");
updateAddressPort(port, PORT);
// Make a successful invocation
doubleIt(port, 25);
// Change the STSClient so that it can no longer find the STS
BindingProvider p = (BindingProvider) port;
clearSTSClient(p, bus);
// This should succeed as the token is cached
doubleIt(port, 30);
// This should fail as the cached token is manually removed
Client client = ClientProxy.getClient(port);
Endpoint ep = client.getEndpoint();
ep.remove(SecurityConstants.TOKEN_ID);
ep.remove(SecurityConstants.TOKEN);
try {
doubleIt(port, 35);
fail("Expected failure on clearing the cache");
} catch (SOAPFaultException ex) {
// Expected
}
((java.io.Closeable) port).close();
bus.shutdown(true);
}
Aggregations