@PreAuthorize("isAuthenticated()") public void logout() { AccessToken accessToken = accessTokenDAO.findByOwner(AuthContextUtils.getUsername()); if (accessToken == null) { throw new NotFoundException("AccessToken for " + AuthContextUtils.getUsername()); } delete(accessToken.getKey()); }
private AccessToken replace( final String subject, final Map<String, Object> claims, final byte[] authorities, final AccessToken accessToken) { Pair<String, Date> generated = generateJWT( accessToken.getKey(), subject, confDAO.find("jwt.lifetime.minutes", 120L), claims); accessToken.setBody(generated.getLeft()); accessToken.setExpiryTime(generated.getRight()); accessToken.setOwner(subject); if (!adminUser.equals(accessToken.getOwner())) { accessToken.setAuthorities(authorities); } return accessTokenDAO.save(accessToken); }
@PreAuthorize("isAuthenticated() " + "and not(hasRole('" + StandardEntitlement.ANONYMOUS + "')) " + "and not(hasRole('" + StandardEntitlement.MUST_CHANGE_PASSWORD + "'))") public ProvisioningResult<UserTO> selfUpdate(final UserPatch userPatch, final boolean nullPriorityAsync) { UserTO userTO = binder.getAuthenticatedUserTO(); userPatch.setKey(userTO.getKey()); ProvisioningResult<UserTO> updated = doUpdate(userPatch, true, nullPriorityAsync); // Ensures that, if the self update above moves the user into a status from which no authentication // is possible, the existing Access Token is clean up to avoid issues with future authentications if (!confDAO.getValuesAsStrings("authentication.statuses").contains(updated.getEntity().getStatus())) { String accessToken = accessTokenDAO.findByOwner(updated.getEntity().getUsername()).getKey(); if (accessToken != null) { accessTokenDAO.delete(accessToken); } } return updated; }
@Override public AccessTokenTO getAccessTokenTO(final AccessToken accessToken) { AccessTokenTO accessTokenTO = new AccessTokenTO(); accessTokenTO.setKey(accessToken.getKey()); accessTokenTO.setBody(accessToken.getBody()); accessTokenTO.setExpiryTime(accessToken.getExpiryTime()); accessTokenTO.setOwner(accessToken.getOwner()); return accessTokenTO; } }