Search in sources :

Example 6 with TokenTypeId

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

the class TokenRequestMarshallerImplTest method testBuildCustomProviderParameters.

@Test
public void testBuildCustomProviderParameters() throws IOException, CertificateException {
    JsonValue jsonUnt = json(object(field("token_type", "USERNAME"), field("username", "bobo"), field("password", "cornholio")));
    JsonValue jsonCustomOutput = json(object(field("token_type", CUSTOM_TOKEN_NAME), field("whatever", "whatever")));
    TokenTypeId customTokenType = new TokenTypeId() {

        @Override
        public String getId() {
            return CUSTOM_TOKEN_NAME;
        }
    };
    RestTokenProviderParameters<?> params = tokenMarshaller.buildTokenProviderParameters(TokenType.USERNAME, jsonUnt, customTokenType, jsonCustomOutput);
    assertEquals(TokenType.USERNAME.getId(), params.getInputTokenType().getId());
    assertEquals(((JsonValue) params.getTokenCreationState()).get("token_type").asString(), CUSTOM_TOKEN_NAME);
}
Also used : JsonValue(org.forgerock.json.JsonValue) TokenTypeId(org.forgerock.openam.sts.TokenTypeId) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 7 with TokenTypeId

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

the class TokenTranslateOperationImpl method translateToken.

@Override
@SuppressWarnings("unchecked")
public JsonValue translateToken(RestSTSTokenTranslationInvocationState invocationState, Context context) throws TokenMarshalException, TokenValidationException, TokenCreationException {
    TokenTypeId inputTokenType = tokenRequestMarshaller.getTokenType(invocationState.getInputTokenState());
    TokenTypeId outputTokenType = tokenRequestMarshaller.getTokenType(invocationState.getOutputTokenState());
    TokenTransform targetedTransform = null;
    for (TokenTransform transform : tokenTransforms) {
        if (transform.isTransformSupported(inputTokenType, outputTokenType)) {
            targetedTransform = transform;
            break;
        }
    }
    if (targetedTransform == null) {
        String message = "The desired transformation, from " + inputTokenType.getId() + " to " + outputTokenType.getId() + ", is not a supported token translation.";
        throw new TokenValidationException(ResourceException.BAD_REQUEST, message);
    }
    RestTokenTransformValidatorParameters<?> validatorParameters = tokenRequestMarshaller.buildTokenTransformValidatorParameters(invocationState.getInputTokenState(), context);
    RestTokenProviderParameters<?> providerParameters = tokenRequestMarshaller.buildTokenProviderParameters(inputTokenType, invocationState.getInputTokenState(), outputTokenType, invocationState.getOutputTokenState());
    return targetedTransform.transformToken(validatorParameters, providerParameters);
}
Also used : TokenTypeId(org.forgerock.openam.sts.TokenTypeId) TokenValidationException(org.forgerock.openam.sts.TokenValidationException)

Example 8 with TokenTypeId

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

the class IssuedTokenValidateOperationImpl method validateToken.

public JsonValue validateToken(RestSTSTokenValidationInvocationState invocationState) throws TokenValidationException, TokenMarshalException {
    TokenTypeId tokenTypeId = tokenRequestMarshaller.getTokenType(invocationState.getValidatedTokenState());
    RestIssuedTokenValidatorParameters<?> validatorParameters = tokenRequestMarshaller.buildIssuedTokenValidatorParameters(invocationState.getValidatedTokenState());
    for (RestIssuedTokenValidator tokenValidator : tokenValidators) {
        if (tokenValidator.canValidateToken(tokenTypeId)) {
            @SuppressWarnings("unchecked") boolean tokenValid = tokenValidator.validateToken(validatorParameters);
            return json(object(field(AMSTSConstants.TOKEN_VALID, tokenValid)));
        }
    }
    throw new TokenValidationException(ResourceException.BAD_REQUEST, "No IssuedTokenValidators available for " + "token type: " + tokenTypeId.getId() + ". Does this sts issue tokens of the specified type?");
}
Also used : RestIssuedTokenValidator(org.forgerock.openam.sts.rest.token.validator.RestIssuedTokenValidator) TokenTypeId(org.forgerock.openam.sts.TokenTypeId) TokenValidationException(org.forgerock.openam.sts.TokenValidationException)

Example 9 with TokenTypeId

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

the class DefaultSaml2XmlTokenAuthnContextMapper method getAuthnContextForDelegatedToken.

@Override
public String getAuthnContextForDelegatedToken(List<WSHandlerResult> securityPolicyBindingTraversalYield, ReceivedToken delegatedToken) {
    final TokenTypeId tokenType = parseTokenTypeFromDelegatedReceivedToken(delegatedToken);
    if (tokenType != null) {
        return peformSaml2AuthNContextClassReferenceMappingForDelegatedToken(tokenType);
    }
    logger.error("Unexpected delegated token type. Returning " + SAML2Constants.AUTH_CONTEXT_CLASS_REF_UNSPECIFIED + " for the AuthnContext class ref.");
    return SAML2Constants.AUTH_CONTEXT_CLASS_REF_UNSPECIFIED;
}
Also used : 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