Search in sources :

Example 1 with GroupMembership

use of io.gravitee.rest.api.management.rest.model.GroupMembership 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 2 with GroupMembership

use of io.gravitee.rest.api.management.rest.model.GroupMembership 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 3 with GroupMembership

use of io.gravitee.rest.api.management.rest.model.GroupMembership 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 4 with GroupMembership

use of io.gravitee.rest.api.management.rest.model.GroupMembership in project gravitee-management-rest-api by gravitee-io.

the class GroupMembersResourceTest method shouldUpdateNothing.

@Test
public void shouldUpdateNothing() {
    initUPDATEmock();
    GroupMembership groupMembership = new GroupMembership();
    groupMembership.setId(USERNAME);
    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, never()).addRoleToMemberOnReference(any(), any(), any());
}
Also used : Response(javax.ws.rs.core.Response) GroupMembership(io.gravitee.rest.api.management.rest.model.GroupMembership) Test(org.junit.Test)

Example 5 with GroupMembership

use of io.gravitee.rest.api.management.rest.model.GroupMembership 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)

Aggregations

GroupMembership (io.gravitee.rest.api.management.rest.model.GroupMembership)6 Response (javax.ws.rs.core.Response)6 MembershipService (io.gravitee.rest.api.service.MembershipService)5 Test (org.junit.Test)5 Page (io.gravitee.common.data.domain.Page)1 EventManager (io.gravitee.common.event.EventManager)1 MediaType (io.gravitee.common.http.MediaType)1 Pageable (io.gravitee.rest.api.management.rest.model.Pageable)1 PagedResult (io.gravitee.rest.api.management.rest.model.PagedResult)1 Permission (io.gravitee.rest.api.management.rest.security.Permission)1 Permissions (io.gravitee.rest.api.management.rest.security.Permissions)1 io.gravitee.rest.api.model (io.gravitee.rest.api.model)1 ApplicationAlertEventType (io.gravitee.rest.api.model.alert.ApplicationAlertEventType)1 ApplicationAlertMembershipEvent (io.gravitee.rest.api.model.alert.ApplicationAlertMembershipEvent)1 RolePermission (io.gravitee.rest.api.model.permissions.RolePermission)1 ENVIRONMENT_GROUP (io.gravitee.rest.api.model.permissions.RolePermission.ENVIRONMENT_GROUP)1 RolePermissionAction (io.gravitee.rest.api.model.permissions.RolePermissionAction)1 RoleScope (io.gravitee.rest.api.model.permissions.RoleScope)1 SystemRole (io.gravitee.rest.api.model.permissions.SystemRole)1 ApplicationService (io.gravitee.rest.api.service.ApplicationService)1