WSSConfig wssConfig = WSSConfig.getNewInstance();
KerberosTokenValidator validator = new KerberosTokenValidator();
validator.setContextName("bob");
validator.setServiceName("bob@service.ws.apache.org");
wssConfig.setValidator(WSSecurityEngine.BINARY_TOKEN, validator);
WSSecurityEngine secEngine = new WSSecurityEngine();
secEngine.setWssConfig(wssConfig);
CallbackHandler callbackHandler = new CallbackHandler() {
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
if (callbacks[0] instanceof PasswordCallback) {
PasswordCallback passwordCallback = (PasswordCallback) callbacks[0];
if (passwordCallback.getPrompt().contains("bob")) {
passwordCallback.setPassword("bob".toCharArray());
}
}
}
};
List<WSSecurityEngineResult> results =
secEngine.processSecurityHeader(document, null, callbackHandler, null);
WSSecurityEngineResult actionResult =
WSSecurityUtil.fetchActionResult(results, WSConstants.BST);
BinarySecurity token =
(BinarySecurity) actionResult.get(WSSecurityEngineResult.TAG_BINARY_SECURITY_TOKEN);
Assert.assertTrue(token != null);