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