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);
}
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);
}
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?");
}
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;
}
Aggregations