Search in sources :

Example 1 with PrincipalRelationships

use of com.enonic.xp.security.PrincipalRelationships 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 PrincipalRelationships

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

the class ProjectServiceImplTest method modify_permissions.

@Test
void modify_permissions() {
    final RepositoryId projectRepoId = RepositoryId.from("com.enonic.cms.test-project");
    adminContext().runWith(() -> {
        final User user1 = securityService.createUser(CreateUserParams.create().userKey(PrincipalKey.ofUser(IdProviderKey.system(), "user1")).displayName("user1").login("user1").build());
        final User user2 = securityService.createUser(CreateUserParams.create().userKey(PrincipalKey.ofUser(IdProviderKey.system(), "user2")).displayName("user2").login("user2").build());
        doCreateProjectAsAdmin(ProjectName.from(projectRepoId), ProjectPermissions.create().addOwner(user1.getKey()).build());
        projectService.modifyPermissions(ProjectName.from("test-project"), ProjectPermissions.create().addOwner(user2.getKey()).build());
        final PrincipalRelationships principalRelationships = securityService.getRelationships(PrincipalKey.ofRole("cms.project.test-project.owner"));
        assertEquals(1, principalRelationships.getSize());
        assertEquals(principalRelationships.get(0).getTo(), user2.getKey());
    });
}
Also used : User(com.enonic.xp.security.User) RepositoryId(com.enonic.xp.repository.RepositoryId) PrincipalRelationships(com.enonic.xp.security.PrincipalRelationships) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 3 with PrincipalRelationships

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

the class UpdateProjectRolesCommand method doSetRoleMembers.

private Set<PrincipalKey> doSetRoleMembers(final ProjectRole projectRole) {
    final PrincipalKey roleKey = ProjectAccessHelper.createRoleKey(projectName, projectRole);
    final PrincipalRelationships currRoleMembers = securityService.getRelationships(roleKey);
    final PrincipalKeys newRoleMembers = this.permissions.getPermission(projectRole);
    doGetAddedMembers(currRoleMembers, newRoleMembers, roleKey).forEach(securityService::addRelationship);
    doGetRemovedMembers(currRoleMembers, newRoleMembers).forEach(securityService::removeRelationship);
    return securityService.getRelationships(roleKey).stream().map(PrincipalRelationship::getTo).collect(Collectors.toSet());
}
Also used : PrincipalKeys(com.enonic.xp.security.PrincipalKeys) PrincipalKey(com.enonic.xp.security.PrincipalKey) PrincipalRelationships(com.enonic.xp.security.PrincipalRelationships)

Example 4 with PrincipalRelationships

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

the class SecurityServiceImplTest method testRemoveRelationship.

@Test
public void testRemoveRelationship() throws Exception {
    runAsAdmin(() -> {
        // set up
        final PrincipalKey userKey1 = PrincipalKey.ofUser(SYSTEM, "User1");
        final CreateUserParams createUser1 = CreateUserParams.create().userKey(userKey1).displayName("User 1").email("user1@enonic.com").login("User1").password("123456").build();
        final PrincipalKey userKey2 = PrincipalKey.ofUser(SYSTEM, "user2");
        final CreateUserParams createUser2 = CreateUserParams.create().userKey(userKey2).displayName("User 2").email("user2@enonic.com").login("user2").build();
        final PrincipalKey groupKey1 = PrincipalKey.ofGroup(SYSTEM, "Group-a");
        final CreateGroupParams createGroup = CreateGroupParams.create().groupKey(groupKey1).displayName("Group A").build();
        securityService.createUser(createUser1);
        securityService.createUser(createUser2);
        securityService.createGroup(createGroup);
        refresh();
        PrincipalRelationship membership = PrincipalRelationship.from(groupKey1).to(userKey1);
        PrincipalRelationship membership2 = PrincipalRelationship.from(groupKey1).to(userKey2);
        securityService.addRelationship(membership);
        securityService.addRelationship(membership2);
        refresh();
        // exercise
        securityService.removeRelationship(membership);
        refresh();
        // verify
        final PrincipalRelationships relationships = securityService.getRelationships(groupKey1);
        assertEquals(1, relationships.getSize());
        assertEquals(membership2, relationships.get(0));
    });
}
Also used : CreateUserParams(com.enonic.xp.security.CreateUserParams) CreateGroupParams(com.enonic.xp.security.CreateGroupParams) PrincipalRelationship(com.enonic.xp.security.PrincipalRelationship) PrincipalKey(com.enonic.xp.security.PrincipalKey) PrincipalRelationships(com.enonic.xp.security.PrincipalRelationships) AbstractElasticsearchIntegrationTest(com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 5 with PrincipalRelationships

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

the class SecurityServiceImplTest method testRemoveAllRelationships.

@Test
public void testRemoveAllRelationships() throws Exception {
    runAsAdmin(() -> {
        // set up
        final PrincipalKey userKey1 = PrincipalKey.ofUser(SYSTEM, "User1");
        final CreateUserParams createUser1 = CreateUserParams.create().userKey(userKey1).displayName("User 1").email("user1@enonic.com").login("User1").password("123456").build();
        final PrincipalKey userKey2 = PrincipalKey.ofUser(SYSTEM, "user2");
        final CreateUserParams createUser2 = CreateUserParams.create().userKey(userKey2).displayName("User 2").email("user2@enonic.com").login("user2").build();
        final PrincipalKey groupKey1 = PrincipalKey.ofGroup(SYSTEM, "Group-a");
        final CreateGroupParams createGroup = CreateGroupParams.create().groupKey(groupKey1).displayName("Group A").build();
        securityService.createUser(createUser1);
        securityService.createUser(createUser2);
        securityService.createGroup(createGroup);
        refresh();
        PrincipalRelationship membership = PrincipalRelationship.from(groupKey1).to(userKey1);
        PrincipalRelationship membership2 = PrincipalRelationship.from(groupKey1).to(userKey2);
        securityService.addRelationship(membership);
        securityService.addRelationship(membership2);
        refresh();
        // exercise
        securityService.removeRelationships(groupKey1);
        refresh();
        // verify
        final PrincipalRelationships relationships = securityService.getRelationships(groupKey1);
        assertEquals(0, relationships.getSize());
    });
}
Also used : CreateUserParams(com.enonic.xp.security.CreateUserParams) CreateGroupParams(com.enonic.xp.security.CreateGroupParams) PrincipalRelationship(com.enonic.xp.security.PrincipalRelationship) PrincipalKey(com.enonic.xp.security.PrincipalKey) PrincipalRelationships(com.enonic.xp.security.PrincipalRelationships) AbstractElasticsearchIntegrationTest(com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

PrincipalRelationships (com.enonic.xp.security.PrincipalRelationships)9 Test (org.junit.jupiter.api.Test)7 PrincipalKey (com.enonic.xp.security.PrincipalKey)5 PrincipalKeys (com.enonic.xp.security.PrincipalKeys)4 PrincipalRelationship (com.enonic.xp.security.PrincipalRelationship)4 AbstractElasticsearchIntegrationTest (com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest)3 CreateGroupParams (com.enonic.xp.security.CreateGroupParams)3 CreateUserParams (com.enonic.xp.security.CreateUserParams)3 Group (com.enonic.xp.security.Group)3 User (com.enonic.xp.security.User)3 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)1 RepositoryId (com.enonic.xp.repository.RepositoryId)1 Principals (com.enonic.xp.security.Principals)1