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