use of org.apache.wss4j.common.spnego.SpnegoClientAction 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);
}
}
}
Aggregations