Search in sources :

Example 11 with Group

use of com.enonic.xp.security.Group in project xp by enonic.

the class GetMembershipsHandlerTest method testGetUserMembershipsWithRoleAndGroup.

@Test
public void testGetUserMembershipsWithRoleAndGroup() {
    final Role role = TestDataFixtures.getTestRole();
    final Group group = TestDataFixtures.getTestGroup();
    final PrincipalKeys principalKeys = PrincipalKeys.from(role.getKey(), group.getKey());
    Mockito.when(securityService.getMemberships(PrincipalKey.from("user:myIdProvider:userId"))).thenReturn(principalKeys);
    Mockito.when(securityService.getPrincipals(principalKeys)).thenReturn(Principals.from(role, group));
    runFunction("/test/getMemberships-test.js", "getUserMembershipsWithRoleAndGroup");
}
Also used : Role(com.enonic.xp.security.Role) Group(com.enonic.xp.security.Group) PrincipalKeys(com.enonic.xp.security.PrincipalKeys) Test(org.junit.jupiter.api.Test)

Example 12 with Group

use of com.enonic.xp.security.Group in project xp by enonic.

the class GetMembershipsHandlerTest method testGetUserMemberships.

@Test
public void testGetUserMemberships() {
    final Group group = TestDataFixtures.getTestGroup();
    final PrincipalKeys principalKeys = PrincipalKeys.from(group.getKey());
    final PrincipalKey pKey = PrincipalKey.from("user:myIdProvider:userId");
    Mockito.when(securityService.getMemberships(pKey)).thenReturn(principalKeys);
    Mockito.verify(securityService, Mockito.never()).getAllMemberships(pKey);
    Mockito.when(securityService.getPrincipals(principalKeys)).thenReturn(Principals.from(group));
    runFunction("/test/getMemberships-test.js", "getUserMemberships");
}
Also used : Group(com.enonic.xp.security.Group) PrincipalKeys(com.enonic.xp.security.PrincipalKeys) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test)

Example 13 with Group

use of com.enonic.xp.security.Group in project xp by enonic.

the class SecurityServiceImplTest method testCreateGroup.

@Test
public void testCreateGroup() throws Exception {
    runAsAdmin(() -> {
        final PrincipalKey groupKey1 = PrincipalKey.ofGroup(SYSTEM, "Group-a");
        final CreateGroupParams createGroup = CreateGroupParams.create().groupKey(groupKey1).displayName("Group A").description("Group A Description").build();
        final PrincipalKey groupKey2 = PrincipalKey.ofGroup(SYSTEM, "group-b");
        final CreateGroupParams createGroup2 = CreateGroupParams.create().groupKey(groupKey2).displayName("Group B").build();
        final Group group1 = securityService.createGroup(createGroup);
        final Group group2 = securityService.createGroup(createGroup2);
        refresh();
        final Group createdGroup1 = securityService.getGroup(groupKey1).get();
        final Group createdGroup2 = securityService.getGroup(groupKey2).get();
        assertEquals("Group A", group1.getDisplayName());
        assertEquals("Group A", createdGroup1.getDisplayName());
        assertEquals("Group A Description", group1.getDescription());
        assertEquals("Group A Description", createdGroup1.getDescription());
        assertEquals("Group B", group2.getDisplayName());
        assertEquals("Group B", createdGroup2.getDisplayName());
        assertNull(group2.getDescription());
        assertNull(createdGroup2.getDescription());
    });
}
Also used : Group(com.enonic.xp.security.Group) CreateGroupParams(com.enonic.xp.security.CreateGroupParams) PrincipalKey(com.enonic.xp.security.PrincipalKey) AbstractElasticsearchIntegrationTest(com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 14 with Group

use of com.enonic.xp.security.Group in project xp by enonic.

the class GroupNodeTranslatorTest method toCreateNode.

@Test
public void toCreateNode() throws Exception {
    final Group group = Group.create().displayName("My Group").key(PrincipalKey.ofGroup(IdProviderKey.system(), "group-a")).modifiedTime(Instant.now(clock)).description("my group a").build();
    final CreateNodeParams createNodeParams = PrincipalNodeTranslator.toCreateNodeParams(group);
    assertEquals("group-a", createNodeParams.getName());
    final PropertyTree rootDataSet = createNodeParams.getData();
    assertNotNull(rootDataSet);
    assertEquals(4, rootDataSet.getTotalSize());
    assertEquals(IdProviderKey.system().toString(), rootDataSet.getString(PrincipalPropertyNames.ID_PROVIDER_KEY));
    assertEquals(PrincipalType.GROUP.toString(), rootDataSet.getString(PrincipalPropertyNames.PRINCIPAL_TYPE_KEY));
    assertEquals("My Group", rootDataSet.getString(PrincipalPropertyNames.DISPLAY_NAME_KEY));
    assertEquals("my group a", rootDataSet.getString(PrincipalPropertyNames.DESCRIPTION_KEY));
}
Also used : Group(com.enonic.xp.security.Group) PropertyTree(com.enonic.xp.data.PropertyTree) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Test(org.junit.jupiter.api.Test)

Aggregations

Group (com.enonic.xp.security.Group)14 Test (org.junit.jupiter.api.Test)11 PrincipalKeys (com.enonic.xp.security.PrincipalKeys)6 PrincipalKey (com.enonic.xp.security.PrincipalKey)4 Node (com.enonic.xp.node.Node)3 PrincipalRelationships (com.enonic.xp.security.PrincipalRelationships)3 PropertyTree (com.enonic.xp.data.PropertyTree)2 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)2 AbstractElasticsearchIntegrationTest (com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest)2 CreateGroupParams (com.enonic.xp.security.CreateGroupParams)2 Role (com.enonic.xp.security.Role)2 User (com.enonic.xp.security.User)2 NodeAlreadyExistAtPathException (com.enonic.xp.node.NodeAlreadyExistAtPathException)1 NodeIdExistsException (com.enonic.xp.node.NodeIdExistsException)1 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)1 EditableGroup (com.enonic.xp.security.EditableGroup)1 GroupEditor (com.enonic.xp.security.GroupEditor)1 PrincipalAlreadyExistsException (com.enonic.xp.security.PrincipalAlreadyExistsException)1 PrincipalNotFoundException (com.enonic.xp.security.PrincipalNotFoundException)1 UpdateGroupParams (com.enonic.xp.security.UpdateGroupParams)1