use of org.forgerock.openam.sts.token.model.RestUsernameToken in project OpenAM by OpenRock.
the class TokenRequestMarshallerImpl method buildUsernameTokenTransformValidatorParameters.
private RestTokenTransformValidatorParameters<RestUsernameToken> buildUsernameTokenTransformValidatorParameters(JsonValue receivedToken) throws TokenMarshalException {
if (!receivedToken.get(AMSTSConstants.USERNAME_TOKEN_USERNAME).isString()) {
final String message = "Exception: json representation of UNT does not contain a username field. The representation: " + receivedToken;
throw new TokenMarshalException(ResourceException.BAD_REQUEST, message);
}
if (!receivedToken.get(AMSTSConstants.USERNAME_TOKEN_PASSWORD).isString()) {
final String message = "Exception: json representation of UNT does not contain a password field. The representation: \n" + receivedToken;
throw new TokenMarshalException(ResourceException.BAD_REQUEST, message);
}
final String username = receivedToken.get(AMSTSConstants.USERNAME_TOKEN_USERNAME).asString();
final String password = receivedToken.get(AMSTSConstants.USERNAME_TOKEN_PASSWORD).asString();
try {
final RestUsernameToken restUsernameToken = new RestUsernameToken(username.getBytes(AMSTSConstants.UTF_8_CHARSET_ID), password.getBytes(AMSTSConstants.UTF_8_CHARSET_ID));
return new RestTokenTransformValidatorParameters<RestUsernameToken>() {
@Override
public RestUsernameToken getInputToken() {
return restUsernameToken;
}
};
} catch (UnsupportedEncodingException e) {
throw new TokenMarshalException(ResourceException.INTERNAL_ERROR, "Unable to marshal username token state to strings: " + e.getMessage(), e);
}
}
Aggregations