Search in sources :

Example 1 with IndexItem

use of com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexItem in project xp by enonic.

the class AccessControlListStoreDocumentFactory method create.

static List<IndexItem> create(final AccessControlList accessControlList) {
    final List<IndexItem> aclStoreDocumentItems = new ArrayList<>();
    for (final AccessControlEntry entry : accessControlList) {
        final Iterable<Permission> allowedPermissions = entry.getAllowedPermissions();
        final PrincipalKey principalKey = entry.getPrincipal();
        for (final Permission permission : allowedPermissions) {
            aclStoreDocumentItems.add(new IndexItemString(getPathForPermission(permission), principalKey.toString()));
        }
    }
    return aclStoreDocumentItems;
}
Also used : IndexItemString(com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexItemString) ArrayList(java.util.ArrayList) Permission(com.enonic.xp.security.acl.Permission) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) PrincipalKey(com.enonic.xp.security.PrincipalKey) IndexItem(com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexItem)

Example 2 with IndexItem

use of com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexItem in project xp by enonic.

the class AccessControlListIndexDocumentFactoryTest method single_user.

@Test
public void single_user() throws Exception {
    final AccessControlList acl = AccessControlList.create().add(AccessControlEntry.create().allow(Permission.READ).principal(PrincipalKey.from("user:myidprovider:rmy")).build()).build();
    final List<IndexItem> aclStoreDocumentItems = AccessControlListStoreDocumentFactory.create(acl);
    assertEquals(1, aclStoreDocumentItems.size());
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) IndexItem(com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexItem) Test(org.junit.jupiter.api.Test)

Example 3 with IndexItem

use of com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexItem in project xp by enonic.

the class AccessControlListIndexDocumentFactoryTest method multiple_user.

@Test
public void multiple_user() throws Exception {
    final AccessControlList acl = AccessControlList.create().add(AccessControlEntry.create().allow(Permission.READ).principal(PrincipalKey.from("user:myidprovider:rmy")).build()).add(AccessControlEntry.create().allow(Permission.READ).principal(PrincipalKey.from("user:myidprovider:tsi")).build()).add(AccessControlEntry.create().allow(Permission.READ).allow(Permission.DELETE).principal(PrincipalKey.from("user:myidprovider:aro")).build()).add(AccessControlEntry.create().allow(Permission.DELETE).principal(PrincipalKey.from("user:myidprovider:srs")).build()).build();
    final List<IndexItem> aclStoreDocumentItems = AccessControlListStoreDocumentFactory.create(acl);
    assertEquals(5, aclStoreDocumentItems.size());
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) IndexItem(com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexItem) Test(org.junit.jupiter.api.Test)

Example 4 with IndexItem

use of com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexItem in project xp by enonic.

the class AccessControlListIndexDocumentFactoryTest method single_user_all_permissions.

@Test
public void single_user_all_permissions() throws Exception {
    final AccessControlList acl = AccessControlList.create().add(AccessControlEntry.create().allow(Permission.READ).allow(Permission.PUBLISH).allow(Permission.WRITE_PERMISSIONS).allow(Permission.READ_PERMISSIONS).allow(Permission.MODIFY).allow(Permission.CREATE).allow(Permission.DELETE).principal(PrincipalKey.from("user:myidprovider:rmy")).build()).build();
    final List<IndexItem> aclStoreDocumentItems = AccessControlListStoreDocumentFactory.create(acl);
    assertEquals(7, aclStoreDocumentItems.size());
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) IndexItem(com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexItem) Test(org.junit.jupiter.api.Test)

Aggregations

IndexItem (com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexItem)4 AccessControlList (com.enonic.xp.security.acl.AccessControlList)3 Test (org.junit.jupiter.api.Test)3 IndexItemString (com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexItemString)1 PrincipalKey (com.enonic.xp.security.PrincipalKey)1 AccessControlEntry (com.enonic.xp.security.acl.AccessControlEntry)1 Permission (com.enonic.xp.security.acl.Permission)1 ArrayList (java.util.ArrayList)1