use of com.auth0.json.mgmt.Role in project auth0-java by auth0.
the class RolesEntityTest method shouldThrowOnUpdateRoleWithNullId.
@Test
public void shouldThrowOnUpdateRoleWithNullId() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("'role id' cannot be null!");
api.roles().update(null, new Role());
}
use of com.auth0.json.mgmt.Role in project auth0-java by auth0.
the class RolesEntityTest method shouldUpdateRole.
@Test
public void shouldUpdateRole() throws Exception {
Role updatedRole = new Role();
updatedRole.setName("roleId");
Request<Role> request = api.roles().update("1", updatedRole);
assertThat(request, is(notNullValue()));
server.jsonResponse(MGMT_ROLE, 200);
Role response = request.execute();
RecordedRequest recordedRequest = server.takeRequest();
assertThat(recordedRequest, hasMethodAndPath("PATCH", "/api/v2/roles/1"));
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("name", "roleId"));
assertThat(response, is(notNullValue()));
}
use of com.auth0.json.mgmt.Role in project tutorials by csh0034.
the class JwtUtils method decode.
public TokenUser decode(String token) {
jwtVerifier.verify(token);
DecodedJWT jwt = JWT.decode(token);
String id = jwt.getSubject();
String role = jwt.getClaim(ROLE_CLAIM_KEY).asString();
return new TokenUser(id, role);
}
use of com.auth0.json.mgmt.Role in project toy by gmoon92.
the class JwtUtils method decode.
public User decode(String tokenOfIncludeSchema) {
String token = obtainTokenWithoutSchema(tokenOfIncludeSchema);
verify(token);
DecodedJWT jwt = JWT.decode(token);
String username = jwt.getClaim("username").asString();
Role role = Role.valueOf(jwt.getClaim("role").asString());
return User.create(username, "", role);
}
use of com.auth0.json.mgmt.Role in project toy by gmoon92.
the class JwtUtils method generate.
public String generate(User user) {
try {
ZonedDateTime today = ZonedDateTime.now();
String token = JWT.create().withIssuer(apiVersion).withClaim("username", user.getUsername()).withClaim("role", user.getRole().name()).withIssuedAt(Date.from(today.toInstant())).withExpiresAt(Date.from(today.plusDays(DAY_OF_EXPIRATION).toInstant())).sign(algorithm);
return String.format("%s %s", AuthenticationSchema.BEARER.getName(), token);
} catch (JWTCreationException e) {
throw new JWTCreationException("Invalid Signing configuration or Couldn't convert Claims.", e);
}
}
Aggregations