Search in sources :

Example 1 with RestTokenTransformValidatorParameters

use of org.forgerock.openam.sts.rest.token.validator.RestTokenTransformValidatorParameters in project OpenAM by OpenRock.

the class TokenRequestMarshallerImplTest method testX509CertificateTokenMarshalling.

@Test
public void testX509CertificateTokenMarshalling() throws Exception {
    X509Certificate certificate = getCertificate();
    ClientContext clientInfoContext = ClientContext.buildExternalClientContext(null).certificates(certificate).build();
    @SuppressWarnings("unchecked") RestTokenTransformValidatorParameters<X509Certificate[]> params = (RestTokenTransformValidatorParameters<X509Certificate[]>) tokenMarshaller.buildTokenTransformValidatorParameters(new X509TokenState().toJson(), clientInfoContext);
    assertEquals(certificate.getEncoded(), (params.getInputToken()[0].getEncoded()));
}
Also used : X509TokenState(org.forgerock.openam.sts.user.invocation.X509TokenState) RestTokenTransformValidatorParameters(org.forgerock.openam.sts.rest.token.validator.RestTokenTransformValidatorParameters) ClientContext(org.forgerock.services.context.ClientContext) X509Certificate(java.security.cert.X509Certificate) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 2 with RestTokenTransformValidatorParameters

use of org.forgerock.openam.sts.rest.token.validator.RestTokenTransformValidatorParameters 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)

Example 3 with RestTokenTransformValidatorParameters

use of org.forgerock.openam.sts.rest.token.validator.RestTokenTransformValidatorParameters in project OpenAM by OpenRock.

the class TokenRequestMarshallerImpl method buildOpenIdConnectIdTokenTransformValidatorParameters.

private RestTokenTransformValidatorParameters<OpenIdConnectIdToken> buildOpenIdConnectIdTokenTransformValidatorParameters(JsonValue receivedToken) throws TokenMarshalException {
    if (!receivedToken.get(AMSTSConstants.OPEN_ID_CONNECT_ID_TOKEN_KEY).isString()) {
        String message = "Exception: json representation of Open ID Connect ID Token does not contain a " + AMSTSConstants.OPEN_ID_CONNECT_ID_TOKEN_KEY + " field. The representation: " + receivedToken;
        throw new TokenMarshalException(ResourceException.BAD_REQUEST, message);
    } else {
        final String tokenValue = receivedToken.get(AMSTSConstants.OPEN_ID_CONNECT_ID_TOKEN_KEY).asString();
        final OpenIdConnectIdToken openIdConnectIdToken = new OpenIdConnectIdToken(tokenValue);
        return new RestTokenTransformValidatorParameters<OpenIdConnectIdToken>() {

            @Override
            public OpenIdConnectIdToken getInputToken() {
                return openIdConnectIdToken;
            }
        };
    }
}
Also used : RestTokenTransformValidatorParameters(org.forgerock.openam.sts.rest.token.validator.RestTokenTransformValidatorParameters) TokenMarshalException(org.forgerock.openam.sts.TokenMarshalException) OpenIdConnectIdToken(org.forgerock.openam.sts.token.model.OpenIdConnectIdToken)

Example 4 with RestTokenTransformValidatorParameters

use of org.forgerock.openam.sts.rest.token.validator.RestTokenTransformValidatorParameters in project OpenAM by OpenRock.

the class TokenRequestMarshallerImpl method buildAMSessionTokenTransformValidatorParameters.

private RestTokenTransformValidatorParameters<OpenAMSessionToken> buildAMSessionTokenTransformValidatorParameters(JsonValue receivedToken) throws TokenMarshalException {
    if (!receivedToken.get(AMSTSConstants.AM_SESSION_TOKEN_SESSION_ID).isString()) {
        String message = "Exception: json representation of AM Session Token does not contain a session_id field. " + "The representation: " + receivedToken;
        throw new TokenMarshalException(ResourceException.BAD_REQUEST, message);
    } else {
        final String sessionId = receivedToken.get(AMSTSConstants.AM_SESSION_TOKEN_SESSION_ID).asString();
        final OpenAMSessionToken openAMSessionToken = new OpenAMSessionToken(sessionId);
        return new RestTokenTransformValidatorParameters<OpenAMSessionToken>() {

            @Override
            public OpenAMSessionToken getInputToken() {
                return openAMSessionToken;
            }
        };
    }
}
Also used : OpenAMSessionToken(org.forgerock.openam.sts.token.model.OpenAMSessionToken) RestTokenTransformValidatorParameters(org.forgerock.openam.sts.rest.token.validator.RestTokenTransformValidatorParameters) TokenMarshalException(org.forgerock.openam.sts.TokenMarshalException)

Aggregations

RestTokenTransformValidatorParameters (org.forgerock.openam.sts.rest.token.validator.RestTokenTransformValidatorParameters)4 TokenMarshalException (org.forgerock.openam.sts.TokenMarshalException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 X509Certificate (java.security.cert.X509Certificate)1 OpenAMSessionToken (org.forgerock.openam.sts.token.model.OpenAMSessionToken)1 OpenIdConnectIdToken (org.forgerock.openam.sts.token.model.OpenIdConnectIdToken)1 RestUsernameToken (org.forgerock.openam.sts.token.model.RestUsernameToken)1 X509TokenState (org.forgerock.openam.sts.user.invocation.X509TokenState)1 ClientContext (org.forgerock.services.context.ClientContext)1 BeforeTest (org.testng.annotations.BeforeTest)1 Test (org.testng.annotations.Test)1