use of org.alfresco.repo.security.permissions.PermissionEntry in project alfresco-repository by Alfresco.
the class PermissionServiceTest method testSetPermissionEntry.
public void testSetPermissionEntry() {
permissionService.setPermission(allowAndyAll);
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());
}
// Set duplicate
permissionService.setPermission(allowAndyAll);
assertNotNull(permissionService.getSetPermissions(rootNodeRef));
assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
assertEquals(1, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
// Set new
permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, permissionService.getAllPermissionReference(), "other", AccessStatus.ALLOWED));
assertNotNull(permissionService.getSetPermissions(rootNodeRef));
assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
assertEquals(2, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
// Deny
permissionService.setPermission(denyAndyAll);
assertNotNull(permissionService.getSetPermissions(rootNodeRef));
assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
assertEquals(2, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
// new
permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, new SimplePermissionReference(QName.createQName("A", "B"), "C"), "andy", AccessStatus.DENIED));
assertNotNull(permissionService.getSetPermissions(rootNodeRef));
assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
assertEquals(3, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
permissionService.deletePermission(new SimplePermissionEntry(rootNodeRef, new SimplePermissionReference(QName.createQName("A", "B"), "C"), "andy", AccessStatus.DENIED));
assertNotNull(permissionService.getSetPermissions(rootNodeRef));
assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
assertEquals(2, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
permissionService.deletePermission(denyAndyAll);
assertNotNull(permissionService.getSetPermissions(rootNodeRef));
assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
assertEquals(1, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
permissionService.deletePermission(new SimplePermissionEntry(rootNodeRef, permissionService.getAllPermissionReference(), "other", AccessStatus.ALLOWED));
assertNotNull(permissionService.getSetPermissions(rootNodeRef));
assertTrue(permissionService.getSetPermissions(rootNodeRef).inheritPermissions());
assertEquals(rootNodeRef, permissionService.getSetPermissions(rootNodeRef).getNodeRef());
assertEquals(0, permissionService.getSetPermissions(rootNodeRef).getPermissionEntries().size());
// delete when we know there's nothing do delete
permissionService.deletePermission(allowAndyAll);
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 PermissionServiceImpl method getAllSetPermissions.
@Override
@Extend(traitAPI = PermissionServiceTrait.class, extensionAPI = PermissionServiceExtension.class)
public Set<AccessPermission> getAllSetPermissions(NodeRef nodeRef) {
HashSet<AccessPermission> accessPermissions = new HashSet<AccessPermission>();
NodePermissionEntry nodePremissionEntry = getSetPermissions(nodeRef);
for (PermissionEntry pe : nodePremissionEntry.getPermissionEntries()) {
accessPermissions.add(new AccessPermissionImpl(getPermission(pe.getPermissionReference()), pe.getAccessStatus(), pe.getAuthority(), pe.getPosition()));
}
return accessPermissions;
}
use of org.alfresco.repo.security.permissions.PermissionEntry in project alfresco-repository by Alfresco.
the class PermissionServiceImpl method getAllSetPermissions.
@Override
@Extend(traitAPI = PermissionServiceTrait.class, extensionAPI = PermissionServiceExtension.class)
public Set<AccessPermission> getAllSetPermissions(StoreRef storeRef) {
HashSet<AccessPermission> accessPermissions = new HashSet<AccessPermission>();
NodePermissionEntry nodePremissionEntry = getSetPermissions(storeRef);
for (PermissionEntry pe : nodePremissionEntry.getPermissionEntries()) {
accessPermissions.add(new AccessPermissionImpl(getPermission(pe.getPermissionReference()), pe.getAccessStatus(), pe.getAuthority(), pe.getPosition()));
}
return accessPermissions;
}
use of org.alfresco.repo.security.permissions.PermissionEntry in project alfresco-repository by Alfresco.
the class VirtualPermissionServiceExtension method getSetPermissions.
@Override
public NodePermissionEntry getSetPermissions(NodeRef nodeRef) {
PermissionServiceTrait theTrait = getTrait();
Reference reference = Reference.fromNodeRef(nodeRef);
if (reference == null) {
return theTrait.getSetPermissions(nodeRef);
} else {
NodePermissionEntry virtualSetPermissions = smartStore.getSetPermissions(reference);
NodeRef nodeToAdhereTo = establishPermisisonAdherence(reference);
List<? extends PermissionEntry> actualPermissionEntries;
boolean inheritPermissions = false;
if (nodeToAdhereTo != null) {
NodePermissionEntry actualSetPermissions = theTrait.getSetPermissions(nodeToAdhereTo);
actualPermissionEntries = actualSetPermissions.getPermissionEntries();
inheritPermissions = actualSetPermissions.inheritPermissions();
} else {
actualPermissionEntries = Collections.emptyList();
inheritPermissions = false;
}
List<PermissionEntry> mergedEntries = new LinkedList<>();
List<? extends PermissionEntry> virtualPermissionEntries = virtualSetPermissions.getPermissionEntries();
Set<QName> overridenPermissions = new HashSet<>();
for (PermissionEntry permissionEntry : virtualPermissionEntries) {
overridenPermissions.add(permissionEntry.getPermissionReference().getQName());
mergedEntries.add(permissionEntry);
}
for (PermissionEntry permissionEntry : actualPermissionEntries) {
if (!overridenPermissions.contains(permissionEntry.getPermissionReference().getQName())) {
mergedEntries.add(permissionEntry);
}
}
return new SimpleNodePermissionEntry(nodeRef, inheritPermissions, mergedEntries);
}
}
use of org.alfresco.repo.security.permissions.PermissionEntry in project alfresco-repository by Alfresco.
the class VirtualPermissionServiceExtensionTest method assertUniquePermission.
/**
* Asserts that the permission with the given name uniquely found in the
* given permission entries list has the given access status for the given
* authority.
*
* @param permissionName
* @param accessStatus
* @param authority
* @param permissionEntries
*/
protected void assertUniquePermission(String permissionName, AccessStatus accessStatus, String authority, List<? extends PermissionEntry> permissionEntries) {
Map<String, List<? extends PermissionEntry>> entriesByName = mapPermissionsByName((List<? extends PermissionEntry>) permissionEntries);
assertNotNull("Not null permission " + permissionName + " expected.", entriesByName.get(permissionName));
assertEquals(1, entriesByName.get(permissionName).size());
PermissionEntry permission = entriesByName.get(permissionName).get(0);
assertEquals(accessStatus, permission.getAccessStatus());
assertEquals(authority, permission.getAuthority());
}
Aggregations