Search in sources :

Example 1 with Group

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

the class GetMembersHandlerTest method testGetNoMembers.

@Test
public void testGetNoMembers() {
    final Group group = TestDataFixtures.getTestGroup();
    final PrincipalRelationships relationships = PrincipalRelationships.empty();
    Mockito.when(securityService.getRelationships(group.getKey())).thenReturn(relationships);
    Mockito.when(securityService.getPrincipals(PrincipalKeys.empty())).thenReturn(Principals.empty());
    runFunction("/test/getMembers-test.js", "getNoMembers");
}
Also used : Group(com.enonic.xp.security.Group) PrincipalRelationships(com.enonic.xp.security.PrincipalRelationships) Test(org.junit.jupiter.api.Test)

Example 2 with Group

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

the class GetMembershipsHandlerTest method testGetTransitiveUserMemberships.

@Test
public void testGetTransitiveUserMemberships() {
    final Group group = TestDataFixtures.getTestGroup();
    final PrincipalKeys principalKeys = PrincipalKeys.from(group.getKey());
    final PrincipalKey pKey = PrincipalKey.from("user:myIdProvider:userId");
    Mockito.when(securityService.getAllMemberships(pKey)).thenReturn(principalKeys);
    Mockito.verify(securityService, Mockito.never()).getMemberships(pKey);
    Mockito.when(securityService.getPrincipals(principalKeys)).thenReturn(Principals.from(group));
    runFunction("/test/getMemberships-test.js", "getTransitiveUserMemberships");
}
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 3 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 4 with Group

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

the class SecurityServiceImpl method createGroup.

@Override
public Group createGroup(final CreateGroupParams createGroup) {
    final Group group = Group.create().key(createGroup.getKey()).displayName(createGroup.getDisplayName()).modifiedTime(Instant.now(clock)).description(createGroup.getDescription()).build();
    final CreateNodeParams createGroupParams = PrincipalNodeTranslator.toCreateNodeParams(group);
    try {
        final Node node = callWithContext(() -> {
            final Node createdNode = this.nodeService.create(createGroupParams);
            this.nodeService.refresh(RefreshMode.SEARCH);
            return createdNode;
        });
        return PrincipalNodeTranslator.groupFromNode(node);
    } catch (NodeIdExistsException | NodeAlreadyExistAtPathException e) {
        throw new PrincipalAlreadyExistsException(createGroup.getKey());
    }
}
Also used : Group(com.enonic.xp.security.Group) PrincipalAlreadyExistsException(com.enonic.xp.security.PrincipalAlreadyExistsException) NodeIdExistsException(com.enonic.xp.node.NodeIdExistsException) Node(com.enonic.xp.node.Node) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) CreateNodeParams(com.enonic.xp.node.CreateNodeParams)

Example 5 with Group

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

the class SecurityServiceImpl method updateGroup.

@Override
public Group updateGroup(final UpdateGroupParams updateGroupParams) {
    return callWithContext(() -> {
        final Node node = this.nodeService.getByPath(updateGroupParams.getKey().toPath());
        if (node == null) {
            throw new PrincipalNotFoundException(updateGroupParams.getKey());
        }
        final Group existingGroup = PrincipalNodeTranslator.groupFromNode(node);
        final Group groupToUpdate = updateGroupParams.update(existingGroup);
        final UpdateNodeParams updateNodeParams = PrincipalNodeTranslator.toUpdateNodeParams(groupToUpdate);
        final Node updatedNode = nodeService.update(updateNodeParams);
        this.nodeService.refresh(RefreshMode.SEARCH);
        return PrincipalNodeTranslator.groupFromNode(updatedNode);
    });
}
Also used : Group(com.enonic.xp.security.Group) Node(com.enonic.xp.node.Node) PrincipalNotFoundException(com.enonic.xp.security.PrincipalNotFoundException) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams)

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