Search in sources :

Example 11 with AccessControlList

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

the class PermissionServiceImpl method getReaders.

/**
 * {@inheritDoc}
 */
@Override
@Extend(traitAPI = PermissionServiceTrait.class, extensionAPI = PermissionServiceExtension.class)
public Set<String> getReaders(Long aclId) {
    AccessControlList acl = aclDaoComponent.getAccessControlList(aclId);
    if (acl == null) {
        return Collections.emptySet();
    }
    Set<String> aclReaders = readersCache.get((Serializable) acl.getProperties());
    if (aclReaders != null) {
        return aclReaders;
    }
    HashSet<String> assigned = new HashSet<String>();
    HashSet<String> readers = new HashSet<String>();
    for (AccessControlEntry ace : acl.getEntries()) {
        assigned.add(ace.getAuthority());
    }
    for (String authority : assigned) {
        UnconditionalAclTest test = new UnconditionalAclTest(getPermissionReference(PermissionService.READ));
        if (test.evaluate(authority, aclId)) {
            readers.add(authority);
        }
    }
    aclReaders = Collections.unmodifiableSet(readers);
    readersCache.put((Serializable) acl.getProperties(), aclReaders);
    return aclReaders;
}
Also used : AccessControlList(org.alfresco.repo.security.permissions.AccessControlList) AccessControlEntry(org.alfresco.repo.security.permissions.AccessControlEntry) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Extend(org.alfresco.traitextender.Extend)

Example 12 with AccessControlList

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

the class AclDaoComponentTest method testSimpleInheritFromDefining.

public void testSimpleInheritFromDefining() {
    SimpleAccessControlListProperties properties = new SimpleAccessControlListProperties();
    properties.setAclType(ACLType.DEFINING);
    properties.setVersioned(true);
    AccessControlListProperties aclProps = aclDaoComponent.createAccessControlList(properties);
    long id = aclProps.getId();
    assertEquals(aclProps.getAclType(), ACLType.DEFINING);
    assertEquals(aclProps.getAclVersion(), Long.valueOf(1l));
    assertEquals(aclProps.getInherits(), Boolean.TRUE);
    assertEquals(aclDaoComponent.getAccessControlListProperties(id), aclProps);
    SimpleAccessControlEntry ace1 = new SimpleAccessControlEntry();
    ace1.setAccessStatus(AccessStatus.ALLOWED);
    ace1.setAceType(ACEType.ALL);
    ace1.setAuthority("andy");
    ace1.setPermission(new SimplePermissionReference(QName.createQName("uri", "local"), "Read"));
    ace1.setPosition(null);
    aclDaoComponent.setAccessControlEntry(id, ace1);
    AccessControlList defined = aclDaoComponent.getAccessControlList(id);
    assertEquals(defined.getProperties().getAclType(), ACLType.DEFINING);
    assertEquals(defined.getProperties().getAclVersion(), Long.valueOf(1l));
    assertEquals(defined.getProperties().getInherits(), Boolean.TRUE);
    assertEquals(defined.getEntries().size(), 1);
    assertTrue(hasAce(defined.getEntries(), ace1, 0));
    Long sharedId = aclDaoComponent.getInheritedAccessControlList(id);
    AccessControlListProperties sharedProps = aclDaoComponent.getAccessControlListProperties(sharedId);
    assertEquals(sharedProps.getAclType(), ACLType.SHARED);
    assertEquals(sharedProps.getAclVersion(), Long.valueOf(1l));
    assertEquals(sharedProps.getInherits(), Boolean.TRUE);
    assertEquals(aclDaoComponent.getInheritedAccessControlList(id), sharedId);
    AccessControlList shared = aclDaoComponent.getAccessControlList(sharedId);
    assertEquals(shared.getProperties().getAclType(), ACLType.SHARED);
    assertEquals(shared.getProperties().getAclVersion(), Long.valueOf(1l));
    assertEquals(shared.getProperties().getInherits(), Boolean.TRUE);
    assertEquals(shared.getEntries().size(), 1);
    assertTrue(hasAce(shared.getEntries(), ace1, 1));
    SimpleAccessControlEntry ace2 = new SimpleAccessControlEntry();
    ace2.setAccessStatus(AccessStatus.ALLOWED);
    ace2.setAceType(ACEType.ALL);
    ace2.setAuthority("paul");
    ace2.setPermission(new SimplePermissionReference(QName.createQName("uri", "local"), "Write"));
    ace2.setPosition(null);
    aclDaoComponent.setAccessControlEntry(id, ace2);
    defined = aclDaoComponent.getAccessControlList(id);
    assertEquals(defined.getProperties().getAclType(), ACLType.DEFINING);
    assertEquals(defined.getProperties().getAclVersion(), Long.valueOf(1l));
    assertEquals(defined.getProperties().getInherits(), Boolean.TRUE);
    assertEquals(defined.getEntries().size(), 2);
    assertTrue(hasAce(defined.getEntries(), ace1, 0));
    assertTrue(hasAce(defined.getEntries(), ace2, 0));
    sharedId = aclDaoComponent.getInheritedAccessControlList(id);
    shared = aclDaoComponent.getAccessControlList(sharedId);
    assertEquals(shared.getProperties().getAclType(), ACLType.SHARED);
    assertEquals(shared.getProperties().getAclVersion(), Long.valueOf(1l));
    assertEquals(shared.getProperties().getInherits(), Boolean.TRUE);
    assertEquals(shared.getEntries().size(), 2);
    assertTrue(hasAce(shared.getEntries(), ace1, 1));
    assertTrue(hasAce(shared.getEntries(), ace2, 1));
}
Also used : AccessControlList(org.alfresco.repo.security.permissions.AccessControlList) AccessControlListProperties(org.alfresco.repo.security.permissions.AccessControlListProperties) SimpleAccessControlListProperties(org.alfresco.repo.security.permissions.SimpleAccessControlListProperties) SimpleAccessControlListProperties(org.alfresco.repo.security.permissions.SimpleAccessControlListProperties) SimpleAccessControlEntry(org.alfresco.repo.security.permissions.SimpleAccessControlEntry)

Aggregations

AccessControlList (org.alfresco.repo.security.permissions.AccessControlList)12 AccessControlEntry (org.alfresco.repo.security.permissions.AccessControlEntry)10 HashSet (java.util.HashSet)5 SimpleAccessControlEntry (org.alfresco.repo.security.permissions.SimpleAccessControlEntry)5 SimpleAccessControlListProperties (org.alfresco.repo.security.permissions.SimpleAccessControlListProperties)4 ArrayList (java.util.ArrayList)3 AccessControlListProperties (org.alfresco.repo.security.permissions.AccessControlListProperties)3 LinkedHashSet (java.util.LinkedHashSet)2 NodeIdAndAclId (org.alfresco.repo.domain.node.NodeIdAndAclId)2 SimpleAccessControlList (org.alfresco.repo.security.permissions.SimpleAccessControlList)2 SimpleNodePermissionEntry (org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry)2 SimplePermissionEntry (org.alfresco.repo.security.permissions.impl.SimplePermissionEntry)2 Extend (org.alfresco.traitextender.Extend)2 Map (java.util.Map)1 Acl (org.alfresco.repo.domain.permissions.Acl)1 AuthenticationUtil (org.alfresco.repo.security.authentication.AuthenticationUtil)1 AclChange (org.alfresco.repo.security.permissions.impl.AclChange)1 SimplePermissionReference (org.alfresco.repo.security.permissions.impl.SimplePermissionReference)1 QName (org.alfresco.service.namespace.QName)1