boolean bspCompliant = isWsiBSPCompliant(message);
boolean utWithCallbacks =
MessageUtils.getContextualBoolean(message, SecurityConstants.VALIDATE_TOKEN, true);
boolean allowNoPassword = isAllowNoPassword(message.get(AssertionInfoMap.class));
if (utWithCallbacks) {
UsernameTokenProcessor p = new UsernameTokenProcessor();
WSDocInfo wsDocInfo = new WSDocInfo(tokenElement.getOwnerDocument());
RequestData data = new RequestData() {
public CallbackHandler getCallbackHandler() {
return getCallback(message);
}
public Validator getValidator(QName qName) throws WSSecurityException {
Object validator =
message.getContextualProperty(SecurityConstants.USERNAME_TOKEN_VALIDATOR);
if (validator == null) {
return super.getValidator(qName);
}
return (Validator)validator;
}
};
// Configure replay caching
ReplayCache nonceCache =
WSS4JUtils.getReplayCache(
message, SecurityConstants.ENABLE_NONCE_CACHE, SecurityConstants.NONCE_CACHE_INSTANCE
);
data.setNonceReplayCache(nonceCache);
WSSConfig config = WSSConfig.getNewInstance();
config.setAllowUsernameTokenNoPassword(allowNoPassword);
data.setWssConfig(config);
if (!bspCompliant) {
data.setDisableBSPEnforcement(true);
}
List<WSSecurityEngineResult> results =
p.handleToken(tokenElement, data, wsDocInfo);
return (UsernameTokenPrincipal)results.get(0).get(WSSecurityEngineResult.TAG_PRINCIPAL);
} else {
UsernameTokenPrincipal principal = parseTokenAndCreatePrincipal(tokenElement, bspCompliant);
WSS4JTokenConverter.convertToken(message, principal);
return principal;