final WSSConfig cfg = WSSConfig.getNewInstance();
final RequestData reqData = new RequestData();
reqData.setWssConfig(cfg);
java.util.Map<String, Object> messageContext = new java.util.TreeMap<String, Object>();
messageContext.put(
WSHandlerConstants.PW_CALLBACK_REF, new KeystoreCallbackHandler()
);
reqData.setMsgContext(messageContext);
EncryptionActionToken actionToken = new EncryptionActionToken();
actionToken.setUser("wss40");
actionToken.setCryptoProperties("wss40.properties");
EncryptionActionToken actionToken2 = new EncryptionActionToken();
actionToken2.setKeyIdentifierId(WSConstants.ENCRYPTED_KEY_SHA1_IDENTIFIER);
actionToken2.setKey(keyData);
actionToken2.setSymmetricAlgorithm(WSConstants.AES_128);
actionToken2.setEncSymmetricEncryptionKey(false);
WSEncryptionPart encP =
new WSEncryptionPart("Timestamp", WSConstants.WSU_NS, "");
actionToken2.setParts(Collections.singletonList(encP));
final Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
CustomHandler handler = new CustomHandler();
List<HandlerAction> actions = new ArrayList<HandlerAction>();
actions.add(new HandlerAction(WSConstants.ENCR, actionToken));
actions.add(new HandlerAction(WSConstants.TS, null));
actions.add(new HandlerAction(WSConstants.ENCR, actionToken2));
handler.send(
doc,
reqData,
actions,
true
);
if (LOG.isDebugEnabled()) {
String outputString =
XMLUtils.PrettyDocumentToString(doc);
LOG.debug(outputString);
}
SecretKeyCallbackHandler secretKeyCallbackHandler = new SecretKeyCallbackHandler();
byte[] encodedBytes = WSSecurityUtil.generateDigest(keyData);
String identifier = Base64.encode(encodedBytes);
secretKeyCallbackHandler.addSecretKey(identifier, keyData);
CombinedCallbackHandler combinedCallbackHandler =
new CombinedCallbackHandler(secretKeyCallbackHandler, new KeystoreCallbackHandler());
verify(doc, combinedCallbackHandler);
}