Search in sources :

Example 16 with User

use of com.auth0.json.mgmt.users.User in project neubbs by nuitcoder.

the class SecretUtil method decryptUserInfoToken.

/**
 * 解密用户信息 Token
 *      - 解密 JWT 生成的用户信息 Token, 获取 UserDO 对象
 *
 * @param token 密文 token
 * @return UserDO 用户信息对象(包含 id,name,rank,state 属性)
 */
public static UserDO decryptUserInfoToken(String token) {
    checkParamNotNull(token);
    DecodedJWT decodedJWT;
    try {
        // decrypt HS256
        JWTVerifier verifier = JWT.require(Algorithm.HMAC256(SetConst.JWT_TOKEN_SECRET_KEY)).build();
        // decoding Base64
        decodedJWT = verifier.verify(token);
    } catch (UnsupportedEncodingException | TokenExpiredException e) {
        throw new UtilClassException(ApiMessage.UNKNOWN_ERROR).log(LogWarnEnum.UC10);
    }
    // Get User information(id, name, rank ,state)
    UserDO user = new UserDO();
    user.setId(decodedJWT.getClaim(ParamConst.ID).asInt());
    user.setName(decodedJWT.getClaim(ParamConst.NAME).asString());
    user.setRank(decodedJWT.getClaim(ParamConst.RANK).asString());
    user.setState(decodedJWT.getClaim(ParamConst.STATE).asInt());
    return user;
}
Also used : UtilClassException(org.neusoft.neubbs.exception.UtilClassException) TokenExpiredException(com.auth0.jwt.exceptions.TokenExpiredException) UserDO(org.neusoft.neubbs.entity.UserDO) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT) JWTVerifier(com.auth0.jwt.JWTVerifier)

Example 17 with User

use of com.auth0.json.mgmt.users.User in project gravitee-management-rest-api by gravitee-io.

the class UserServiceImpl method findByIds.

@Override
public Set<UserEntity> findByIds(List<String> ids) {
    try {
        LOGGER.debug("Find users by ID: {}", ids);
        Set<User> users = userRepository.findByIds(ids);
        if (!users.isEmpty()) {
            return users.stream().map(u -> this.convert(u, false)).collect(Collectors.toSet());
        }
        Optional<String> idsAsString = ids.stream().reduce((a, b) -> a + '/' + b);
        if (idsAsString.isPresent()) {
            throw new UserNotFoundException(idsAsString.get());
        } else {
            throw new UserNotFoundException("?");
        }
    } catch (TechnicalException ex) {
        Optional<String> idsAsString = ids.stream().reduce((a, b) -> a + '/' + b);
        LOGGER.error("An error occurs while trying to find users using their ID {}", idsAsString, ex);
        throw new TechnicalManagementException("An error occurs while trying to find users using their ID " + idsAsString, ex);
    }
}
Also used : RoleScope(io.gravitee.repository.management.model.RoleScope) java.util(java.util) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) NotificationParamsBuilder(io.gravitee.management.service.notification.NotificationParamsBuilder) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) MembershipDefaultReferenceId(io.gravitee.repository.management.model.MembershipDefaultReferenceId) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) EmailNotificationBuilder(io.gravitee.management.service.builder.EmailNotificationBuilder) StringUtils(org.apache.commons.lang3.StringUtils) Value(org.springframework.beans.factory.annotation.Value) DEFAULT_JWT_EMAIL_REGISTRATION_EXPIRE_AFTER(io.gravitee.management.service.common.JWTHelper.DefaultValues.DEFAULT_JWT_EMAIL_REGISTRATION_EXPIRE_AFTER) JWTVerifier(com.auth0.jwt.JWTVerifier) UUID(io.gravitee.common.utils.UUID) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) io.gravitee.management.model(io.gravitee.management.model) UserRepository(io.gravitee.repository.management.api.UserRepository) JWTSigner(com.auth0.jwt.JWTSigner) DEFAULT_JWT_ISSUER(io.gravitee.management.service.common.JWTHelper.DefaultValues.DEFAULT_JWT_ISSUER) UserNotFoundException(io.gravitee.management.service.exceptions.UserNotFoundException) Claims(io.gravitee.management.service.common.JWTHelper.Claims) MembershipReferenceType(io.gravitee.repository.management.model.MembershipReferenceType) UsernameAlreadyExistsException(io.gravitee.management.service.exceptions.UsernameAlreadyExistsException) Logger(org.slf4j.Logger) DefaultRoleNotFoundException(io.gravitee.management.service.exceptions.DefaultRoleNotFoundException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) PortalHook(io.gravitee.management.service.notification.PortalHook) Collectors(java.util.stream.Collectors) IOUtils(org.apache.commons.io.IOUtils) Component(org.springframework.stereotype.Component) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) USER(io.gravitee.repository.management.model.Audit.AuditProperties.USER) io.gravitee.management.service(io.gravitee.management.service) User(io.gravitee.repository.management.model.User) io.gravitee.common.utils(io.gravitee.common.utils) DatatypeConverter(javax.xml.bind.DatatypeConverter) UserNotFoundException(io.gravitee.management.service.exceptions.UserNotFoundException) User(io.gravitee.repository.management.model.User) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 18 with User

use of com.auth0.json.mgmt.users.User in project nextprot-api by calipho-sib.

the class NextprotAuth0EndpointImpl method fetchUser.

@Cacheable("user-auth")
public Auth0User fetchUser(String accessToken) throws IOException, JSONException {
    Resty resty = new Resty();
    String userInfoUri = getUserInfoUri(accessToken);
    JSONResource json = resty.json(userInfoUri);
    return new Auth0User(json.toObject());
}
Also used : Auth0User(com.auth0.Auth0User) Resty(us.monoid.web.Resty) JSONResource(us.monoid.web.JSONResource) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 19 with User

use of com.auth0.json.mgmt.users.User in project survey by markoniemi.

the class JwtTokenTest method verifyTokenWithExpiredToken.

@Test
public void verifyTokenWithExpiredToken() {
    try {
        User user = new User("username", "password", "email", Role.ROLE_USER);
        Map<String, Object> payload = new HashMap<String, Object>();
        payload.put("username", user.getUsername());
        JwtToken token = new JwtToken(payload, 1);
        Thread.sleep(1000);
        token.verifyToken();
        Assert.fail();
    } catch (Exception e) {
        Assert.assertTrue(e instanceof JWTExpiredException);
    }
}
Also used : User(org.survey.model.user.User) HashMap(java.util.HashMap) JWTExpiredException(com.auth0.jwt.JWTExpiredException) JWTExpiredException(com.auth0.jwt.JWTExpiredException) JWTVerifyException(com.auth0.jwt.JWTVerifyException) Test(org.junit.Test)

Example 20 with User

use of com.auth0.json.mgmt.users.User in project chefly_android by chef-ly.

the class MainActivity method socialLogin.

private void socialLogin(String connection) {
    // getString(R.string.auth0_domain
    Auth0 auth0 = new Auth0(getString(R.string.auth0_client_id), getString(R.string.auth0_domain));
    WebAuthProvider.init(auth0).withConnection(connection).start(MainActivity.this, new AuthCallback() {

        @Override
        public void onFailure(@NonNull Dialog dialog) {
            dialog.show();
        }

        @Override
        public void onFailure(final AuthenticationException exception) {
            // Show error to the user
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    Log.d(TAG, "LOGIN FAIL");
                    String errorMsg = "Sign in request failed";
                    showToast(errorMsg);
                }
            });
        }

        @Override
        public void onSuccess(@NonNull Credentials credentials) {
            // Navigate to your next activity
            startRecipeListActivity("aaa");
        }
    });
}
Also used : Auth0(com.auth0.android.Auth0) AuthenticationException(com.auth0.android.authentication.AuthenticationException) AuthCallback(com.auth0.android.provider.AuthCallback) Dialog(android.app.Dialog) Credentials(com.auth0.android.result.Credentials)

Aggregations

JWTSigner (com.auth0.jwt.JWTSigner)5 JWT (com.auth0.jwt.JWT)4 JWTVerifier (com.auth0.jwt.JWTVerifier)4 Algorithm (com.auth0.jwt.algorithms.Algorithm)4 Collectors (java.util.stream.Collectors)4 Test (org.junit.Test)4 JWTExpiredException (com.auth0.jwt.JWTExpiredException)3 JWTVerifyException (com.auth0.jwt.JWTVerifyException)3 EmailNotificationBuilder (io.gravitee.management.service.builder.EmailNotificationBuilder)3 DefaultRoleNotFoundException (io.gravitee.management.service.exceptions.DefaultRoleNotFoundException)3 TechnicalManagementException (io.gravitee.management.service.exceptions.TechnicalManagementException)3 UserNotFoundException (io.gravitee.management.service.exceptions.UserNotFoundException)3 URI (java.net.URI)3 APIException (com.auth0.exception.APIException)2 Auth0Exception (com.auth0.exception.Auth0Exception)2 User (com.auth0.json.mgmt.users.User)2 JWTCreator (com.auth0.jwt.JWTCreator)2 PublicClaims (com.auth0.jwt.impl.PublicClaims)2 Claim (com.auth0.jwt.interfaces.Claim)2 ImmutableList (com.google.common.collect.ImmutableList)2