Search in sources :

Example 6 with MembershipService

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"));
}
Also used : Response(javax.ws.rs.core.Response) MembershipService(io.gravitee.rest.api.service.MembershipService) GroupMembership(io.gravitee.rest.api.management.rest.model.GroupMembership) Test(org.junit.Test)

Example 7 with MembershipService

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"));
}
Also used : Response(javax.ws.rs.core.Response) MembershipService(io.gravitee.rest.api.service.MembershipService) GroupMembership(io.gravitee.rest.api.management.rest.model.GroupMembership) Test(org.junit.Test)

Example 8 with MembershipService

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"));
}
Also used : Response(javax.ws.rs.core.Response) MembershipService(io.gravitee.rest.api.service.MembershipService) GroupMembership(io.gravitee.rest.api.management.rest.model.GroupMembership) Test(org.junit.Test)

Example 9 with MembershipService

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"));
}
Also used : Response(javax.ws.rs.core.Response) MembershipService(io.gravitee.rest.api.service.MembershipService) GroupMembership(io.gravitee.rest.api.management.rest.model.GroupMembership) Test(org.junit.Test)

Example 10 with MembershipService

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());
}
Also used : Response(javax.ws.rs.core.Response) MembershipService(io.gravitee.rest.api.service.MembershipService) RoleMembership(io.gravitee.rest.api.management.rest.model.RoleMembership) Test(org.junit.Test)

Aggregations

MembershipService (io.gravitee.rest.api.service.MembershipService)14 Test (org.junit.Test)14 Response (javax.ws.rs.core.Response)11 List (java.util.List)5 GroupMembership (io.gravitee.rest.api.management.rest.model.GroupMembership)4 RoleEntity (io.gravitee.rest.api.model.RoleEntity)4 MembershipCommand (io.gravitee.cockpit.api.command.membership.MembershipCommand)3 MembershipPayload (io.gravitee.cockpit.api.command.membership.MembershipPayload)3 MembershipReply (io.gravitee.cockpit.api.command.membership.MembershipReply)3 UserEntity (io.gravitee.rest.api.model.UserEntity)3 ApiMembership (io.gravitee.rest.api.management.rest.model.ApiMembership)1 ApplicationMembership (io.gravitee.rest.api.management.rest.model.ApplicationMembership)1 RoleMembership (io.gravitee.rest.api.management.rest.model.RoleMembership)1 MemberEntity (io.gravitee.rest.api.model.MemberEntity)1