Search in sources :

Example 6 with AccessControlEntry

use of com.enonic.xp.security.acl.AccessControlEntry in project xp by enonic.

the class XmlPermissionsParserTest method testParse.

@Test
public void testParse() throws Exception {
    final Document doc;
    try (Reader reader = new InputStreamReader(getClass().getResourceAsStream("permissions.xml"))) {
        doc = DomHelper.parse(reader);
    }
    final AccessControlList accessControlList = XmlPermissionsParser.parse(DomElement.from(doc.getDocumentElement()));
    final AccessControlEntry entry = accessControlList.getEntry(PrincipalKey.from("role:system.admin"));
    assertNotNull(entry);
    assertTrue(entry.isAllowed(Permission.READ));
    assertTrue(entry.isAllowed(Permission.CREATE));
    assertTrue(entry.isAllowed(Permission.MODIFY));
    assertTrue(entry.isAllowed(Permission.DELETE));
    assertTrue(entry.isAllowed(Permission.PUBLISH));
    assertTrue(entry.isAllowed(Permission.READ_PERMISSIONS));
    assertTrue(entry.isAllowed(Permission.WRITE_PERMISSIONS));
    final AccessControlEntry cmsAdmin = accessControlList.getEntry(PrincipalKey.from("role:cms.admin"));
    assertNotNull(cmsAdmin);
    assertTrue(cmsAdmin.isAllowed(Permission.CREATE));
    assertTrue(cmsAdmin.isDenied(Permission.PUBLISH));
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) Document(org.w3c.dom.Document) Test(org.junit.jupiter.api.Test)

Example 7 with AccessControlEntry

use of com.enonic.xp.security.acl.AccessControlEntry in project xp by enonic.

the class PermissionsXmlSerializer method serialize.

public void serialize() {
    this.domBuilder.start("permissions");
    for (final AccessControlEntry entry : this.accessControlList) {
        serialize(entry);
    }
    this.domBuilder.end();
}
Also used : AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry)

Example 8 with AccessControlEntry

use of com.enonic.xp.security.acl.AccessControlEntry in project xp by enonic.

the class NodeVersionJsonDumpSerializerTest method serialize_deserialize.

@Test
public void serialize_deserialize() throws Exception {
    PropertyTree nodeData = new PropertyTree();
    nodeData.setDouble("a.b.c", 2.0);
    nodeData.setLocalDate("b", LocalDate.of(2013, 1, 2));
    nodeData.setString("c", "runar");
    nodeData.setLocalDateTime("d", LocalDateTime.of(2013, 1, 2, 3, 4, 5, 0));
    nodeData.setBinaryReference("e", BinaryReference.from("myImage1"));
    nodeData.setBinaryReference("f", BinaryReference.from("myImage2"));
    final AccessControlEntry entry1 = AccessControlEntry.create().principal(PrincipalKey.ofAnonymous()).allow(Permission.READ).deny(Permission.DELETE).build();
    final AccessControlEntry entry2 = AccessControlEntry.create().principal(PrincipalKey.ofUser(IdProviderKey.system(), "user1")).allow(Permission.MODIFY).deny(Permission.PUBLISH).build();
    AccessControlList acl = AccessControlList.create().add(entry1).add(entry2).build();
    IndexValueProcessor indexValueProcessor = new IndexValueProcessor() {

        @Override
        public Value process(final Value value) {
            return value;
        }

        @Override
        public String getName() {
            return "indexValueProcessor";
        }
    };
    IndexConfig indexConfig = IndexConfig.create().enabled(true).fulltext(true).nGram(true).decideByType(false).includeInAllText(true).path(true).addIndexValueProcessor(indexValueProcessor).addIndexValueProcessor(indexValueProcessor).build();
    NodeVersion nodeVersion = NodeVersion.create().id(NodeId.from("myId")).indexConfigDocument(PatternIndexConfigDocument.create().analyzer("myAnalyzer").defaultConfig(IndexConfig.MINIMAL).add("myPath", indexConfig).build()).data(nodeData).childOrder(ChildOrder.create().add(FieldOrderExpr.create(IndexPath.from("modifiedTime"), OrderExpr.Direction.ASC)).add(FieldOrderExpr.create(IndexPath.from("displayName"), OrderExpr.Direction.DESC)).build()).permissions(acl).nodeType(NodeType.from("myNodeType")).attachedBinaries(AttachedBinaries.create().add(new AttachedBinary(BinaryReference.from("myImage1"), "a")).add(new AttachedBinary(BinaryReference.from("myImage2"), "b")).build()).build();
    final String expectedNodeStr = readJson("serialized-node.json");
    final String expectedIndexConfigStr = readJson("serialized-index.json");
    final String expectedAccessControlStr = readJson("serialized-access.json");
    final String serializedNode = new String(this.serializer.toNodeString(nodeVersion), StandardCharsets.UTF_8);
    final String serializedIndexConfig = new String(this.serializer.toIndexConfigDocumentString(nodeVersion), StandardCharsets.UTF_8);
    final String serializedAccessControl = new String(this.serializer.toAccessControlString(nodeVersion), StandardCharsets.UTF_8);
    assertEquals(expectedNodeStr, serializedNode);
    assertEquals(expectedIndexConfigStr, serializedIndexConfig);
    assertEquals(expectedAccessControlStr, serializedAccessControl);
    final NodeVersion deSerializedNode = this.serializer.toNodeVersion(expectedNodeStr.getBytes(StandardCharsets.UTF_8), expectedIndexConfigStr.getBytes(StandardCharsets.UTF_8), expectedAccessControlStr.getBytes(StandardCharsets.UTF_8));
    assertEquals(nodeVersion, deSerializedNode);
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) NodeVersion(com.enonic.xp.node.NodeVersion) IndexConfig(com.enonic.xp.index.IndexConfig) PropertyTree(com.enonic.xp.data.PropertyTree) Value(com.enonic.xp.data.Value) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) IndexValueProcessor(com.enonic.xp.index.IndexValueProcessor) AttachedBinary(com.enonic.xp.node.AttachedBinary) Test(org.junit.jupiter.api.Test)

Example 9 with AccessControlEntry

use of com.enonic.xp.security.acl.AccessControlEntry in project xp by enonic.

the class IdProviderNodeTranslator method idProviderPermissionsToUsersNodePermissions.

static AccessControlList idProviderPermissionsToUsersNodePermissions(final IdProviderAccessControlList idProviderPermissions) {
    final List<AccessControlEntry> entries = new ArrayList<>();
    for (IdProviderAccessControlEntry entry : idProviderPermissions) {
        final AccessControlEntry ace;
        switch(entry.getAccess()) {
            case CREATE_USERS:
                ace = AccessControlEntry.create().principal(entry.getPrincipal()).allow(CREATE).build();
                entries.add(ace);
                break;
            case WRITE_USERS:
                ace = AccessControlEntry.create().principal(entry.getPrincipal()).allow(READ, CREATE, MODIFY, DELETE).build();
                entries.add(ace);
                break;
            case ID_PROVIDER_MANAGER:
                ace = AccessControlEntry.create().principal(entry.getPrincipal()).allow(READ, CREATE, MODIFY, DELETE).build();
                entries.add(ace);
                break;
            case ADMINISTRATOR:
                ace = AccessControlEntry.create().principal(entry.getPrincipal()).allow(READ, CREATE, MODIFY, DELETE, PUBLISH, READ_PERMISSIONS, WRITE_PERMISSIONS).build();
                entries.add(ace);
                break;
            case READ:
                ace = AccessControlEntry.create().principal(entry.getPrincipal()).allow(READ).build();
                entries.add(ace);
                break;
        }
    }
    return AccessControlList.create().addAll(entries).build();
}
Also used : ArrayList(java.util.ArrayList) IdProviderAccessControlEntry(com.enonic.xp.security.acl.IdProviderAccessControlEntry) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) IdProviderAccessControlEntry(com.enonic.xp.security.acl.IdProviderAccessControlEntry)

Example 10 with AccessControlEntry

use of com.enonic.xp.security.acl.AccessControlEntry in project xp by enonic.

the class IdProviderNodeTranslator method idProviderPermissionsToGroupsNodePermissions.

static AccessControlList idProviderPermissionsToGroupsNodePermissions(final IdProviderAccessControlList idProviderPermissions) {
    final List<AccessControlEntry> entries = new ArrayList<>();
    for (IdProviderAccessControlEntry entry : idProviderPermissions) {
        final AccessControlEntry ace;
        switch(entry.getAccess()) {
            case ID_PROVIDER_MANAGER:
                ace = AccessControlEntry.create().principal(entry.getPrincipal()).allow(READ, CREATE, MODIFY, DELETE).build();
                entries.add(ace);
                break;
            case ADMINISTRATOR:
                ace = AccessControlEntry.create().principal(entry.getPrincipal()).allow(READ, CREATE, MODIFY, DELETE, PUBLISH, READ_PERMISSIONS, WRITE_PERMISSIONS).build();
                entries.add(ace);
                break;
        }
    }
    return AccessControlList.create().addAll(entries).build();
}
Also used : ArrayList(java.util.ArrayList) IdProviderAccessControlEntry(com.enonic.xp.security.acl.IdProviderAccessControlEntry) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) IdProviderAccessControlEntry(com.enonic.xp.security.acl.IdProviderAccessControlEntry)

Aggregations

AccessControlEntry (com.enonic.xp.security.acl.AccessControlEntry)16 PropertyTree (com.enonic.xp.data.PropertyTree)4 AccessControlList (com.enonic.xp.security.acl.AccessControlList)4 IdProviderAccessControlEntry (com.enonic.xp.security.acl.IdProviderAccessControlEntry)4 ArrayList (java.util.ArrayList)4 PropertySet (com.enonic.xp.data.PropertySet)3 PrincipalKey (com.enonic.xp.security.PrincipalKey)3 IndexConfig (com.enonic.xp.index.IndexConfig)2 AttachedBinary (com.enonic.xp.node.AttachedBinary)2 Permission (com.enonic.xp.security.acl.Permission)2 Test (org.junit.jupiter.api.Test)2 ContentId (com.enonic.xp.content.ContentId)1 Value (com.enonic.xp.data.Value)1 ChildOrder (com.enonic.xp.index.ChildOrder)1 IndexValueProcessor (com.enonic.xp.index.IndexValueProcessor)1 PatternIndexConfigDocument (com.enonic.xp.index.PatternIndexConfigDocument)1 NodePath (com.enonic.xp.node.NodePath)1 NodeVersion (com.enonic.xp.node.NodeVersion)1 IndexItem (com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexItem)1 IndexItemString (com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexItemString)1