use of io.gravitee.am.gateway.handler.common.vertx.web.auth.provider.OAuth2AuthProvider in project gravitee-access-management by gravitee-io.
the class UserInfoEndpointHandlerTest method shouldInvokeUserEndpoint_scopesRequest_roles_groups_full_profile.
@Test
public void shouldInvokeUserEndpoint_scopesRequest_roles_groups_full_profile() throws Exception {
JWT jwt = new JWT();
jwt.setJti("id-token");
jwt.setAud("client-id");
jwt.setSub("id-subject");
jwt.setScope("openid full_profile roles groups");
Client client = new Client();
client.setId("client-id");
client.setClientId("client-id");
Role role1 = new Role();
role1.setId("role1");
role1.setName("role-1");
Role role2 = new Role();
role2.setId("role2");
role2.setName("role-2");
router.route().order(-1).handler(createOAuth2AuthHandler(oAuth2AuthProvider(jwt, client)));
User user = createUser();
user.setRolesPermissions(new HashSet<>(Arrays.asList(role1, role2)));
user.setGroups(Arrays.asList("group-1", "group-2"));
when(userService.findById(anyString())).thenReturn(Maybe.just(user));
when(userService.enhance(user)).thenReturn(Single.just(user));
testRequest(HttpMethod.GET, "/userinfo", req -> req.putHeader(HttpHeaders.AUTHORIZATION, "Bearer test-token"), resp -> resp.bodyHandler(body -> {
final Map<String, Object> claims = Json.decodeValue(body.toString(), Map.class);
assertNotNull(claims);
assertEquals(23, claims.size());
assertTrue(claims.containsKey(CustomClaims.ROLES));
assertTrue(((List) claims.get(CustomClaims.ROLES)).containsAll(Arrays.asList("role-1", "role-2")));
assertTrue(claims.containsKey(CustomClaims.GROUPS));
assertTrue(((List) claims.get(CustomClaims.GROUPS)).containsAll(Arrays.asList("group-1", "group-2")));
assertTrue(claims.containsKey("custom-claim"));
assertTrue("gravitee".equals(claims.get("custom-claim")));
assertTrue("user-id".equals(claims.get("sub")));
}), HttpStatusCode.OK_200, "OK", null);
}
use of io.gravitee.am.gateway.handler.common.vertx.web.auth.provider.OAuth2AuthProvider in project gravitee-access-management by gravitee-io.
the class UserInfoEndpointHandlerTest method shouldInvokeUserEndpoint_scopesRequest_email.
@Test
public void shouldInvokeUserEndpoint_scopesRequest_email() throws Exception {
JWT jwt = new JWT();
jwt.setJti("id-token");
jwt.setAud("client-id");
jwt.setSub("id-subject");
jwt.setScope("openid email");
Client client = new Client();
client.setId("client-id");
client.setClientId("client-id");
router.route().order(-1).handler(createOAuth2AuthHandler(oAuth2AuthProvider(jwt, client)));
User user = createUser();
when(userService.findById(anyString())).thenReturn(Maybe.just(user));
testRequest(HttpMethod.GET, "/userinfo", req -> req.putHeader(HttpHeaders.AUTHORIZATION, "Bearer test-token"), resp -> resp.bodyHandler(body -> {
final Map<String, Object> claims = Json.decodeValue(body.toString(), Map.class);
assertNotNull(claims);
assertEquals(3, claims.size());
assertTrue(claims.containsKey(StandardClaims.EMAIL));
assertTrue(claims.containsKey(StandardClaims.EMAIL_VERIFIED));
}), HttpStatusCode.OK_200, "OK", null);
}
use of io.gravitee.am.gateway.handler.common.vertx.web.auth.provider.OAuth2AuthProvider in project gravitee-access-management by gravitee-io.
the class UserInfoEndpointHandlerTest method shouldInvokeUserEndpoint_scopesRequest.
@Test
public void shouldInvokeUserEndpoint_scopesRequest() throws Exception {
JWT jwt = new JWT();
jwt.setJti("id-token");
jwt.setAud("client-id");
jwt.setSub("id-subject");
jwt.setScope("openid profile");
Client client = new Client();
client.setId("client-id");
client.setClientId("client-id");
router.route().order(-1).handler(createOAuth2AuthHandler(oAuth2AuthProvider(jwt, client)));
User user = createUser();
when(userService.findById(anyString())).thenReturn(Maybe.just(user));
testRequest(HttpMethod.GET, "/userinfo", req -> req.putHeader(HttpHeaders.AUTHORIZATION, "Bearer test-token"), resp -> resp.bodyHandler(body -> {
final Map<String, Object> claims = Json.decodeValue(body.toString(), Map.class);
assertNotNull(claims);
assertEquals(15, claims.size());
}), HttpStatusCode.OK_200, "OK", null);
}
use of io.gravitee.am.gateway.handler.common.vertx.web.auth.provider.OAuth2AuthProvider in project gravitee-access-management by gravitee-io.
the class UserInfoEndpointHandlerTest method shouldInvokeUserEndpoint_scopesRequest_groups.
@Test
public void shouldInvokeUserEndpoint_scopesRequest_groups() throws Exception {
JWT jwt = new JWT();
jwt.setJti("id-token");
jwt.setAud("client-id");
jwt.setSub("id-subject");
jwt.setScope("openid groups");
Client client = new Client();
client.setId("client-id");
client.setClientId("client-id");
router.route().order(-1).handler(createOAuth2AuthHandler(oAuth2AuthProvider(jwt, client)));
User user = createUser();
user.setGroups(Arrays.asList("group-1", "group-2"));
when(userService.findById(anyString())).thenReturn(Maybe.just(user));
when(userService.enhance(user)).thenReturn(Single.just(user));
testRequest(HttpMethod.GET, "/userinfo", req -> req.putHeader(HttpHeaders.AUTHORIZATION, "Bearer test-token"), resp -> resp.bodyHandler(body -> {
final Map<String, Object> claims = Json.decodeValue(body.toString(), Map.class);
assertNotNull(claims);
assertEquals(2, claims.size());
assertTrue(claims.containsKey(CustomClaims.GROUPS));
assertTrue(((List) claims.get(CustomClaims.GROUPS)).containsAll(Arrays.asList("group-1", "group-2")));
}), HttpStatusCode.OK_200, "OK", null);
}
use of io.gravitee.am.gateway.handler.common.vertx.web.auth.provider.OAuth2AuthProvider in project gravitee-access-management by gravitee-io.
the class UserInfoEndpointHandlerTest method shouldInvokeUserEndpoint_scopesRequest_roles_noRole.
@Test
public void shouldInvokeUserEndpoint_scopesRequest_roles_noRole() throws Exception {
JWT jwt = new JWT();
jwt.setJti("id-token");
jwt.setAud("client-id");
jwt.setSub("id-subject");
jwt.setScope("openid roles");
Client client = new Client();
client.setId("client-id");
client.setClientId("client-id");
router.route().order(-1).handler(createOAuth2AuthHandler(oAuth2AuthProvider(jwt, client)));
User user = createUser();
when(userService.findById(anyString())).thenReturn(Maybe.just(user));
when(userService.enhance(user)).thenReturn(Single.just(user));
testRequest(HttpMethod.GET, "/userinfo", req -> req.putHeader(HttpHeaders.AUTHORIZATION, "Bearer test-token"), resp -> resp.bodyHandler(body -> {
final Map<String, Object> claims = Json.decodeValue(body.toString(), Map.class);
assertNotNull(claims);
assertEquals(1, claims.size());
assertTrue(!claims.containsKey(CustomClaims.ROLES));
}), HttpStatusCode.OK_200, "OK", null);
}
Aggregations