Search in sources :

Example 1 with RestUsernameToken

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);
    }
}
Also used : RestTokenTransformValidatorParameters(org.forgerock.openam.sts.rest.token.validator.RestTokenTransformValidatorParameters) TokenMarshalException(org.forgerock.openam.sts.TokenMarshalException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RestUsernameToken(org.forgerock.openam.sts.token.model.RestUsernameToken)

Aggregations

UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 TokenMarshalException (org.forgerock.openam.sts.TokenMarshalException)1 RestTokenTransformValidatorParameters (org.forgerock.openam.sts.rest.token.validator.RestTokenTransformValidatorParameters)1 RestUsernameToken (org.forgerock.openam.sts.token.model.RestUsernameToken)1