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");
}
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());
});
}
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());
}
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));
});
}
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());
});
}
Aggregations