Search in sources :

Example 1 with OAuth2RevokeAllTokenSuperRequest

use of de.ids_mannheim.korap.oauth2.oltu.OAuth2RevokeAllTokenSuperRequest in project Kustvakt by KorAP.

the class OAuth2Controller method revokeAllClientTokensViaSuperClient.

/**
 * Revokes all tokens of a client for the authenticated user from
 * a super client. This service is not part of the OAUTH2
 * specification. It requires user authentication via
 * authorization header, and super client
 * via URL-encoded form parameters.
 *
 * @param request
 * @param form
 *            containing client_id, super_client_id,
 *            super_client_secret
 * @return 200 if token invalidation is successful or the given
 *         token is invalid
 */
@POST
@Path("revoke/super/all")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response revokeAllClientTokensViaSuperClient(@Context SecurityContext context, @Context HttpServletRequest request, MultivaluedMap<String, String> form) {
    TokenContext tokenContext = (TokenContext) context.getUserPrincipal();
    String username = tokenContext.getUsername();
    try {
        OAuth2RevokeAllTokenSuperRequest revokeTokenRequest = new OAuth2RevokeAllTokenSuperRequest(new FormRequestWrapper(request, form));
        tokenService.revokeAllClientTokensViaSuperClient(username, revokeTokenRequest);
        return Response.ok("SUCCESS").build();
    } catch (OAuthSystemException e) {
        throw responseHandler.throwit(e);
    } catch (OAuthProblemException e) {
        throw responseHandler.throwit(e);
    } catch (KustvaktException e) {
        throw responseHandler.throwit(e);
    }
}
Also used : TokenContext(de.ids_mannheim.korap.security.context.TokenContext) OAuthProblemException(org.apache.oltu.oauth2.common.exception.OAuthProblemException) FormRequestWrapper(de.ids_mannheim.korap.web.utils.FormRequestWrapper) OAuth2RevokeAllTokenSuperRequest(de.ids_mannheim.korap.oauth2.oltu.OAuth2RevokeAllTokenSuperRequest) KustvaktException(de.ids_mannheim.korap.exceptions.KustvaktException) OAuthSystemException(org.apache.oltu.oauth2.common.exception.OAuthSystemException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 2 with OAuth2RevokeAllTokenSuperRequest

use of de.ids_mannheim.korap.oauth2.oltu.OAuth2RevokeAllTokenSuperRequest in project Kustvakt by KorAP.

the class OltuTokenService method revokeAllClientTokensViaSuperClient.

public void revokeAllClientTokensViaSuperClient(String username, OAuth2RevokeAllTokenSuperRequest revokeTokenRequest) throws KustvaktException {
    String superClientId = revokeTokenRequest.getSuperClientId();
    String superClientSecret = revokeTokenRequest.getSuperClientSecret();
    OAuth2Client superClient = clientService.authenticateClient(superClientId, superClientSecret);
    if (!superClient.isSuper()) {
        throw new KustvaktException(StatusCodes.CLIENT_AUTHENTICATION_FAILED);
    }
    String clientId = revokeTokenRequest.getClientId();
    OAuth2Client client = clientService.retrieveClient(clientId);
    if (clientService.isPublicClient(client)) {
        List<AccessToken> accessTokens = tokenDao.retrieveAccessTokenByClientId(clientId, username);
        for (AccessToken t : accessTokens) {
            revokeAccessToken(t);
        }
    } else {
        List<RefreshToken> refreshTokens = refreshDao.retrieveRefreshTokenByClientId(clientId, username);
        for (RefreshToken r : refreshTokens) {
            revokeRefreshToken(r);
        }
    }
}
Also used : KustvaktException(de.ids_mannheim.korap.exceptions.KustvaktException) RefreshToken(de.ids_mannheim.korap.oauth2.entity.RefreshToken) OAuth2Client(de.ids_mannheim.korap.oauth2.entity.OAuth2Client) AccessToken(de.ids_mannheim.korap.oauth2.entity.AccessToken)

Aggregations

KustvaktException (de.ids_mannheim.korap.exceptions.KustvaktException)2 AccessToken (de.ids_mannheim.korap.oauth2.entity.AccessToken)1 OAuth2Client (de.ids_mannheim.korap.oauth2.entity.OAuth2Client)1 RefreshToken (de.ids_mannheim.korap.oauth2.entity.RefreshToken)1 OAuth2RevokeAllTokenSuperRequest (de.ids_mannheim.korap.oauth2.oltu.OAuth2RevokeAllTokenSuperRequest)1 TokenContext (de.ids_mannheim.korap.security.context.TokenContext)1 FormRequestWrapper (de.ids_mannheim.korap.web.utils.FormRequestWrapper)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 OAuthProblemException (org.apache.oltu.oauth2.common.exception.OAuthProblemException)1 OAuthSystemException (org.apache.oltu.oauth2.common.exception.OAuthSystemException)1