use of com.enonic.xp.security.PrincipalKeys in project xp by enonic.
the class NodePermissionsResolver method doUserHasPermission.
private static boolean doUserHasPermission(final AuthenticationInfo authInfo, final Permission permission, final AccessControlList nodePermissions) {
if (authInfo.hasRole(RoleKeys.ADMIN)) {
return true;
}
final PrincipalKeys authInfoPrincipals = authInfo.getPrincipals();
final PrincipalKeys principalsAllowed = nodePermissions.getPrincipalsWithPermission(permission);
return principalsAllowed.stream().anyMatch(authInfoPrincipals::contains);
}
use of com.enonic.xp.security.PrincipalKeys in project xp by enonic.
the class BranchAclEntryTest method equals.
@Test
public void equals() throws Exception {
final Branch branch = Branch.from("fisk");
final PrincipalKeys keys = PrincipalKeys.from(PrincipalKey.ofRole("fisk"));
final BranchAclEntry entry1 = new BranchAclEntry(branch, keys);
final BranchAclEntry entry2 = new BranchAclEntry(branch, keys);
assertEquals(entry1, entry2);
}
use of com.enonic.xp.security.PrincipalKeys in project xp by enonic.
the class IdProviderNodeTranslator method idProviderPermissionsFromNode.
static IdProviderAccessControlList idProviderPermissionsFromNode(final Node idProviderNode, final Node usersNode, final Node groupsNode) {
final IdProviderAccessControlList.Builder acl = IdProviderAccessControlList.create();
final AccessControlList idProviderPermissions = idProviderNode.getPermissions();
final AccessControlList usersPermissions = usersNode.getPermissions();
final AccessControlList groupsPermissions = groupsNode.getPermissions();
final PrincipalKeys principals = PrincipalKeys.from(idProviderPermissions.getAllPrincipals(), usersPermissions.getAllPrincipals(), groupsPermissions.getAllPrincipals());
for (PrincipalKey principal : principals) {
if (idProviderPermissions.isAllowedFor(principal, READ, CREATE, MODIFY, DELETE, PUBLISH, READ_PERMISSIONS, WRITE_PERMISSIONS) && usersPermissions.isAllowedFor(principal, READ, CREATE, MODIFY, DELETE, PUBLISH, READ_PERMISSIONS, WRITE_PERMISSIONS) && groupsPermissions.isAllowedFor(principal, READ, CREATE, MODIFY, DELETE, PUBLISH, READ_PERMISSIONS, WRITE_PERMISSIONS)) {
final IdProviderAccessControlEntry access = IdProviderAccessControlEntry.create().principal(principal).access(ADMINISTRATOR).build();
acl.add(access);
} else if (usersPermissions.isAllowedFor(principal, READ, CREATE, MODIFY, DELETE) && groupsPermissions.isAllowedFor(principal, READ, CREATE, MODIFY, DELETE)) {
final IdProviderAccessControlEntry access = IdProviderAccessControlEntry.create().principal(principal).access(ID_PROVIDER_MANAGER).build();
acl.add(access);
} else if (usersPermissions.isAllowedFor(principal, READ, CREATE, MODIFY, DELETE)) {
final IdProviderAccessControlEntry access = IdProviderAccessControlEntry.create().principal(principal).access(WRITE_USERS).build();
acl.add(access);
} else if (usersPermissions.isAllowedFor(principal, CREATE)) {
final IdProviderAccessControlEntry access = IdProviderAccessControlEntry.create().principal(principal).access(CREATE_USERS).build();
acl.add(access);
} else if (usersPermissions.isAllowedFor(principal, READ)) {
final IdProviderAccessControlEntry access = IdProviderAccessControlEntry.create().principal(principal).access(IdProviderAccess.READ).build();
acl.add(access);
}
}
return acl.build();
}
use of com.enonic.xp.security.PrincipalKeys in project xp by enonic.
the class SecurityServiceImplTest method testGetUserMemberships.
@Test
public void testGetUserMemberships() 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();
securityService.createUser(createUser);
securityService.createGroup(createGroup1);
securityService.createGroup(createGroup2);
securityService.addRelationship(PrincipalRelationship.from(groupKey1).to(userKey));
securityService.addRelationship(PrincipalRelationship.from(groupKey2).to(userKey));
refresh();
final PrincipalKeys memberships = securityService.getMemberships(userKey);
assertTrue(memberships.contains(groupKey1));
assertTrue(memberships.contains(groupKey2));
assertEquals(2, memberships.getSize());
});
}
use of com.enonic.xp.security.PrincipalKeys in project xp by enonic.
the class SecurityServiceImpl method doRemoveMemberships.
private void doRemoveMemberships(final PrincipalKey member) {
final PrincipalKeys memberships = queryDirectMemberships(member);
if (memberships.isEmpty()) {
return;
}
for (PrincipalKey from : memberships) {
final PrincipalRelationship relationship = PrincipalRelationship.from(from).to(member);
final UpdateNodeParams updateNodeParams = PrincipalNodeTranslator.removeRelationshipToUpdateNodeParams(relationship);
nodeService.update(updateNodeParams);
}
}
Aggregations