/**
* Test that adds a UserNameToken via WSHandler
*/
@org.junit.Test
public void testUsernameTokenWSHandler() throws Exception {
CustomHandler handler = new CustomHandler();
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
RequestData reqData = new RequestData();
java.util.Map<String, Object> config = new java.util.TreeMap<String, Object>();
config.put("password", "verySecret");
config.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
reqData.setUsername("wernerd");
reqData.setMsgContext(config);
java.util.List<Integer> actions = new java.util.ArrayList<Integer>();
actions.add(new Integer(WSConstants.UT));
handler.send(WSConstants.UT, doc, reqData, actions, true);
if (LOG.isDebugEnabled()) {
LOG.debug("Username Token via WSHandler");
String outputString =
org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
LOG.debug(outputString);
}
//
// It should pass even on a different password type, as we haven't set the
// processing to be strict
//
config.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
reqData.setMsgContext(config);
handler.receive(WSConstants.UT, reqData);
WSSecurityEngine secEngine = new WSSecurityEngine();
secEngine.setWssConfig(reqData.getWssConfig());
secEngine.processSecurityHeader(doc, null, callbackHandler, null);
//
// It should fail on strict password type processing
//
config.put(WSHandlerConstants.PASSWORD_TYPE_STRICT, "true");
reqData.setMsgContext(config);
handler.receive(WSConstants.UT, reqData);
try {
secEngine.processSecurityHeader(doc, null, callbackHandler, null);
fail("Expected failure on the wrong password type");
} catch (WSSecurityException ex) {
// expected