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