Search in sources :

Example 1 with TokenCancellationException

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?");
}
Also used : TokenTypeId(org.forgerock.openam.sts.TokenTypeId) TokenCancellationException(org.forgerock.openam.sts.TokenCancellationException) RestIssuedTokenCanceller(org.forgerock.openam.sts.rest.token.canceller.RestIssuedTokenCanceller)

Example 2 with TokenCancellationException

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);
    }
}
Also used : HttpURLConnectionWrapper(org.forgerock.openam.sts.HttpURLConnectionWrapper) TokenCancellationException(org.forgerock.openam.sts.TokenCancellationException) IOException(java.io.IOException) URL(java.net.URL)

Example 3 with TokenCancellationException

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);
        }
    }
}
Also used : STSException(org.apache.cxf.ws.security.sts.provider.STSException) ReceivedToken(org.apache.cxf.sts.request.ReceivedToken) TokenCancellationException(org.forgerock.openam.sts.TokenCancellationException) TokenCancellerResponse(org.apache.cxf.sts.token.canceller.TokenCancellerResponse)

Aggregations

TokenCancellationException (org.forgerock.openam.sts.TokenCancellationException)3 IOException (java.io.IOException)1 URL (java.net.URL)1 ReceivedToken (org.apache.cxf.sts.request.ReceivedToken)1 TokenCancellerResponse (org.apache.cxf.sts.token.canceller.TokenCancellerResponse)1 STSException (org.apache.cxf.ws.security.sts.provider.STSException)1 HttpURLConnectionWrapper (org.forgerock.openam.sts.HttpURLConnectionWrapper)1 TokenTypeId (org.forgerock.openam.sts.TokenTypeId)1 RestIssuedTokenCanceller (org.forgerock.openam.sts.rest.token.canceller.RestIssuedTokenCanceller)1