Search in sources :

Example 31 with User

use of com.auth0.flickr2.domain.User in project auth0-java by auth0.

the class UsersEntityTest method shouldGetUserWithFields.

@Test
public void shouldGetUserWithFields() throws Exception {
    UserFilter filter = new UserFilter().withFields("some,random,fields", true);
    Request<User> request = api.users().get("1", filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_USER, 200);
    User response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/users/1"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(recordedRequest, hasQueryParameter("fields", "some,random,fields"));
    assertThat(recordedRequest, hasQueryParameter("include_fields", "true"));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) User(com.auth0.json.mgmt.users.User) UserFilter(com.auth0.client.mgmt.filter.UserFilter) Test(org.junit.Test)

Example 32 with User

use of com.auth0.flickr2.domain.User in project auth0-java by auth0.

the class EmailVerificationTicketTest method shouldSerializeWithIdentity.

@Test
public void shouldSerializeWithIdentity() throws Exception {
    EmailVerificationTicket ticket = new EmailVerificationTicket("usr123");
    ticket.setResultUrl("https://page.auth0.com/result");
    ticket.setTTLSeconds(36000);
    EmailVerificationIdentity identity = new EmailVerificationIdentity("some-provider", "some-user-id");
    ticket.setIdentity(identity);
    String serialized = toJSON(ticket);
    assertThat(serialized, is(notNullValue()));
    assertThat(serialized, JsonMatcher.hasEntry("user_id", "usr123"));
    assertThat(serialized, JsonMatcher.hasEntry("result_url", "https://page.auth0.com/result"));
    assertThat(serialized, JsonMatcher.hasEntry("ttl_sec", 36000));
    Map<String, String> identityMap = new HashMap<>();
    identityMap.put("provider", "some-provider");
    identityMap.put("user_id", "some-user-id");
    assertThat(serialized, JsonMatcher.hasEntry("identity", identityMap));
}
Also used : HashMap(java.util.HashMap) EmailVerificationIdentity(com.auth0.json.mgmt.EmailVerificationIdentity) JsonTest(com.auth0.json.JsonTest) Test(org.junit.Test)

Example 33 with User

use of com.auth0.flickr2.domain.User in project auth0-java by auth0.

the class JobErrorDetailsTest method shouldSerialize.

@Test
public void shouldSerialize() throws JsonProcessingException {
    User user = new User();
    user.setEmail("john.doe@gmail.com");
    JobError error = new JobError("code", "message", "path");
    JobErrorDetails errorDetails = new JobErrorDetails(user, Collections.singletonList(error));
    String serialized = toJSON(errorDetails);
    assertThat(serialized, is(equalTo(json)));
}
Also used : User(com.auth0.json.mgmt.users.User) JsonTest(com.auth0.json.JsonTest) Test(org.junit.Test)

Example 34 with User

use of com.auth0.flickr2.domain.User in project CSKY by SHU-Silence.

the class UserServiceImpl method createToken.

private String createToken(User user) {
    UserVo userVo = new UserVo();
    BeanUtils.copyProperties(user, userVo);
    Algorithm algorithm = Algorithm.HMAC256(user.getPassword());
    Date nowDate = new Date();
    Date expireDate = new Date(System.currentTimeMillis() + 2 * 60 * 60 * 1000);
    return JWT.create().withIssuedAt(// 设置 载荷 生成签名的时间
    nowDate).withExpiresAt(// 设置 载荷 签名过期的时间
    expireDate).withAudience(JSON.toJSONString(userVo), user.getUsername()).sign(// 签名 Signature
    algorithm);
}
Also used : UserVo(shu.java.csky.vo.UserVo) Algorithm(com.auth0.jwt.algorithms.Algorithm) Date(java.util.Date)

Example 35 with User

use of com.auth0.flickr2.domain.User in project conquery by bakdata.

the class ConqueryTokenRealm method doGetAuthenticationInfo.

@Override
public ConqueryAuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    if (!(TOKEN_CLASS.isAssignableFrom(token.getClass()))) {
        log.trace("Incompatible token. Expected {}, got {}", TOKEN_CLASS, token.getClass());
        return null;
    }
    log.trace("Token has expected format: {}\tWas: {} ", TOKEN_CLASS, token.getClass());
    DecodedJWT decodedToken = null;
    try {
        decodedToken = jwtConfig.getTokenVerifier(this).verify((String) token.getCredentials());
    } catch (TokenExpiredException e) {
        log.trace("The provided token is expired.");
        throw new ExpiredCredentialsException(e);
    } catch (SignatureVerificationException | InvalidClaimException e) {
        log.trace("The provided token was not successfully verified against its signature or claims.");
        throw new IncorrectCredentialsException(e);
    } catch (JWTVerificationException e) {
        log.trace("The provided token could not be verified.", e);
        throw new AuthenticationException(e);
    } catch (Exception e) {
        log.trace("Unable to decode token", e);
        throw new AuthenticationException(e);
    }
    log.trace("Received valid token.");
    String username = decodedToken.getSubject();
    UserId userId = UserId.Parser.INSTANCE.parse(username);
    final User user = getUserOrThrowUnknownAccount(storage, userId);
    return new ConqueryAuthenticationInfo(user, token, this, true);
}
Also used : User(com.bakdata.conquery.models.auth.entities.User) InvalidClaimException(com.auth0.jwt.exceptions.InvalidClaimException) TokenExpiredException(com.auth0.jwt.exceptions.TokenExpiredException) InvalidClaimException(com.auth0.jwt.exceptions.InvalidClaimException) SignatureVerificationException(com.auth0.jwt.exceptions.SignatureVerificationException) JWTVerificationException(com.auth0.jwt.exceptions.JWTVerificationException) JWTVerificationException(com.auth0.jwt.exceptions.JWTVerificationException) TokenExpiredException(com.auth0.jwt.exceptions.TokenExpiredException) UserId(com.bakdata.conquery.models.identifiable.ids.specific.UserId) ConqueryAuthenticationInfo(com.bakdata.conquery.models.auth.ConqueryAuthenticationInfo) SignatureVerificationException(com.auth0.jwt.exceptions.SignatureVerificationException) DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT)

Aggregations

Algorithm (com.auth0.jwt.algorithms.Algorithm)64 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)60 IOException (java.io.IOException)51 Test (org.junit.Test)46 JWT (com.auth0.jwt.JWT)42 Instant (java.time.Instant)39 java.util (java.util)37 Duration (java.time.Duration)36 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)35 Maps (io.gravitee.common.util.Maps)34 DEFAULT_JWT_ISSUER (io.gravitee.rest.api.service.common.JWTHelper.DefaultValues.DEFAULT_JWT_ISSUER)34 User (io.gravitee.repository.management.model.User)33 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)32 UserRepository (io.gravitee.repository.management.api.UserRepository)30 io.gravitee.rest.api.model (io.gravitee.rest.api.model)30 JWTVerifier (com.auth0.jwt.JWTVerifier)28 MetadataPage (io.gravitee.common.data.domain.MetadataPage)28 MembershipRepository (io.gravitee.repository.management.api.MembershipRepository)28 Membership (io.gravitee.repository.management.model.Membership)28 UserStatus (io.gravitee.repository.management.model.UserStatus)28