}
}
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();
}
}
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 {
SAMLTokenPrincipal samlPrincipal =
new SAMLTokenPrincipal(credential.getTransformedToken());
result.put(WSSecurityEngineResult.TAG_PRINCIPAL, samlPrincipal);
}
} else if (credential.getPrincipal() != null) {
result.put(WSSecurityEngineResult.TAG_PRINCIPAL, credential.getPrincipal());
} else {
WSUsernameTokenPrincipal principal =
new WSUsernameTokenPrincipal(token.getName(), token.isHashed());
principal.setNonce(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());
}