use of org.forgerock.openam.sts.TokenCancellationException 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.TokenCancellationException in project OpenAM by OpenRock.
the class TokenServiceConsumerImpl method invokeTokenCancellation.
private void invokeTokenCancellation(String tokenId, String callerSSOTokenString) throws TokenCancellationException {
try {
Map<String, String> headerMap = makeCommonHeaders(callerSSOTokenString);
HttpURLConnectionWrapper.ConnectionResult connectionResult = httpURLConnectionWrapperFactory.httpURLConnectionWrapper(new URL(urlConstituentCatenator.catenateUrlConstituents(tokenServiceEndpoint, tokenId))).setRequestHeaders(headerMap).setRequestMethod(DELETE).makeInvocation();
final int responseCode = connectionResult.getStatusCode();
if (responseCode != HttpURLConnection.HTTP_OK) {
throw new TokenCancellationException(responseCode, connectionResult.getResult());
}
} catch (IOException e) {
throw new TokenCancellationException(ResourceException.INTERNAL_ERROR, "Exception caught invoking TokenService to cancel a token: " + e);
}
}
use of org.forgerock.openam.sts.TokenCancellationException in project OpenAM by OpenRock.
the class TokenCancellerBase method cancelToken.
@Override
public TokenCancellerResponse cancelToken(TokenCancellerParameters tokenParameters) {
TokenCancellerResponse response = new TokenCancellerResponse();
ReceivedToken cancelTarget = tokenParameters.getToken();
cancelTarget.setState(ReceivedToken.STATE.VALID);
response.setToken(cancelTarget);
String tokenServiceConsumptionToken = null;
try {
final String tokenId = generateIdFromValidateTarget(cancelTarget);
tokenServiceConsumptionToken = getTokenServiceConsumptionToken();
tokenServiceConsumer.cancelToken(tokenId, tokenServiceConsumptionToken);
cancelTarget.setState(ReceivedToken.STATE.CANCELLED);
return response;
} catch (TokenCancellationException e) {
throw new STSException("Exception caught validating issued token: " + e.getMessage(), e);
} finally {
if (tokenServiceConsumptionToken != null) {
invalidateTokenGenerationServiceConsumptionToken(tokenServiceConsumptionToken);
}
}
}
Aggregations