* Test that uses a 32 byte key length for the secret key, instead of the default 16 bytes.
* This test configures the key length via WSHandler.
*/
@org.junit.Test
public void testWSS226Handler() throws Exception {
CustomHandler handler = new CustomHandler();
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
RequestData reqData = new RequestData();
reqData.setWssConfig(WSSConfig.getNewInstance());
java.util.Map<String, Object> config = new java.util.TreeMap<String, Object>();
config.put("password", "verySecret");
config.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
config.put(WSHandlerConstants.WSE_SECRET_KEY_LENGTH, "32");
config.put(WSHandlerConstants.USE_DERIVED_KEY, "false");
reqData.setUsername("wernerd");
reqData.setMsgContext(config);
java.util.List<Integer> actions = new java.util.ArrayList<Integer>();
actions.add(new Integer(WSConstants.UT_SIGN));
handler.send(WSConstants.UT_SIGN, doc, reqData, actions, true);
if (LOG.isDebugEnabled()) {
LOG.debug("Username Token Signature via WSHandler");
String outputString =
org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
LOG.debug(outputString);
}
//
// It should fail on the default key length of 16...
//
try {
secEngine.processSecurityHeader(doc, null, callbackHandler, null);
fail ("An error was expected on verifying the signature");
} catch (Exception ex) {
// expected
}
handler.receive(WSConstants.UT_SIGN, reqData);
WSSecurityEngine wss226SecurityEngine = new WSSecurityEngine();
wss226SecurityEngine.setWssConfig(reqData.getWssConfig());
wss226SecurityEngine.processSecurityHeader(doc, null, callbackHandler, null);
}