use of io.jans.as.model.common.TokenTypeHint in project jans by JanssenProject.
the class RevokeRestWebServiceImpl method requestAccessToken.
@Override
public Response requestAccessToken(String tokenString, String tokenTypeHint, String clientId, HttpServletRequest request, HttpServletResponse response, SecurityContext sec) {
log.debug("Attempting to revoke token: token = {}, tokenTypeHint = {}, isSecure = {}", tokenString, tokenTypeHint, sec.isSecure());
errorResponseFactory.validateComponentEnabled(ComponentType.REVOKE_TOKEN);
OAuth2AuditLog oAuth2AuditLog = new OAuth2AuditLog(ServerUtil.getIpAddress(request), Action.TOKEN_REVOCATION);
validateToken(tokenString);
Response.ResponseBuilder builder = Response.ok();
SessionClient sessionClient = identity.getSessionClient();
Client client = sessionClient != null ? sessionClient.getClient() : null;
if (client == null) {
client = clientService.getClient(clientId);
if (!clientService.isPublic(client)) {
log.trace("Client is not public and not authenticated. Skip revoking.");
return response(builder, oAuth2AuditLog);
}
}
if (client == null) {
log.trace("Client is not unknown. Skip revoking.");
return response(builder, oAuth2AuditLog);
}
oAuth2AuditLog.setClientId(client.getClientId());
ExecutionContext executionContext = new ExecutionContext(request, response);
executionContext.setClient(client);
executionContext.setResponseBuilder(builder);
final boolean scriptResult = externalRevokeTokenService.revokeTokenMethods(executionContext);
if (!scriptResult) {
log.trace("Revoke is forbidden by 'Revoke Token' custom script (method returned false). Exit without revoking.");
return response(builder, oAuth2AuditLog);
}
TokenTypeHint tth = TokenTypeHint.getByValue(tokenTypeHint);
boolean isAll = Constants.ALL.equalsIgnoreCase(tokenString) && appConfiguration.getAllowAllValueForRevokeEndpoint();
if (isAll) {
removeAllTokens(tth, executionContext);
return response(builder, oAuth2AuditLog);
}
String[] tokens = tokenString.split(" ");
if (ArrayUtils.isEmpty(tokens)) {
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST.getStatusCode()).type(MediaType.APPLICATION_JSON_TYPE).entity(errorResponseFactory.errorAsJson(TokenRevocationErrorResponseType.INVALID_REQUEST, "Failed to validate token.")).build());
}
boolean isSingle = tokens.length == 1;
for (String token : tokens) {
final Response removeTokenResponse = removeToken(token, executionContext, tth, oAuth2AuditLog, isSingle);
if (removeTokenResponse != null) {
return removeTokenResponse;
}
}
return response(builder, oAuth2AuditLog);
}
Aggregations