Search in sources :

Example 1 with TokenTypeId

use of org.forgerock.openam.sts.TokenTypeId in project OpenAM by OpenRock.

the class TokenRequestMarshallerImplTest method testBuildCustomProviderParametersWithUnregisteredCustomToken.

@Test(expectedExceptions = TokenMarshalException.class)
public void testBuildCustomProviderParametersWithUnregisteredCustomToken() throws IOException, CertificateException {
    JsonValue jsonUnt = json(object(field("token_type", "USERNAME"), field("username", "bobo"), field("password", "cornholio")));
    JsonValue jsonCustomOutput = json(object(field("token_type", "NOT_REGISTERED_AS_CUSTOM_TYPE"), field("whatever", "whatever")));
    TokenTypeId customTokenType = new TokenTypeId() {

        @Override
        public String getId() {
            return "NOT_REGISTERED_AS_CUSTOM_TYPE";
        }
    };
    RestTokenProviderParameters<?> params = tokenMarshaller.buildTokenProviderParameters(TokenType.USERNAME, jsonUnt, customTokenType, new JsonValue(new HashMap<String, Object>()));
}
Also used : HashMap(java.util.HashMap) JsonValue(org.forgerock.json.JsonValue) TokenTypeId(org.forgerock.openam.sts.TokenTypeId) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 2 with TokenTypeId

use of org.forgerock.openam.sts.TokenTypeId in project OpenAM by OpenRock.

the class IssuedTokenCancelOperationImpl method cancelToken.

@Override
@SuppressWarnings("unchecked")
public JsonValue cancelToken(RestSTSTokenCancellationInvocationState invocationState) throws TokenCancellationException, TokenMarshalException {
    TokenTypeId tokenTypeId = tokenRequestMarshaller.getTokenType(invocationState.getCancelledTokenState());
    RestIssuedTokenCancellerParameters<?> cancellerParameters = tokenRequestMarshaller.buildIssuedTokenCancellerParameters(invocationState.getCancelledTokenState());
    for (RestIssuedTokenCanceller tokenCanceller : tokenCancellers) {
        if (tokenCanceller.canCancelToken(tokenTypeId)) {
            tokenCanceller.cancelToken(cancellerParameters);
            return json(object(field(RESULT, tokenTypeId.getId() + " token cancelled successfully.")));
        }
    }
    throw new TokenCancellationException(ResourceException.BAD_REQUEST, "No IssuedTokenCancellers available for " + "token type: " + tokenTypeId.getId() + ". Does this sts issue tokens of the specified type?");
}
Also used : TokenTypeId(org.forgerock.openam.sts.TokenTypeId) TokenCancellationException(org.forgerock.openam.sts.TokenCancellationException) RestIssuedTokenCanceller(org.forgerock.openam.sts.rest.token.canceller.RestIssuedTokenCanceller)

Example 3 with TokenTypeId

use of org.forgerock.openam.sts.TokenTypeId in project OpenAM by OpenRock.

the class TokenTransformFactoryImpl method buildTokenTransform.

@SuppressWarnings("unchecked")
public TokenTransform<?, ? extends TokenTypeId> buildTokenTransform(TokenTransformConfig tokenTransformConfig) throws STSInitializationException {
    TokenTypeId inputTokenType = tokenTransformConfig.getInputTokenType();
    TokenTypeId outputTokenType = tokenTransformConfig.getOutputTokenType();
    RestTokenTransformValidator<?> tokenValidator;
    if (TokenType.USERNAME.getId().equals(inputTokenType.getId())) {
        tokenValidator = buildUsernameTokenValidator(tokenTransformConfig.invalidateInterimOpenAMSession());
    } else if (TokenType.OPENAM.getId().equals(inputTokenType.getId())) {
        tokenValidator = buildOpenAMTokenValidator(tokenTransformConfig.invalidateInterimOpenAMSession());
    } else if (TokenType.OPENIDCONNECT.getId().equals(inputTokenType.getId())) {
        tokenValidator = buildOpenIdConnectValidator(tokenTransformConfig.invalidateInterimOpenAMSession());
    } else if (TokenType.X509.getId().equals(inputTokenType.getId())) {
        tokenValidator = buildX509TokenValidator(tokenTransformConfig.invalidateInterimOpenAMSession());
    } else {
        tokenValidator = buildCustomTokenValidator(inputTokenType, ValidationInvocationContext.REST_TOKEN_TRANSFORMATION, tokenTransformConfig.invalidateInterimOpenAMSession());
    }
    RestTokenProvider<?> tokenProvider;
    if (TokenType.SAML2.getId().equals(outputTokenType.getId())) {
        tokenProvider = buildOpenSAMLTokenProvider();
    } else if (TokenType.OPENIDCONNECT.getId().equals(outputTokenType.getId())) {
        tokenProvider = buildOpenIdConnectTokenProvider();
    } else {
        tokenProvider = buildCustomTokenProvider(outputTokenType);
    }
    return new TokenTransformImpl(tokenValidator, tokenProvider, inputTokenType, outputTokenType);
}
Also used : TokenTypeId(org.forgerock.openam.sts.TokenTypeId)

Example 4 with TokenTypeId

use of org.forgerock.openam.sts.TokenTypeId in project OpenAM by OpenRock.

the class TokenTransformConfigTest method testCustomTokenTypeMarshaling.

@Test
public void testCustomTokenTypeMarshaling() {
    TokenTransformConfig ttc1 = TokenTransformConfig.fromSMSString(CUSTOM_INPUT_STRING_TRANSFORM);
    assertEquals(ttc1, TokenTransformConfig.fromJson(ttc1.toJson()));
    assertEquals(ttc1, TokenTransformConfig.fromSMSString(ttc1.toSMSString()));
    ttc1 = TokenTransformConfig.fromSMSString(CUSTOM_OUTPUT_STRING_TRANSFORM);
    assertEquals(ttc1, TokenTransformConfig.fromJson(ttc1.toJson()));
    assertEquals(ttc1, TokenTransformConfig.fromSMSString(ttc1.toSMSString()));
    TokenTypeId tokenTypeId = new TokenTypeId() {

        @Override
        public String getId() {
            return CUSTOM_TOKEN_NAME;
        }
    };
    ttc1 = new TokenTransformConfig(tokenTypeId, tokenTypeId, true);
    assertEquals(CUSTOM_TOKEN_NAME, ttc1.getInputTokenType().getId());
    assertEquals(CUSTOM_TOKEN_NAME, ttc1.getOutputTokenType().getId());
}
Also used : TokenTypeId(org.forgerock.openam.sts.TokenTypeId) Test(org.testng.annotations.Test)

Example 5 with TokenTypeId

use of org.forgerock.openam.sts.TokenTypeId in project OpenAM by OpenRock.

the class TokenRequestMarshallerImpl method getTokenType.

@Override
public TokenTypeId getTokenType(JsonValue receivedToken) throws TokenMarshalException {
    JsonValue jsonTokenType = receivedToken.get(AMSTSConstants.TOKEN_TYPE_KEY);
    if (jsonTokenType.isNull() || !jsonTokenType.isString()) {
        String message = "REST STS invocation does not contain " + AMSTSConstants.TOKEN_TYPE_KEY + " String entry. The json token: " + receivedToken;
        throw new TokenMarshalException(ResourceException.BAD_REQUEST, message);
    }
    final String tokenType = jsonTokenType.asString();
    return new TokenTypeId() {

        @Override
        public String getId() {
            return tokenType;
        }
    };
}
Also used : JsonValue(org.forgerock.json.JsonValue) TokenMarshalException(org.forgerock.openam.sts.TokenMarshalException) TokenTypeId(org.forgerock.openam.sts.TokenTypeId)

Aggregations

TokenTypeId (org.forgerock.openam.sts.TokenTypeId)9 JsonValue (org.forgerock.json.JsonValue)3 Test (org.testng.annotations.Test)3 TokenValidationException (org.forgerock.openam.sts.TokenValidationException)2 BeforeTest (org.testng.annotations.BeforeTest)2 HashMap (java.util.HashMap)1 TokenCancellationException (org.forgerock.openam.sts.TokenCancellationException)1 TokenMarshalException (org.forgerock.openam.sts.TokenMarshalException)1 RestIssuedTokenCanceller (org.forgerock.openam.sts.rest.token.canceller.RestIssuedTokenCanceller)1 RestIssuedTokenValidator (org.forgerock.openam.sts.rest.token.validator.RestIssuedTokenValidator)1