Search in sources :

Example 21 with SimpleAccessControlEntry

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

the class AclDaoComponentTest method testAddSimilar.

public void testAddSimilar() {
    SimpleAccessControlListProperties properties = new SimpleAccessControlListProperties();
    properties.setAclType(ACLType.DEFINING);
    properties.setVersioned(false);
    Long id1 = aclDaoComponent.createAccessControlList(properties).getId();
    Long shared1 = aclDaoComponent.getInheritedAccessControlList(id1);
    Long id2 = aclDaoComponent.createAccessControlList(properties).getId();
    Long shared2 = aclDaoComponent.getInheritedAccessControlList(id2);
    aclDaoComponent.mergeInheritedAccessControlList(shared1, id2);
    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);
    SimpleAccessControlEntry ace2 = new SimpleAccessControlEntry();
    ace2.setAccessStatus(AccessStatus.ALLOWED);
    ace2.setAceType(ACEType.ALL);
    ace2.setAuthority("andy");
    ace2.setPermission(new SimplePermissionReference(QName.createQName("uri", "local"), "Read"));
    ace2.setPosition(null);
    aclDaoComponent.setAccessControlEntry(id1, ace1);
    aclDaoComponent.setAccessControlEntry(id2, ace1);
    assertEquals(aclDaoComponent.getAccessControlList(id1).getEntries().size(), 1);
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(id1).getEntries(), ace1, 0));
    assertEquals(aclDaoComponent.getAccessControlList(shared1).getEntries().size(), 1);
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(shared1).getEntries(), ace1, 1));
    assertEquals(aclDaoComponent.getAccessControlList(id2).getEntries().size(), 2);
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(id2).getEntries(), ace1, 0));
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(id2).getEntries(), ace1, 2));
    assertEquals(aclDaoComponent.getAccessControlList(shared2).getEntries().size(), 2);
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(shared2).getEntries(), ace1, 1));
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(shared2).getEntries(), ace1, 3));
    aclDaoComponent.setAccessControlEntry(id1, ace2);
    assertEquals(aclDaoComponent.getAccessControlList(id1).getEntries().size(), 1);
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(id1).getEntries(), ace2, 0));
    assertEquals(aclDaoComponent.getAccessControlList(shared1).getEntries().size(), 1);
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(shared1).getEntries(), ace2, 1));
    assertEquals(aclDaoComponent.getAccessControlList(id2).getEntries().size(), 2);
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(id2).getEntries(), ace2, 0));
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(id2).getEntries(), ace1, 2));
    assertEquals(aclDaoComponent.getAccessControlList(shared2).getEntries().size(), 2);
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(shared2).getEntries(), ace2, 1));
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(shared2).getEntries(), ace1, 3));
    aclDaoComponent.setAccessControlEntry(id1, ace1);
    aclDaoComponent.setAccessControlEntry(id2, ace2);
    assertEquals(aclDaoComponent.getAccessControlList(id1).getEntries().size(), 1);
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(id1).getEntries(), ace1, 0));
    assertEquals(aclDaoComponent.getAccessControlList(shared1).getEntries().size(), 1);
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(shared1).getEntries(), ace1, 1));
    assertEquals(aclDaoComponent.getAccessControlList(id2).getEntries().size(), 2);
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(id2).getEntries(), ace1, 0));
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(id2).getEntries(), ace2, 2));
    assertEquals(aclDaoComponent.getAccessControlList(shared2).getEntries().size(), 2);
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(shared2).getEntries(), ace1, 1));
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(shared2).getEntries(), ace2, 3));
    aclDaoComponent.setAccessControlEntry(id1, ace2);
    assertEquals(aclDaoComponent.getAccessControlList(id1).getEntries().size(), 1);
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(id1).getEntries(), ace2, 0));
    assertEquals(aclDaoComponent.getAccessControlList(shared1).getEntries().size(), 1);
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(shared1).getEntries(), ace2, 1));
    assertEquals(aclDaoComponent.getAccessControlList(id2).getEntries().size(), 2);
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(id2).getEntries(), ace2, 0));
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(id2).getEntries(), ace2, 2));
    assertEquals(aclDaoComponent.getAccessControlList(shared2).getEntries().size(), 2);
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(shared2).getEntries(), ace2, 1));
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(shared2).getEntries(), ace2, 3));
    aclDaoComponent.setAccessControlEntry(id1, ace1);
    aclDaoComponent.setAccessControlEntry(id2, ace1);
    assertEquals(aclDaoComponent.getAccessControlList(id1).getEntries().size(), 1);
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(id1).getEntries(), ace1, 0));
    assertEquals(aclDaoComponent.getAccessControlList(shared1).getEntries().size(), 1);
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(shared1).getEntries(), ace1, 1));
    assertEquals(aclDaoComponent.getAccessControlList(id2).getEntries().size(), 2);
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(id2).getEntries(), ace1, 0));
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(id2).getEntries(), ace1, 2));
    assertEquals(aclDaoComponent.getAccessControlList(shared2).getEntries().size(), 2);
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(shared2).getEntries(), ace1, 1));
    assertTrue(hasAce(aclDaoComponent.getAccessControlList(shared2).getEntries(), ace1, 3));
}
Also used : SimpleAccessControlListProperties(org.alfresco.repo.security.permissions.SimpleAccessControlListProperties) SimpleAccessControlEntry(org.alfresco.repo.security.permissions.SimpleAccessControlEntry)

Aggregations

SimpleAccessControlEntry (org.alfresco.repo.security.permissions.SimpleAccessControlEntry)21 SimpleAccessControlListProperties (org.alfresco.repo.security.permissions.SimpleAccessControlListProperties)9 AclChange (org.alfresco.repo.security.permissions.impl.AclChange)9 ArrayList (java.util.ArrayList)8 AccessControlListProperties (org.alfresco.repo.security.permissions.AccessControlListProperties)4 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)3 HashSet (java.util.HashSet)2 AccessControlEntry (org.alfresco.repo.security.permissions.AccessControlEntry)2 AccessControlList (org.alfresco.repo.security.permissions.AccessControlList)2 SimplePermissionReference (org.alfresco.repo.security.permissions.impl.SimplePermissionReference)2 QName (org.alfresco.service.namespace.QName)2 Map (java.util.Map)1 NodePermissionEntry (org.alfresco.repo.security.permissions.NodePermissionEntry)1 PermissionEntry (org.alfresco.repo.security.permissions.PermissionEntry)1 SimpleAccessControlList (org.alfresco.repo.security.permissions.SimpleAccessControlList)1 SimpleNodePermissionEntry (org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry)1 SimplePermissionEntry (org.alfresco.repo.security.permissions.impl.SimplePermissionEntry)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1