use of com.enonic.xp.security.PrincipalKeys in project xp by enonic.
the class SecurityServiceImpl method resolveMemberships.
private PrincipalKeys resolveMemberships(final PrincipalKey userKey) {
final PrincipalKeys directMemberships = queryDirectMemberships(userKey);
final Set<PrincipalKey> resolvedMemberships = new LinkedHashSet<>(directMemberships.getSet());
final Set<PrincipalKey> queriedMemberships = new LinkedHashSet<>();
do {
final Set<PrincipalKey> newMemberships = new LinkedHashSet<>();
resolvedMemberships.stream().filter(principal -> !queriedMemberships.contains(principal)).forEach(principal -> {
final PrincipalKeys indirectMemberships = queryDirectMemberships(principal);
newMemberships.addAll(indirectMemberships.getSet());
queriedMemberships.add(principal);
});
resolvedMemberships.addAll(newMemberships);
} while (resolvedMemberships.size() > queriedMemberships.size());
return PrincipalKeys.from(resolvedMemberships);
}
use of com.enonic.xp.security.PrincipalKeys 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.PrincipalKeys in project xp by enonic.
the class SecurityServiceImplTest method testGetAllMemberships.
@Test
public void testGetAllMemberships() throws Exception {
runAsAdmin(() -> {
final PrincipalKey userKey = PrincipalKey.ofUser(SYSTEM, "user1");
final CreateUserParams createUser = CreateUserParams.create().userKey(userKey).displayName("User 1").email("user1@enonic.com").login("user1").password("123456").build();
final PrincipalKey groupKey1 = PrincipalKey.ofGroup(SYSTEM, "group-a");
final CreateGroupParams createGroup1 = CreateGroupParams.create().groupKey(groupKey1).displayName("Group A").build();
final PrincipalKey groupKey2 = PrincipalKey.ofGroup(SYSTEM, "group-b");
final CreateGroupParams createGroup2 = CreateGroupParams.create().groupKey(groupKey2).displayName("Group B").build();
final PrincipalKey roleKey1 = PrincipalKey.ofRole("role-a");
final CreateRoleParams createRole = CreateRoleParams.create().roleKey(roleKey1).displayName("Role A").description("Group A Description").build();
securityService.createUser(createUser);
securityService.createGroup(createGroup1);
securityService.createGroup(createGroup2);
securityService.createRole(createRole);
securityService.addRelationship(PrincipalRelationship.from(groupKey1).to(userKey));
securityService.addRelationship(PrincipalRelationship.from(groupKey2).to(groupKey1));
securityService.addRelationship(PrincipalRelationship.from(roleKey1).to(groupKey2));
refresh();
final PrincipalKeys memberships = securityService.getAllMemberships(userKey);
assertTrue(memberships.contains(groupKey1));
assertTrue(memberships.contains(groupKey2));
assertTrue(memberships.contains(roleKey1));
assertEquals(3, memberships.getSize());
});
}
use of com.enonic.xp.security.PrincipalKeys in project xp by enonic.
the class AdminToolDescriptorServiceImplTest method getAllowedAdminToolDescriptors.
@Test
public void getAllowedAdminToolDescriptors() throws Exception {
final PrincipalKeys principalKeys = PrincipalKeys.from(PrincipalKey.from("role:system.user.admin"));
AdminToolDescriptors result = this.service.getAllowedAdminToolDescriptors(principalKeys);
assertNotNull(result);
assertEquals(1, result.getSize());
result = this.service.getAllowedAdminToolDescriptors(PrincipalKeys.empty());
assertNotNull(result);
assertEquals(0, result.getSize());
}
use of com.enonic.xp.security.PrincipalKeys in project xp by enonic.
the class XmlServiceDescriptorParserTest method assertResult.
private void assertResult() throws Exception {
final ServiceDescriptor result = this.builder.build();
assertEquals("myapplication:myservice", result.getKey().toString());
final PrincipalKeys allowedPrincipals = result.getAllowedPrincipals();
assertNotNull(allowedPrincipals);
assertEquals(1, allowedPrincipals.getSize());
assertTrue(allowedPrincipals.first().equals(PrincipalKey.from("role:system.admin")));
}
Aggregations