}
}
Validator validator = data.getValidator(WSSecurityEngine.USERNAME_TOKEN);
Credential credential = handleUsernameToken(elem, validator, data);
UsernameToken token = credential.getUsernametoken();
int action = WSConstants.UT;
byte[] secretKey = null;
if (token.getPassword() == null) {
action = WSConstants.UT_NOPASSWORD;
if (token.isDerivedKey()) {
token.setRawPassword(data);
secretKey = token.getDerivedKey(data.getBSPEnforcer());
}
}
WSSecurityEngineResult result = new WSSecurityEngineResult(action, token);
result.put(WSSecurityEngineResult.TAG_ID, token.getID());
result.put(WSSecurityEngineResult.TAG_SECRET, secretKey);
if (validator != null) {
result.put(WSSecurityEngineResult.TAG_VALIDATED_TOKEN, Boolean.TRUE);
if (credential.getTransformedToken() != null) {
result.put(
WSSecurityEngineResult.TAG_TRANSFORMED_TOKEN, credential.getTransformedToken()
);
if (credential.getPrincipal() != null) {
result.put(WSSecurityEngineResult.TAG_PRINCIPAL, credential.getPrincipal());
} else {
SAMLTokenPrincipalImpl samlPrincipal =
new SAMLTokenPrincipalImpl(credential.getTransformedToken());
result.put(WSSecurityEngineResult.TAG_PRINCIPAL, samlPrincipal);
}
} else if (credential.getPrincipal() != null) {
result.put(WSSecurityEngineResult.TAG_PRINCIPAL, credential.getPrincipal());
} else {
WSUsernameTokenPrincipalImpl principal =
new WSUsernameTokenPrincipalImpl(token.getName(), token.isHashed());
principal.setNonce(Base64.decodeBase64(token.getNonce()));
principal.setPassword(token.getPassword());
principal.setCreatedTime(token.getCreated());
principal.setPasswordType(token.getPasswordType());
result.put(WSSecurityEngineResult.TAG_PRINCIPAL, principal);
}
result.put(WSSecurityEngineResult.TAG_SUBJECT, credential.getSubject());
}