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