Search in sources :

Example 1 with OpenAMSessionToken

use of org.forgerock.openam.sts.token.model.OpenAMSessionToken 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)

Example 2 with OpenAMSessionToken

use of org.forgerock.openam.sts.token.model.OpenAMSessionToken in project OpenAM by OpenRock.

the class TokenRequestMarshallerImplTest method marshallOpenAMToken.

@Test
public void marshallOpenAMToken() throws TokenMarshalException {
    JsonValue jsonOpenAM = json(object(field("token_type", "OPENAM"), field("session_id", "super_random")));
    RestTokenTransformValidatorParameters<?> params = tokenMarshaller.buildTokenTransformValidatorParameters(jsonOpenAM, null);
    assertTrue("super_random".equals(((OpenAMSessionToken) params.getInputToken()).getSessionId()));
}
Also used : OpenAMSessionToken(org.forgerock.openam.sts.token.model.OpenAMSessionToken) JsonValue(org.forgerock.json.JsonValue) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

OpenAMSessionToken (org.forgerock.openam.sts.token.model.OpenAMSessionToken)2 JsonValue (org.forgerock.json.JsonValue)1 TokenMarshalException (org.forgerock.openam.sts.TokenMarshalException)1 RestTokenTransformValidatorParameters (org.forgerock.openam.sts.rest.token.validator.RestTokenTransformValidatorParameters)1 BeforeTest (org.testng.annotations.BeforeTest)1 Test (org.testng.annotations.Test)1