use of org.alfresco.repo.security.permissions.PermissionEntry in project alfresco-repository by Alfresco.
the class GetSetPermissionsMethod method execute.
private NodePermissionEntry execute(Reference reference, Set<String> toAllow, Set<String> toDeny) {
NodeRef rNodeRef = reference.toNodeRef();
List<PermissionEntry> permissions = new LinkedList<>();
for (String permission : toAllow) {
PermissionReference permissionReference = PermissionReferenceImpl.getPermissionReference(userPermissions.getPermissionTypeQName(), permission);
permissions.add(new SimplePermissionEntry(rNodeRef, permissionReference, authority, AccessStatus.ALLOWED));
}
for (String permission : toDeny) {
PermissionReference permissionReference = PermissionReferenceImpl.getPermissionReference(userPermissions.getPermissionTypeQName(), permission);
permissions.add(new SimplePermissionEntry(rNodeRef, permissionReference, authority, AccessStatus.DENIED));
}
return new SimpleNodePermissionEntry(rNodeRef, false, permissions);
}
use of org.alfresco.repo.security.permissions.PermissionEntry in project alfresco-repository by Alfresco.
the class AbstractPermissionsDaoComponentImpl method setPermission.
public void setPermission(NodePermissionEntry nodePermissionEntry) {
NodeRef nodeRef = nodePermissionEntry.getNodeRef();
// Get the access control list
// Note the logic here requires to know whether it was created or not
Acl existing = getAccessControlList(nodeRef);
if (existing != null) {
deletePermissions(nodeRef);
}
// create the access control list
existing = getAccessControlList(nodeRef);
CreationReport report = createAccessControlList(nodeRef, nodePermissionEntry.inheritPermissions(), existing);
// add all entries
for (PermissionEntry pe : nodePermissionEntry.getPermissionEntries()) {
SimpleAccessControlEntry entry = new SimpleAccessControlEntry();
entry.setAuthority(pe.getAuthority());
entry.setPermission(pe.getPermissionReference());
entry.setAccessStatus(pe.isAllowed() ? AccessStatus.ALLOWED : AccessStatus.DENIED);
entry.setAceType(ACEType.ALL);
entry.setPosition(Integer.valueOf(0));
List<AclChange> changes = aclDaoComponent.setAccessControlEntry(report.getCreated().getId(), entry);
List<AclChange> all = new ArrayList<AclChange>(changes.size() + report.getChanges().size());
all.addAll(report.getChanges());
all.addAll(changes);
getACLDAO(nodeRef).updateChangedAcls(nodeRef, all);
}
}
use of org.alfresco.repo.security.permissions.PermissionEntry in project alfresco-repository by Alfresco.
the class PermissionServiceTest method testSetPermissionEntryElements.
public void testSetPermissionEntryElements() {
// add andy-all (allow)
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());
}
// add andy-all (allow)
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());
// add other-all (allow)
permissionService.setPermission(rootNodeRef, "other", permissionService.getAllPermission(), true);
assertNotNull(permissionService.getSetPermissions(rootNodeRef));
assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
assertEquals(2, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
// add andy-all (deny)
permissionService.setPermission(rootNodeRef, "andy", permissionService.getAllPermission(), false);
assertNotNull(permissionService.getSetPermissions(rootNodeRef));
assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
assertEquals(2, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
// add andy-read (deny)
permissionService.setPermission(rootNodeRef, "andy", PermissionService.READ, false);
assertNotNull(permissionService.getSetPermissions(rootNodeRef));
assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
assertEquals(3, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
// remove andy-read
permissionService.deletePermission(rootNodeRef, "andy", PermissionService.READ);
assertNotNull(permissionService.getSetPermissions(rootNodeRef));
assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
assertEquals(2, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
// remove andy-all
permissionService.deletePermission(rootNodeRef, "andy", permissionService.getAllPermission());
assertNotNull(permissionService.getSetPermissions(rootNodeRef));
assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
assertEquals(1, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
// remove other-all
permissionService.deletePermission(rootNodeRef, "other", permissionService.getAllPermission());
assertNotNull(permissionService.getSetPermissions(rootNodeRef));
assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
assertEquals(0, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
}
use of org.alfresco.repo.security.permissions.PermissionEntry in project alfresco-repository by Alfresco.
the class VirtualPermissionServiceExtensionTest method mapPermissionsByName.
@SuppressWarnings("unchecked")
private Map<String, List<? extends PermissionEntry>> mapPermissionsByName(List<? extends PermissionEntry> entries) {
Map<String, List<? extends PermissionEntry>> nameMap = new HashMap<>();
for (PermissionEntry permissionEntry : entries) {
String name = permissionEntry.getPermissionReference().getName();
List<PermissionEntry> permissions = (List<PermissionEntry>) nameMap.get(name);
if (permissions == null) {
permissions = new ArrayList<>();
nameMap.put(name, permissions);
}
permissions.add(permissionEntry);
}
return nameMap;
}
Aggregations