Search in sources :

Example 16 with TokenValidationException

use of org.forgerock.openam.sts.TokenValidationException 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 17 with TokenValidationException

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

the class SimpleTokenValidatorBase method validateToken.

@Override
public TokenValidatorResponse validateToken(TokenValidatorParameters tokenParameters) {
    TokenValidatorResponse response = new TokenValidatorResponse();
    ReceivedToken validateTarget = tokenParameters.getToken();
    response.setToken(validateTarget);
    String tokenServiceConsumptionToken = null;
    try {
        final String tokenId = generateIdFromValidateTarget(validateTarget);
        tokenServiceConsumptionToken = getTokenServiceConsumptionToken();
        final boolean isTokenValid = tokenServiceConsumer.validateToken(tokenId, tokenServiceConsumptionToken);
        validateTarget.setState(isTokenValid ? ReceivedToken.STATE.VALID : ReceivedToken.STATE.INVALID);
        return response;
    } catch (TokenValidationException e) {
        throw new STSException("Exception caught validating issued token: " + e.getMessage(), e);
    } finally {
        if (tokenServiceConsumptionToken != null) {
            invalidateTokenGenerationServiceConsumptionToken(tokenServiceConsumptionToken);
        }
    }
}
Also used : STSException(org.apache.cxf.ws.security.sts.provider.STSException) TokenValidatorResponse(org.apache.cxf.sts.token.validator.TokenValidatorResponse) ReceivedToken(org.apache.cxf.sts.request.ReceivedToken) TokenValidationException(org.forgerock.openam.sts.TokenValidationException)

Aggregations

TokenValidationException (org.forgerock.openam.sts.TokenValidationException)17 IOException (java.io.IOException)7 HttpURLConnectionWrapper (org.forgerock.openam.sts.HttpURLConnectionWrapper)7 HashMap (java.util.HashMap)6 URL (java.net.URL)3 WSSecurityException (org.apache.ws.security.WSSecurityException)3 JsonException (org.forgerock.json.JsonException)2 JsonValue (org.forgerock.json.JsonValue)2 TokenTypeId (org.forgerock.openam.sts.TokenTypeId)2 MalformedURLException (java.net.MalformedURLException)1 Principal (java.security.Principal)1 CertificateEncodingException (java.security.cert.CertificateEncodingException)1 X509Certificate (java.security.cert.X509Certificate)1 ReceivedToken (org.apache.cxf.sts.request.ReceivedToken)1 TokenDelegationResponse (org.apache.cxf.sts.token.delegation.TokenDelegationResponse)1 TokenValidatorResponse (org.apache.cxf.sts.token.validator.TokenValidatorResponse)1 STSException (org.apache.cxf.ws.security.sts.provider.STSException)1 WSSecurityEngineResult (org.apache.ws.security.WSSecurityEngineResult)1 BinarySecurity (org.apache.ws.security.message.token.BinarySecurity)1 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)1