Search in sources :

Example 6 with PermissionEntry

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

the class GetSetPermissionsMethod method execute.

private NodePermissionEntry execute(Reference reference, Set<String> toAllow, Set<String> toDeny) {
    NodeRef rNodeRef = reference.toNodeRef();
    List<PermissionEntry> permissions = new LinkedList<>();
    for (String permission : toAllow) {
        PermissionReference permissionReference = PermissionReferenceImpl.getPermissionReference(userPermissions.getPermissionTypeQName(), permission);
        permissions.add(new SimplePermissionEntry(rNodeRef, permissionReference, authority, AccessStatus.ALLOWED));
    }
    for (String permission : toDeny) {
        PermissionReference permissionReference = PermissionReferenceImpl.getPermissionReference(userPermissions.getPermissionTypeQName(), permission);
        permissions.add(new SimplePermissionEntry(rNodeRef, permissionReference, authority, AccessStatus.DENIED));
    }
    return new SimpleNodePermissionEntry(rNodeRef, false, permissions);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) SimpleNodePermissionEntry(org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry) PermissionReference(org.alfresco.repo.security.permissions.PermissionReference) PermissionEntry(org.alfresco.repo.security.permissions.PermissionEntry) SimplePermissionEntry(org.alfresco.repo.security.permissions.impl.SimplePermissionEntry) NodePermissionEntry(org.alfresco.repo.security.permissions.NodePermissionEntry) SimpleNodePermissionEntry(org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry) SimplePermissionEntry(org.alfresco.repo.security.permissions.impl.SimplePermissionEntry) LinkedList(java.util.LinkedList)

Example 7 with PermissionEntry

use of org.alfresco.repo.security.permissions.PermissionEntry 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 8 with PermissionEntry

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

the class PermissionServiceTest method testSetPermissionEntryElements.

public void testSetPermissionEntryElements() {
    // add andy-all (allow)
    permissionService.setPermission(rootNodeRef, "andy", permissionService.getAllPermission(), true);
    assertNotNull(permissionService.getSetPermissions(rootNodeRef));
    assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
    assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
    assertEquals(1, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
    for (PermissionEntry pe : permissionService.getSetPermissions(rootNodeRef).getPermissionEntries()) {
        assertEquals("andy", pe.getAuthority());
        assertTrue(pe.isAllowed());
        assertTrue(pe.getPermissionReference().getQName().equals(permissionService.getAllPermissionReference().getQName()));
        assertTrue(pe.getPermissionReference().getName().equals(permissionService.getAllPermissionReference().getName()));
        assertEquals(rootNodeRef, pe.getNodeRef());
    }
    // add andy-all (allow)
    permissionService.setPermission(rootNodeRef, "andy", permissionService.getAllPermission(), true);
    assertNotNull(permissionService.getSetPermissions(rootNodeRef));
    assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
    assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
    assertEquals(1, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
    // add other-all (allow)
    permissionService.setPermission(rootNodeRef, "other", permissionService.getAllPermission(), true);
    assertNotNull(permissionService.getSetPermissions(rootNodeRef));
    assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
    assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
    assertEquals(2, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
    // add andy-all (deny)
    permissionService.setPermission(rootNodeRef, "andy", permissionService.getAllPermission(), false);
    assertNotNull(permissionService.getSetPermissions(rootNodeRef));
    assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
    assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
    assertEquals(2, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
    // add andy-read (deny)
    permissionService.setPermission(rootNodeRef, "andy", PermissionService.READ, false);
    assertNotNull(permissionService.getSetPermissions(rootNodeRef));
    assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
    assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
    assertEquals(3, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
    // remove andy-read
    permissionService.deletePermission(rootNodeRef, "andy", PermissionService.READ);
    assertNotNull(permissionService.getSetPermissions(rootNodeRef));
    assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
    assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
    assertEquals(2, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
    // remove andy-all
    permissionService.deletePermission(rootNodeRef, "andy", permissionService.getAllPermission());
    assertNotNull(permissionService.getSetPermissions(rootNodeRef));
    assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
    assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
    assertEquals(1, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
    // remove other-all
    permissionService.deletePermission(rootNodeRef, "other", permissionService.getAllPermission());
    assertNotNull(permissionService.getSetPermissions(rootNodeRef));
    assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
    assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
    assertEquals(0, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
}
Also used : PermissionEntry(org.alfresco.repo.security.permissions.PermissionEntry) NodePermissionEntry(org.alfresco.repo.security.permissions.NodePermissionEntry)

Example 9 with PermissionEntry

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

the class VirtualPermissionServiceExtensionTest method mapPermissionsByName.

@SuppressWarnings("unchecked")
private Map<String, List<? extends PermissionEntry>> mapPermissionsByName(List<? extends PermissionEntry> entries) {
    Map<String, List<? extends PermissionEntry>> nameMap = new HashMap<>();
    for (PermissionEntry permissionEntry : entries) {
        String name = permissionEntry.getPermissionReference().getName();
        List<PermissionEntry> permissions = (List<PermissionEntry>) nameMap.get(name);
        if (permissions == null) {
            permissions = new ArrayList<>();
            nameMap.put(name, permissions);
        }
        permissions.add(permissionEntry);
    }
    return nameMap;
}
Also used : HashMap(java.util.HashMap) PermissionEntry(org.alfresco.repo.security.permissions.PermissionEntry) NodePermissionEntry(org.alfresco.repo.security.permissions.NodePermissionEntry) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

NodePermissionEntry (org.alfresco.repo.security.permissions.NodePermissionEntry)9 PermissionEntry (org.alfresco.repo.security.permissions.PermissionEntry)9 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 SimpleNodePermissionEntry (org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry)3 NodeRef (org.alfresco.service.cmr.repository.NodeRef)3 LinkedHashSet (java.util.LinkedHashSet)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 PermissionReference (org.alfresco.repo.security.permissions.PermissionReference)2 SimplePermissionEntry (org.alfresco.repo.security.permissions.impl.SimplePermissionEntry)2 AccessPermission (org.alfresco.service.cmr.security.AccessPermission)2 Extend (org.alfresco.traitextender.Extend)2 HashMap (java.util.HashMap)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 Reference (org.alfresco.repo.virtual.ref.Reference)1 QName (org.alfresco.service.namespace.QName)1