class TokenRequestMarshallerImpl implements TokenRequestMarshaller {

    @Override
    public RestTokenTransformValidatorParameters<?> buildTokenTransformValidatorParameters(
            JsonValue receivedToken, Context context)
                                                        throws TokenMarshalException {
        if (!receivedToken.get(AMSTSConstants.TOKEN_TYPE_KEY).isString()) {
            String message = "The to-be-translated token does not contain a " + AMSTSConstants.TOKEN_TYPE_KEY +
                    " entry. The token: " + receivedToken;
            throw new TokenMarshalException(ResourceException.BAD_REQUEST, message);
        }
        String tokenType = receivedToken.get(AMSTSConstants.TOKEN_TYPE_KEY).asString();
        if (TokenType.USERNAME.name().equals(tokenType)) {
            return buildUsernameTokenTransformValidatorParameters(receivedToken);
        } else if (TokenType.OPENAM.name().equals(tokenType)) {
            return buildAMSessionTokenTransformValidatorParameters(receivedToken);
        } else if (TokenType.OPENIDCONNECT.name().equals(tokenType)) {
            return buildOpenIdConnectIdTokenTransformValidatorParameters(receivedToken);
        } else if (TokenType.X509.name().equals(tokenType)) {
            return buildX509CertTokenTransformValidatorParameters(context);
        } else {
            for (CustomTokenOperation customTokenOperation : customTokenValidators) {
                if (tokenType.equals(customTokenOperation.getCustomTokenName())) {
                    return buildCustomTokenTransformValidatorParameters(receivedToken);
                }
            }
        }
        throw new TokenMarshalException(ResourceException.BAD_REQUEST, "Unsupported input token type: " + tokenType);
    }

    @Inject  TokenRequestMarshallerImpl(@Named(AMSTSConstants.OFFLOADED_TWO_WAY_TLS_HEADER_KEY) String  offloadedTlsClientCertKey,
                               @Named(AMSTSConstants.TLS_OFFLOAD_ENGINE_HOSTS) Set<String> tlsOffloadEngineHosts,
                               @Named(AMSTSConstants.REST_CUSTOM_TOKEN_VALIDATORS) Set<CustomTokenOperation> customTokenValidators,
                               @Named(AMSTSConstants.REST_CUSTOM_TOKEN_PROVIDERS) Set<CustomTokenOperation> customTokenProviders,
                               Logger logger);

}