use of io.gravitee.rest.api.service.MembershipService in project gravitee-management-rest-api by gravitee-io.
the class GroupMembersResourceTest method shouldUpdateApiRole.
@Test
public void shouldUpdateApiRole() {
initUPDATEmock();
MemberRoleEntity apiRole = new MemberRoleEntity();
apiRole.setRoleScope(io.gravitee.rest.api.model.permissions.RoleScope.API);
apiRole.setRoleName("CUSTOM_API");
GroupMembership groupMembership = new GroupMembership();
groupMembership.setId(USERNAME);
groupMembership.setRoles(Collections.singletonList(apiRole));
final Response response = envTarget().request().post(Entity.json(Collections.singleton(groupMembership)));
assertEquals(HttpStatusCode.OK_200, response.getStatus());
verify(roleService, never()).findDefaultRoleByScopes(RoleScope.API);
verify(roleService, never()).findDefaultRoleByScopes(RoleScope.APPLICATION);
verify(membershipService, times(1)).addRoleToMemberOnReference(any(), any(), any());
verify(membershipService, times(1)).addRoleToMemberOnReference(new MembershipService.MembershipReference(MembershipReferenceType.GROUP, GROUP_ID), new MembershipService.MembershipMember(USERNAME, null, MembershipMemberType.USER), new MembershipService.MembershipRole(RoleScope.API, "CUSTOM_API"));
}
use of io.gravitee.rest.api.service.MembershipService in project gravitee-management-rest-api by gravitee-io.
the class GroupMembersResourceTest method shouldUpdateApplicationRole.
@Test
public void shouldUpdateApplicationRole() {
initUPDATEmock();
MemberRoleEntity appRole = new MemberRoleEntity();
appRole.setRoleScope(io.gravitee.rest.api.model.permissions.RoleScope.APPLICATION);
appRole.setRoleName("CUSTOM_APP");
GroupMembership groupMembership = new GroupMembership();
groupMembership.setId(USERNAME);
groupMembership.setRoles(Collections.singletonList(appRole));
final Response response = envTarget().request().post(Entity.json(Collections.singleton(groupMembership)));
assertEquals(HttpStatusCode.OK_200, response.getStatus());
verify(roleService, never()).findDefaultRoleByScopes(RoleScope.API);
verify(roleService, never()).findDefaultRoleByScopes(RoleScope.APPLICATION);
verify(membershipService, times(1)).addRoleToMemberOnReference(any(), any(), any());
verify(membershipService, times(1)).addRoleToMemberOnReference(new MembershipService.MembershipReference(MembershipReferenceType.GROUP, GROUP_ID), new MembershipService.MembershipMember(USERNAME, null, MembershipMemberType.USER), new MembershipService.MembershipRole(RoleScope.APPLICATION, "CUSTOM_APP"));
}
use of io.gravitee.rest.api.service.MembershipService in project gravitee-management-rest-api by gravitee-io.
the class GroupMembersResourceTest method shouldAddMemberWithCustomApplicationRoleAndCustomApiRole.
@Test
public void shouldAddMemberWithCustomApplicationRoleAndCustomApiRole() {
initADDmock();
MemberRoleEntity apiRole = new MemberRoleEntity();
apiRole.setRoleScope(io.gravitee.rest.api.model.permissions.RoleScope.API);
apiRole.setRoleName("CUSTOM_API");
MemberRoleEntity appRole = new MemberRoleEntity();
appRole.setRoleScope(io.gravitee.rest.api.model.permissions.RoleScope.APPLICATION);
appRole.setRoleName("CUSTOM_APP");
GroupMembership groupMembership = new GroupMembership();
groupMembership.setId(USERNAME);
groupMembership.setRoles(Arrays.asList(apiRole, appRole));
final Response response = envTarget().request().post(Entity.json(Collections.singleton(groupMembership)));
assertEquals(HttpStatusCode.OK_200, response.getStatus());
verify(roleService, never()).findDefaultRoleByScopes(RoleScope.API);
verify(roleService, never()).findDefaultRoleByScopes(RoleScope.APPLICATION);
verify(membershipService, times(1)).addRoleToMemberOnReference(new MembershipService.MembershipReference(MembershipReferenceType.GROUP, GROUP_ID), new MembershipService.MembershipMember(USERNAME, null, MembershipMemberType.USER), new MembershipService.MembershipRole(RoleScope.API, "CUSTOM_API"));
verify(membershipService, times(1)).addRoleToMemberOnReference(new MembershipService.MembershipReference(MembershipReferenceType.GROUP, GROUP_ID), new MembershipService.MembershipMember(USERNAME, null, MembershipMemberType.USER), new MembershipService.MembershipRole(RoleScope.APPLICATION, "CUSTOM_APP"));
}
use of io.gravitee.rest.api.service.MembershipService in project gravitee-management-rest-api by gravitee-io.
the class GroupMembersResourceTest method shouldUpdateApiAndApplicationRole.
@Test
public void shouldUpdateApiAndApplicationRole() {
initUPDATEmock();
MemberRoleEntity apiRole = new MemberRoleEntity();
apiRole.setRoleScope(io.gravitee.rest.api.model.permissions.RoleScope.API);
apiRole.setRoleName("CUSTOM_API");
MemberRoleEntity appRole = new MemberRoleEntity();
appRole.setRoleScope(io.gravitee.rest.api.model.permissions.RoleScope.APPLICATION);
appRole.setRoleName("CUSTOM_APP");
GroupMembership groupMembership = new GroupMembership();
groupMembership.setId(USERNAME);
groupMembership.setRoles(Arrays.asList(apiRole, appRole));
final Response response = envTarget().request().post(Entity.json(Collections.singleton(groupMembership)));
assertEquals(HttpStatusCode.OK_200, response.getStatus());
verify(roleService, never()).findDefaultRoleByScopes(RoleScope.API);
verify(roleService, never()).findDefaultRoleByScopes(RoleScope.APPLICATION);
verify(membershipService, times(1)).addRoleToMemberOnReference(new MembershipService.MembershipReference(MembershipReferenceType.GROUP, GROUP_ID), new MembershipService.MembershipMember(USERNAME, null, MembershipMemberType.USER), new MembershipService.MembershipRole(RoleScope.API, "CUSTOM_API"));
verify(membershipService, times(1)).addRoleToMemberOnReference(new MembershipService.MembershipReference(MembershipReferenceType.GROUP, GROUP_ID), new MembershipService.MembershipMember(USERNAME, null, MembershipMemberType.USER), new MembershipService.MembershipRole(RoleScope.APPLICATION, "CUSTOM_APP"));
}
use of io.gravitee.rest.api.service.MembershipService in project gravitee-management-rest-api by gravitee-io.
the class RoleUsersResourceTest method shouldAddRoleToUser.
@Test
public void shouldAddRoleToUser() {
reset(membershipService);
RoleMembership roleMembership = new RoleMembership();
roleMembership.setId(USER_NAME);
final Response response = envTarget(SCOPE).path("roles").path(ROLE).path("users").request().post(Entity.json(roleMembership));
assertEquals(HttpStatusCode.CREATED_201, response.getStatus());
assertNull(response.getHeaders().getFirst(HttpHeaders.LOCATION));
ArgumentCaptor<MembershipService.MembershipReference> memberShipRefCaptor = ArgumentCaptor.forClass(MembershipService.MembershipReference.class);
ArgumentCaptor<MembershipService.MembershipRole> memberShipRoleCaptor = ArgumentCaptor.forClass(MembershipService.MembershipRole.class);
ArgumentCaptor<MembershipService.MembershipMember> memberShipUserCaptor = ArgumentCaptor.forClass(MembershipService.MembershipMember.class);
Mockito.verify(membershipService).addRoleToMemberOnReference(memberShipRefCaptor.capture(), memberShipUserCaptor.capture(), memberShipRoleCaptor.capture());
assertEquals(GraviteeContext.getCurrentOrganization(), memberShipRefCaptor.getValue().getId());
assertEquals(MembershipReferenceType.ORGANIZATION, memberShipRefCaptor.getValue().getType());
assertEquals(ROLE, memberShipRoleCaptor.getValue().getName());
assertEquals(RoleScope.ORGANIZATION, memberShipRoleCaptor.getValue().getScope());
assertEquals(USER_NAME, memberShipUserCaptor.getValue().getMemberId());
}
Aggregations