Search in sources :

Example 1 with OAuth2RevokeTokenSuperRequest

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

the class OAuth2Controller method revokeTokenViaSuperClient.

@POST
@Path("revoke/super")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response revokeTokenViaSuperClient(@Context SecurityContext context, @Context HttpServletRequest request, MultivaluedMap<String, String> form) {
    TokenContext tokenContext = (TokenContext) context.getUserPrincipal();
    String username = tokenContext.getUsername();
    try {
        OAuth2RevokeTokenSuperRequest revokeTokenRequest = new OAuth2RevokeTokenSuperRequest(new FormRequestWrapper(request, form));
        tokenService.revokeTokensViaSuperClient(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) KustvaktException(de.ids_mannheim.korap.exceptions.KustvaktException) OAuthSystemException(org.apache.oltu.oauth2.common.exception.OAuthSystemException) OAuth2RevokeTokenSuperRequest(de.ids_mannheim.korap.oauth2.oltu.OAuth2RevokeTokenSuperRequest) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 2 with OAuth2RevokeTokenSuperRequest

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

the class OltuTokenService method revokeTokensViaSuperClient.

public void revokeTokensViaSuperClient(String username, OAuth2RevokeTokenSuperRequest 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 token = revokeTokenRequest.getToken();
    RefreshToken refreshToken = refreshDao.retrieveRefreshToken(token, username);
    if (!revokeRefreshToken(refreshToken)) {
        AccessToken accessToken = tokenDao.retrieveAccessToken(token, username);
        revokeAccessToken(accessToken);
    }
}
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 OAuth2RevokeTokenSuperRequest (de.ids_mannheim.korap.oauth2.oltu.OAuth2RevokeTokenSuperRequest)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