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));
}
Aggregations