Search in sources :

Example 1 with PermissionReference

use of org.alfresco.repo.security.permissions.PermissionReference in project records-management by Alfresco.

the class RecordsManagementPermissionPostProcessorUnitTest method permissionInherittedFromConfiguredGroup.

/**
 * Test that the permission groups configured in the global properties file imply descendant permission groups.
 * <p>
 * Given a configured permission is an ancestor of another permission P
 * And the post processor checks if the user has P
 * Then the post processor says that they do.
 */
@Test
public void permissionInherittedFromConfiguredGroup() {
    NodeRef nodeRef = new NodeRef("node://ref/");
    // permissions do not include perm created above
    List<String> configuredReadPermissions = asList();
    List<String> configuredFilePermissions = asList("WriteProperties");
    when(mockNodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_FILE_PLAN_COMPONENT)).thenReturn(true);
    when(mockPermissionService.hasPermission(nodeRef, RMPermissionModel.FILE_RECORDS)).thenReturn(AccessStatus.ALLOWED);
    // Set up "WriteProperties" to imply three other permission groups.
    PermissionReference mockWritePropsPermRef = mock(PermissionReference.class);
    when(mockPermissionModel.getPermissionReference(null, "WriteProperties")).thenReturn(mockWritePropsPermRef);
    PermissionReference childOne = mock(PermissionReference.class);
    when(childOne.getName()).thenReturn("Not this one");
    PermissionReference childTwo = mock(PermissionReference.class);
    when(childTwo.getName()).thenReturn("This is the requested permission");
    PermissionReference childThree = mock(PermissionReference.class);
    when(childThree.getName()).thenReturn("Not this one either");
    when(mockPermissionModel.getGranteePermissions(mockWritePropsPermRef)).thenReturn(Sets.newHashSet(childOne, childTwo, childThree));
    // Call the method under test.
    AccessStatus result = recordsManagementPermissionPostProcessor.process(AccessStatus.DENIED, nodeRef, "This is the requested permission", configuredReadPermissions, configuredFilePermissions);
    assertEquals(AccessStatus.ALLOWED, result);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) PermissionReference(org.alfresco.repo.security.permissions.PermissionReference) AccessStatus(org.alfresco.service.cmr.security.AccessStatus) Test(org.junit.Test)

Aggregations

PermissionReference (org.alfresco.repo.security.permissions.PermissionReference)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 AccessStatus (org.alfresco.service.cmr.security.AccessStatus)1 Test (org.junit.Test)1