Search in sources :

Example 1 with Tokens

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);
    }
}
Also used : BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) Page(io.gravitee.common.data.domain.Page) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) LoggerFactory(org.slf4j.LoggerFactory) MembershipRepository(io.gravitee.repository.management.api.MembershipRepository) Autowired(org.springframework.beans.factory.annotation.Autowired) SocialIdentityProviderEntity(io.gravitee.rest.api.model.configuration.identity.SocialIdentityProviderEntity) RoleScope(io.gravitee.rest.api.model.permissions.RoleScope) StringUtils(org.apache.commons.lang3.StringUtils) UPDATE(io.gravitee.rest.api.model.permissions.RolePermissionAction.UPDATE) IdentityProviderService(io.gravitee.rest.api.service.configuration.identity.IdentityProviderService) TemplateEngine(io.gravitee.el.TemplateEngine) Algorithm(com.auth0.jwt.algorithms.Algorithm) AuditQuery(io.gravitee.rest.api.model.audit.AuditQuery) PageableBuilder(io.gravitee.repository.management.api.search.builder.PageableBuilder) RoleMappingEntity(io.gravitee.rest.api.model.configuration.identity.RoleMappingEntity) Duration(java.time.Duration) PortalHook(io.gravitee.rest.api.service.notification.PortalHook) GroupMappingEntity(io.gravitee.rest.api.model.configuration.identity.GroupMappingEntity) Collectors.toSet(java.util.stream.Collectors.toSet) ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) RolePermissionAction(io.gravitee.rest.api.model.permissions.RolePermissionAction) JsonPathFunction(io.gravitee.el.spel.function.json.JsonPathFunction) Instant(java.time.Instant) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) Collectors(java.util.stream.Collectors) Key(io.gravitee.rest.api.model.parameters.Key) NotificationParamsBuilder(io.gravitee.rest.api.service.notification.NotificationParamsBuilder) EmailNotificationBuilder(io.gravitee.rest.api.service.builder.EmailNotificationBuilder) UrlSanitizerUtils(io.gravitee.rest.api.service.sanitizer.UrlSanitizerUtils) DatatypeConverter(javax.xml.bind.DatatypeConverter) AuditEntity(io.gravitee.rest.api.model.audit.AuditEntity) RolePermission(io.gravitee.rest.api.model.permissions.RolePermission) SearchEngineService(io.gravitee.rest.api.service.search.SearchEngineService) JWT(com.auth0.jwt.JWT) io.gravitee.rest.api.service(io.gravitee.rest.api.service) java.util(java.util) DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT) Pageable(io.gravitee.rest.api.model.common.Pageable) GraviteeContext(io.gravitee.rest.api.service.common.GraviteeContext) DEFAULT_JWT_EMAIL_REGISTRATION_EXPIRE_AFTER(io.gravitee.rest.api.service.common.JWTHelper.DefaultValues.DEFAULT_JWT_EMAIL_REGISTRATION_EXPIRE_AFTER) InitializingBean(org.springframework.beans.factory.InitializingBean) Value(org.springframework.beans.factory.annotation.Value) JWTVerifier(com.auth0.jwt.JWTVerifier) ReadContext(com.jayway.jsonpath.ReadContext) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) UserRepository(io.gravitee.repository.management.api.UserRepository) Claims(io.gravitee.rest.api.service.common.JWTHelper.Claims) UserStatus(io.gravitee.repository.management.model.UserStatus) io.gravitee.rest.api.model(io.gravitee.rest.api.model) Membership(io.gravitee.repository.management.model.Membership) Query(io.gravitee.rest.api.service.search.query.Query) UuidString(io.gravitee.rest.api.service.common.UuidString) Logger(org.slf4j.Logger) ParameterReferenceType(io.gravitee.rest.api.model.parameters.ParameterReferenceType) JsonPath(com.jayway.jsonpath.JsonPath) Maps(io.gravitee.common.util.Maps) DEFAULT_JWT_ISSUER(io.gravitee.rest.api.service.common.JWTHelper.DefaultValues.DEFAULT_JWT_ISSUER) MetadataPage(io.gravitee.common.data.domain.MetadataPage) Collectors.toList(java.util.stream.Collectors.toList) Component(org.springframework.stereotype.Component) USER(io.gravitee.repository.management.model.Audit.AuditProperties.USER) ChronoUnit(java.time.temporal.ChronoUnit) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) io.gravitee.rest.api.service.exceptions(io.gravitee.rest.api.service.exceptions) UserCriteria(io.gravitee.repository.management.api.search.UserCriteria) User(io.gravitee.repository.management.model.User) ACTION(io.gravitee.rest.api.service.common.JWTHelper.ACTION) QueryBuilder(io.gravitee.rest.api.service.search.query.QueryBuilder) SearchResult(io.gravitee.rest.api.service.impl.search.SearchResult) User(io.gravitee.repository.management.model.User) TechnicalException(io.gravitee.repository.exceptions.TechnicalException)

Example 2 with Tokens

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;
}
Also used : VoidRequest(com.auth0.net.VoidRequest)

Example 3 with Tokens

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"));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Token(com.auth0.json.mgmt.Token) Test(org.junit.Test)

Example 4 with Tokens

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;
}
Also used : UserInfo(com.auth0.json.auth.UserInfo) AuthAPI(com.auth0.client.auth.AuthAPI)

Example 5 with Tokens

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());
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) JwtConfig(com.nexblocks.authguard.service.config.JwtConfig) StrategyConfig(com.nexblocks.authguard.service.config.StrategyConfig) AuthResponseBO(com.nexblocks.authguard.service.model.AuthResponseBO) DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT) ServiceAuthorizationException(com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException) Test(org.junit.jupiter.api.Test)

Aggregations

DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)13 HashMap (java.util.HashMap)8 Test (org.junit.jupiter.api.Test)7 Algorithm (com.auth0.jwt.algorithms.Algorithm)6 TokenHolder (com.auth0.json.auth.TokenHolder)4 TokenRequest (com.auth0.net.TokenRequest)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 Date (java.util.Date)4 JWT (com.auth0.jwt.JWT)3 JWTVerifier (com.auth0.jwt.JWTVerifier)3 ServiceAuthorizationException (com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException)3 AccountBO (com.nexblocks.authguard.service.model.AccountBO)3 User (org.springframework.security.core.userdetails.User)3 JWTVerificationException (com.auth0.jwt.exceptions.JWTVerificationException)2 Claim (com.auth0.jwt.interfaces.Claim)2 JsonPath (com.jayway.jsonpath.JsonPath)2 ReadContext (com.jayway.jsonpath.ReadContext)2 JwtConfig (com.nexblocks.authguard.service.config.JwtConfig)2 StrategyConfig (com.nexblocks.authguard.service.config.StrategyConfig)2 AuthResponseBO (com.nexblocks.authguard.service.model.AuthResponseBO)2