use of com.auth0.Tokens in project gravitee-api-management by gravitee-io.
the class UserServiceImpl method delete.
@Override
public void delete(String id) {
try {
// If the users is PO of apps or apis, throw an exception
long apiCount = apiService.findByUser(id, null, false).stream().filter(entity -> entity.getPrimaryOwner().getId().equals(id)).count();
long applicationCount = applicationService.findByUser(GraviteeContext.getCurrentOrganization(), GraviteeContext.getCurrentEnvironment(), id).stream().filter(app -> app.getPrimaryOwner() != null).filter(app -> app.getPrimaryOwner().getId().equals(id)).count();
if (apiCount > 0 || applicationCount > 0) {
throw new StillPrimaryOwnerException(apiCount, applicationCount);
}
Optional<User> optionalUser = userRepository.findById(id);
if (!optionalUser.isPresent()) {
throw new UserNotFoundException(id);
}
membershipService.removeMemberMemberships(MembershipMemberType.USER, id);
User user = optionalUser.get();
// remove notifications
portalNotificationService.deleteAll(user.getId());
portalNotificationConfigService.deleteByUser(user.getId());
genericNotificationConfigService.deleteByUser(user);
// remove tokens
tokenService.revokeByUser(user.getId());
// change user datas
user.setSourceId("deleted-" + user.getSourceId());
user.setStatus(UserStatus.ARCHIVED);
user.setUpdatedAt(new Date());
if (anonymizeOnDelete) {
User anonym = new User();
anonym.setId(user.getId());
anonym.setCreatedAt(user.getCreatedAt());
anonym.setUpdatedAt(user.getUpdatedAt());
anonym.setStatus(user.getStatus());
anonym.setSource(user.getSource());
anonym.setLastConnectionAt(user.getLastConnectionAt());
anonym.setSourceId("deleted-" + user.getId());
anonym.setFirstname("Unknown");
anonym.setLastname("");
anonym.setLoginCount(user.getLoginCount());
user = anonym;
}
userRepository.update(user);
final UserEntity userEntity = convert(optionalUser.get(), false);
searchEngineService.delete(userEntity);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to delete user", ex);
throw new TechnicalManagementException("An error occurs while trying to delete user", ex);
}
}
use of com.auth0.Tokens in project auth0-java by auth0.
the class BlacklistsEntity method blacklistToken.
/**
* Add a Token to the Blacklist. A token with scope blacklist:tokens is needed.
* See https://auth0.com/docs/api/management/v2#!/Blacklists/post_tokens.
*
* @param token the token to blacklist.
* @return a Request to execute.
*/
public Request<Void> blacklistToken(Token token) {
Asserts.assertNotNull(token, "token");
String url = baseUrl.newBuilder().addPathSegments("api/v2/blacklists/tokens").build().toString();
VoidRequest request = new VoidRequest(client, url, "POST");
request.addHeader("Authorization", "Bearer " + apiToken);
request.setBody(token);
return request;
}
use of com.auth0.Tokens in project auth0-java by auth0.
the class BlacklistsEntityTest method shouldBlacklistToken.
@Test
public void shouldBlacklistToken() throws Exception {
Request<Void> request = api.blacklists().blacklistToken(new Token("id"));
assertThat(request, is(notNullValue()));
server.jsonResponse(MGMT_BLACKLISTED_TOKENS_LIST, 200);
request.execute();
RecordedRequest recordedRequest = server.takeRequest();
assertThat(recordedRequest, hasMethodAndPath("POST", "/api/v2/blacklists/tokens"));
assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
Map<String, Object> body = bodyFromRequest(recordedRequest);
assertThat(body.size(), is(1));
assertThat(body, hasEntry("jti", "id"));
}
use of com.auth0.Tokens in project app-auth0-idprovider by enonic.
the class Auth0CallbackService method retrieveUserInfo.
private UserInfo retrieveUserInfo(IdProviderKey idProviderKey, Tokens tokens) throws Auth0Exception {
final String appClientId = configurationService.getAppClientId(idProviderKey);
final String appSecret = configurationService.getAppSecret(idProviderKey);
final String appDomain = configurationService.getAppDomain(idProviderKey);
final UserInfo userInfo = new AuthAPI(appDomain, appClientId, appSecret).userInfo(tokens.getAccessToken()).execute();
return userInfo;
}
use of com.auth0.Tokens in project AuthGuard by AuthGuard.
the class JwtTokenVerifierTest method validateWithJtiBlacklisted.
@Test
void validateWithJtiBlacklisted() {
final StrategyConfig strategyConfig = strategyConfig(true);
final JwtConfig jwtConfig = jwtConfig();
final JwtTokenVerifier jwtTokenVerifier = newVerifierInstance(strategyConfig);
final String jti = UUID.randomUUID().toString();
Mockito.when(jtiProvider.next()).thenReturn(jti);
Mockito.when(jtiProvider.validate(jti)).thenReturn(false);
final AccountBO account = RANDOM.nextObject(AccountBO.class);
final AuthResponseBO tokens = generateToken(jwtConfig, account, jti);
final Either<Exception, DecodedJWT> validatedToken = jwtTokenVerifier.verify(tokens.getToken().toString());
assertThat(validatedToken.isLeft());
}
Aggregations