Search in sources :

Example 6 with NodePermissionEntry

use of org.alfresco.repo.security.permissions.NodePermissionEntry in project alfresco-repository by Alfresco.

the class AbstractPermissionsDaoComponentImpl method setPermission.

public void setPermission(NodePermissionEntry nodePermissionEntry) {
    NodeRef nodeRef = nodePermissionEntry.getNodeRef();
    // Get the access control list
    // Note the logic here requires to know whether it was created or not
    Acl existing = getAccessControlList(nodeRef);
    if (existing != null) {
        deletePermissions(nodeRef);
    }
    // create the access control list
    existing = getAccessControlList(nodeRef);
    CreationReport report = createAccessControlList(nodeRef, nodePermissionEntry.inheritPermissions(), existing);
    // add all entries
    for (PermissionEntry pe : nodePermissionEntry.getPermissionEntries()) {
        SimpleAccessControlEntry entry = new SimpleAccessControlEntry();
        entry.setAuthority(pe.getAuthority());
        entry.setPermission(pe.getPermissionReference());
        entry.setAccessStatus(pe.isAllowed() ? AccessStatus.ALLOWED : AccessStatus.DENIED);
        entry.setAceType(ACEType.ALL);
        entry.setPosition(Integer.valueOf(0));
        List<AclChange> changes = aclDaoComponent.setAccessControlEntry(report.getCreated().getId(), entry);
        List<AclChange> all = new ArrayList<AclChange>(changes.size() + report.getChanges().size());
        all.addAll(report.getChanges());
        all.addAll(changes);
        getACLDAO(nodeRef).updateChangedAcls(nodeRef, all);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) PermissionEntry(org.alfresco.repo.security.permissions.PermissionEntry) SimpleNodePermissionEntry(org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry) SimplePermissionEntry(org.alfresco.repo.security.permissions.impl.SimplePermissionEntry) NodePermissionEntry(org.alfresco.repo.security.permissions.NodePermissionEntry) ArrayList(java.util.ArrayList) AclChange(org.alfresco.repo.security.permissions.impl.AclChange) SimpleAccessControlEntry(org.alfresco.repo.security.permissions.SimpleAccessControlEntry)

Example 7 with NodePermissionEntry

use of org.alfresco.repo.security.permissions.NodePermissionEntry in project alfresco-repository by Alfresco.

the class AbstractPermissionsDaoComponentImpl method getPermissions.

public NodePermissionEntry getPermissions(StoreRef storeRef) {
    // Create the object if it is not found.
    // Null objects are not cached in hibernate
    // If the object does not exist it will repeatedly query to check its
    // non existence.
    NodePermissionEntry npe = null;
    Acl acl = null;
    try {
        acl = getAccessControlList(storeRef);
    } catch (InvalidNodeRefException e) {
    // Do nothing.
    }
    if (acl == null) {
        // there isn't an access control list for the node - spoof a null one
        SimpleNodePermissionEntry snpe = new SimpleNodePermissionEntry(null, true, Collections.<SimplePermissionEntry>emptyList());
        npe = snpe;
    } else {
        npe = createSimpleNodePermissionEntry(storeRef);
    }
    return npe;
}
Also used : SimpleNodePermissionEntry(org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) SimpleNodePermissionEntry(org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry) NodePermissionEntry(org.alfresco.repo.security.permissions.NodePermissionEntry)

Example 8 with NodePermissionEntry

use of org.alfresco.repo.security.permissions.NodePermissionEntry in project alfresco-repository by Alfresco.

the class AbstractPermissionsDaoComponentImpl method getPermissions.

public NodePermissionEntry getPermissions(NodeRef nodeRef) {
    // Create the object if it is not found.
    // Null objects are not cached in hibernate
    // If the object does not exist it will repeatedly query to check its
    // non existence.
    NodePermissionEntry npe = null;
    Acl acl = null;
    try {
        acl = getAccessControlList(nodeRef);
    } catch (InvalidNodeRefException e) {
    // Do nothing.
    }
    if (acl == null) {
        // there isn't an access control list for the node - spoof a null one
        SimpleNodePermissionEntry snpe = new SimpleNodePermissionEntry(nodeRef, true, Collections.<SimplePermissionEntry>emptyList());
        npe = snpe;
    } else {
        npe = createSimpleNodePermissionEntry(nodeRef);
    }
    // done
    if (logger.isDebugEnabled()) {
        logger.debug("Got NodePermissionEntry for node: \n" + "   node: " + nodeRef + "\n" + "   acl: " + npe);
    }
    return npe;
}
Also used : SimpleNodePermissionEntry(org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) SimpleNodePermissionEntry(org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry) NodePermissionEntry(org.alfresco.repo.security.permissions.NodePermissionEntry)

Example 9 with NodePermissionEntry

use of org.alfresco.repo.security.permissions.NodePermissionEntry in project alfresco-repository by Alfresco.

the class PermissionServiceTest method testSimplePermissionOnStore.

public void testSimplePermissionOnStore() {
    runAs("andy");
    NodePermissionEntry entry = permissionService.getSetPermissions(testStoreRef);
    assertNotNull(entry);
    assertEquals(0, entry.getPermissionEntries().size());
    assertEquals(0, permissionService.getAllSetPermissions(testStoreRef).size());
    // Test Nulls
    assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(null, getPermission(PermissionService.READ)));
    assertEquals(AccessStatus.DENIED, permissionService.hasPermission(rootNodeRef, (PermissionReference) null));
    assertEquals(AccessStatus.ALLOWED, permissionService.hasPermission(new NodeRef(testStoreRef, "I don't exist"), getPermission(PermissionService.READ)));
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) PermissionReference(org.alfresco.repo.security.permissions.PermissionReference) NodePermissionEntry(org.alfresco.repo.security.permissions.NodePermissionEntry)

Aggregations

NodePermissionEntry (org.alfresco.repo.security.permissions.NodePermissionEntry)9 PermissionEntry (org.alfresco.repo.security.permissions.PermissionEntry)5 SimpleNodePermissionEntry (org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry)5 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 HashSet (java.util.HashSet)3 PermissionReference (org.alfresco.repo.security.permissions.PermissionReference)3 LinkedHashSet (java.util.LinkedHashSet)2 LinkedList (java.util.LinkedList)2 SimplePermissionEntry (org.alfresco.repo.security.permissions.impl.SimplePermissionEntry)2 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)2 AccessPermission (org.alfresco.service.cmr.security.AccessPermission)2 Extend (org.alfresco.traitextender.Extend)2 ArrayList (java.util.ArrayList)1 SimpleAccessControlEntry (org.alfresco.repo.security.permissions.SimpleAccessControlEntry)1 AclChange (org.alfresco.repo.security.permissions.impl.AclChange)1 PermissionServiceTrait (org.alfresco.repo.security.permissions.impl.traitextender.PermissionServiceTrait)1 VirtualizationIntegrationTest (org.alfresco.repo.virtual.VirtualizationIntegrationTest)1 Reference (org.alfresco.repo.virtual.ref.Reference)1 QName (org.alfresco.service.namespace.QName)1 Test (org.junit.Test)1