Search in sources :

Example 6 with Group

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

the class SecurityServiceImplTest method testUpdateGroup.

@Test
public void testUpdateGroup() throws Exception {
    runAsAdmin(() -> {
        final CreateGroupParams createGroup = CreateGroupParams.create().groupKey(PrincipalKey.ofGroup(SYSTEM, "Group-a")).displayName("Group A").build();
        final Group group = securityService.createGroup(createGroup);
        refresh();
        final UpdateGroupParams groupUpdate = UpdateGroupParams.create(group).displayName("___Group B___").description("description").build();
        final Group updatedGroupResult = securityService.updateGroup(groupUpdate);
        refresh();
        final Group updatedGroup = securityService.getGroup(group.getKey()).get();
        assertEquals("___Group B___", updatedGroupResult.getDisplayName());
        assertEquals("___Group B___", updatedGroup.getDisplayName());
        assertEquals("description", updatedGroupResult.getDescription());
        assertEquals("description", updatedGroup.getDescription());
    });
}
Also used : Group(com.enonic.xp.security.Group) UpdateGroupParams(com.enonic.xp.security.UpdateGroupParams) CreateGroupParams(com.enonic.xp.security.CreateGroupParams) AbstractElasticsearchIntegrationTest(com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 7 with Group

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

the class ModifyGroupHandlerTest method invokeUpdate.

private Group invokeUpdate(final UpdateGroupParams params) {
    final GroupEditor editor = params.getEditor();
    assertNotNull(editor);
    final Group group = TestDataFixtures.getTestGroup();
    final EditableGroup editable = new EditableGroup(group);
    editor.edit(editable);
    return editable.build();
}
Also used : EditableGroup(com.enonic.xp.security.EditableGroup) Group(com.enonic.xp.security.Group) EditableGroup(com.enonic.xp.security.EditableGroup) GroupEditor(com.enonic.xp.security.GroupEditor)

Example 8 with Group

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

the class GetMembersHandlerTest method testGetMembers.

@Test
public void testGetMembers() {
    final Group group = TestDataFixtures.getTestGroup();
    final User user1 = TestDataFixtures.getTestUser();
    final User user2 = TestDataFixtures.getTestUser2();
    final PrincipalKeys principalKeys = PrincipalKeys.from(user1.getKey(), user2.getKey());
    final PrincipalRelationships relationships = PrincipalRelationships.from(PrincipalRelationship.from(group.getKey()).to(user1.getKey()), PrincipalRelationship.from(group.getKey()).to(user2.getKey()));
    Mockito.when(securityService.getRelationships(group.getKey())).thenReturn(relationships);
    Mockito.when(securityService.getPrincipals(principalKeys)).thenReturn(Principals.from(user1, user2));
    runFunction("/test/getMembers-test.js", "getMembers");
}
Also used : Group(com.enonic.xp.security.Group) User(com.enonic.xp.security.User) PrincipalKeys(com.enonic.xp.security.PrincipalKeys) PrincipalRelationships(com.enonic.xp.security.PrincipalRelationships) Test(org.junit.jupiter.api.Test)

Example 9 with Group

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

the class GetMembersHandlerTest method testExamples.

@Test
public void testExamples() {
    final Group group = TestDataFixtures.getTestGroup();
    final User user1 = TestDataFixtures.getTestUser();
    final User user2 = TestDataFixtures.getTestUser2();
    final PrincipalKeys principalKeys = PrincipalKeys.from(user1.getKey(), user2.getKey());
    final PrincipalRelationships relationships = PrincipalRelationships.from(PrincipalRelationship.from(group.getKey()).to(user1.getKey()), PrincipalRelationship.from(group.getKey()).to(user2.getKey()));
    Mockito.when(securityService.getRelationships(group.getKey())).thenReturn(relationships);
    Mockito.when(securityService.getPrincipals(principalKeys)).thenReturn(Principals.from(user1, user2));
    runScript("/lib/xp/examples/auth/getMembers.js");
}
Also used : Group(com.enonic.xp.security.Group) User(com.enonic.xp.security.User) PrincipalKeys(com.enonic.xp.security.PrincipalKeys) PrincipalRelationships(com.enonic.xp.security.PrincipalRelationships) Test(org.junit.jupiter.api.Test)

Example 10 with Group

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

the class GetMembershipsHandlerTest method testExamples.

@Test
public void testExamples() {
    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));
    runScript("/lib/xp/examples/auth/getMemberships.js");
}
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)

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