Search in sources :

Example 1 with PermissionEntry

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

the class PermissionServiceTest method testSetPermissionEntry.

public void testSetPermissionEntry() {
    permissionService.setPermission(allowAndyAll);
    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());
    }
    // Set duplicate
    permissionService.setPermission(allowAndyAll);
    assertNotNull(permissionService.getSetPermissions(rootNodeRef));
    assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
    assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
    assertEquals(1, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
    // Set new
    permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, permissionService.getAllPermissionReference(), "other", AccessStatus.ALLOWED));
    assertNotNull(permissionService.getSetPermissions(rootNodeRef));
    assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
    assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
    assertEquals(2, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
    // Deny
    permissionService.setPermission(denyAndyAll);
    assertNotNull(permissionService.getSetPermissions(rootNodeRef));
    assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
    assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
    assertEquals(2, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
    // new
    permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, new SimplePermissionReference(QName.createQName("A", "B"), "C"), "andy", AccessStatus.DENIED));
    assertNotNull(permissionService.getSetPermissions(rootNodeRef));
    assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
    assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
    assertEquals(3, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
    permissionService.deletePermission(new SimplePermissionEntry(rootNodeRef, new SimplePermissionReference(QName.createQName("A", "B"), "C"), "andy", AccessStatus.DENIED));
    assertNotNull(permissionService.getSetPermissions(rootNodeRef));
    assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
    assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
    assertEquals(2, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
    permissionService.deletePermission(denyAndyAll);
    assertNotNull(permissionService.getSetPermissions(rootNodeRef));
    assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
    assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
    assertEquals(1, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
    permissionService.deletePermission(new SimplePermissionEntry(rootNodeRef, permissionService.getAllPermissionReference(), "other", AccessStatus.ALLOWED));
    assertNotNull(permissionService.getSetPermissions(rootNodeRef));
    assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
    assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
    assertEquals(0, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
    // delete when we know there's nothing do delete
    permissionService.deletePermission(allowAndyAll);
    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 2 with PermissionEntry

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

the class PermissionServiceImpl method getAllSetPermissions.

@Override
@Extend(traitAPI = PermissionServiceTrait.class, extensionAPI = PermissionServiceExtension.class)
public Set<AccessPermission> getAllSetPermissions(NodeRef nodeRef) {
    HashSet<AccessPermission> accessPermissions = new HashSet<AccessPermission>();
    NodePermissionEntry nodePremissionEntry = getSetPermissions(nodeRef);
    for (PermissionEntry pe : nodePremissionEntry.getPermissionEntries()) {
        accessPermissions.add(new AccessPermissionImpl(getPermission(pe.getPermissionReference()), pe.getAccessStatus(), pe.getAuthority(), pe.getPosition()));
    }
    return accessPermissions;
}
Also used : AccessPermission(org.alfresco.service.cmr.security.AccessPermission) NodePermissionEntry(org.alfresco.repo.security.permissions.NodePermissionEntry) PermissionEntry(org.alfresco.repo.security.permissions.PermissionEntry) NodePermissionEntry(org.alfresco.repo.security.permissions.NodePermissionEntry) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Extend(org.alfresco.traitextender.Extend)

Example 3 with PermissionEntry

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

the class PermissionServiceImpl method getAllSetPermissions.

@Override
@Extend(traitAPI = PermissionServiceTrait.class, extensionAPI = PermissionServiceExtension.class)
public Set<AccessPermission> getAllSetPermissions(StoreRef storeRef) {
    HashSet<AccessPermission> accessPermissions = new HashSet<AccessPermission>();
    NodePermissionEntry nodePremissionEntry = getSetPermissions(storeRef);
    for (PermissionEntry pe : nodePremissionEntry.getPermissionEntries()) {
        accessPermissions.add(new AccessPermissionImpl(getPermission(pe.getPermissionReference()), pe.getAccessStatus(), pe.getAuthority(), pe.getPosition()));
    }
    return accessPermissions;
}
Also used : AccessPermission(org.alfresco.service.cmr.security.AccessPermission) NodePermissionEntry(org.alfresco.repo.security.permissions.NodePermissionEntry) PermissionEntry(org.alfresco.repo.security.permissions.PermissionEntry) NodePermissionEntry(org.alfresco.repo.security.permissions.NodePermissionEntry) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Extend(org.alfresco.traitextender.Extend)

Example 4 with PermissionEntry

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

the class VirtualPermissionServiceExtension method getSetPermissions.

@Override
public NodePermissionEntry getSetPermissions(NodeRef nodeRef) {
    PermissionServiceTrait theTrait = getTrait();
    Reference reference = Reference.fromNodeRef(nodeRef);
    if (reference == null) {
        return theTrait.getSetPermissions(nodeRef);
    } else {
        NodePermissionEntry virtualSetPermissions = smartStore.getSetPermissions(reference);
        NodeRef nodeToAdhereTo = establishPermisisonAdherence(reference);
        List<? extends PermissionEntry> actualPermissionEntries;
        boolean inheritPermissions = false;
        if (nodeToAdhereTo != null) {
            NodePermissionEntry actualSetPermissions = theTrait.getSetPermissions(nodeToAdhereTo);
            actualPermissionEntries = actualSetPermissions.getPermissionEntries();
            inheritPermissions = actualSetPermissions.inheritPermissions();
        } else {
            actualPermissionEntries = Collections.emptyList();
            inheritPermissions = false;
        }
        List<PermissionEntry> mergedEntries = new LinkedList<>();
        List<? extends PermissionEntry> virtualPermissionEntries = virtualSetPermissions.getPermissionEntries();
        Set<QName> overridenPermissions = new HashSet<>();
        for (PermissionEntry permissionEntry : virtualPermissionEntries) {
            overridenPermissions.add(permissionEntry.getPermissionReference().getQName());
            mergedEntries.add(permissionEntry);
        }
        for (PermissionEntry permissionEntry : actualPermissionEntries) {
            if (!overridenPermissions.contains(permissionEntry.getPermissionReference().getQName())) {
                mergedEntries.add(permissionEntry);
            }
        }
        return new SimpleNodePermissionEntry(nodeRef, inheritPermissions, mergedEntries);
    }
}
Also used : PermissionReference(org.alfresco.repo.security.permissions.PermissionReference) Reference(org.alfresco.repo.virtual.ref.Reference) QName(org.alfresco.service.namespace.QName) NodePermissionEntry(org.alfresco.repo.security.permissions.NodePermissionEntry) SimpleNodePermissionEntry(org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry) PermissionServiceTrait(org.alfresco.repo.security.permissions.impl.traitextender.PermissionServiceTrait) LinkedList(java.util.LinkedList) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SimpleNodePermissionEntry(org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry) PermissionEntry(org.alfresco.repo.security.permissions.PermissionEntry) NodePermissionEntry(org.alfresco.repo.security.permissions.NodePermissionEntry) SimpleNodePermissionEntry(org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry) HashSet(java.util.HashSet)

Example 5 with PermissionEntry

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

the class VirtualPermissionServiceExtensionTest method assertUniquePermission.

/**
 * Asserts that the permission with the given name uniquely found in the
 * given permission entries list has the given access status for the given
 * authority.
 *
 * @param permissionName
 * @param accessStatus
 * @param authority
 * @param permissionEntries
 */
protected void assertUniquePermission(String permissionName, AccessStatus accessStatus, String authority, List<? extends PermissionEntry> permissionEntries) {
    Map<String, List<? extends PermissionEntry>> entriesByName = mapPermissionsByName((List<? extends PermissionEntry>) permissionEntries);
    assertNotNull("Not null permission " + permissionName + " expected.", entriesByName.get(permissionName));
    assertEquals(1, entriesByName.get(permissionName).size());
    PermissionEntry permission = entriesByName.get(permissionName).get(0);
    assertEquals(accessStatus, permission.getAccessStatus());
    assertEquals(authority, permission.getAuthority());
}
Also used : 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