use of org.alfresco.service.cmr.security.AccessStatus in project records-management by Alfresco.
the class ExtendedPermissionServiceImplUnitTest method preProcessorDoesNotDeny.
/**
* Given a permission pre-processor has been registered
* And does not DENY
* When hasPermission is called
* Then the pre-processor is executed
* And the ACL's are evaluated as normal
*/
@Test
public void preProcessorDoesNotDeny() {
NodeRef nodeRef = generateCmContent("anyname");
String perm = AlfMock.generateText();
when(mockedPermissionProcessorRegistry.getPermissionPreProcessors()).thenReturn(asList(mockedPermissionPreProcessor));
when(mockedPermissionPreProcessor.process(nodeRef, perm)).thenReturn(AccessStatus.UNDETERMINED);
AccessStatus result = extendedPermissionServiceImpl.hasPermission(nodeRef, perm);
assertEquals(AccessStatus.UNDETERMINED, result);
verify(mockedPermissionPreProcessor).process(nodeRef, perm);
verify(extendedPermissionServiceImpl).hasPermissionImpl(nodeRef, perm);
}
use of org.alfresco.service.cmr.security.AccessStatus in project records-management by Alfresco.
the class ExtendedPermissionServiceImplUnitTest method postProcessorRegistered.
/**
* Given a permission post-processor has been registered
* When hasPermission is called
* Then the permission post-processor is called
*/
@Test
public void postProcessorRegistered() {
NodeRef nodeRef = generateCmContent("anyname");
String perm = AlfMock.generateText();
List<String> configuredReadPermissions = asList("ReadProperties", "ReadChildren");
List<String> configuredFilePermissions = asList("WriteProperties", "AddChildren");
extendedPermissionServiceImpl.setConfiguredReadPermissions("ReadProperties,ReadChildren");
extendedPermissionServiceImpl.setConfiguredFilePermissions("WriteProperties,AddChildren");
when(mockedPermissionProcessorRegistry.getPermissionPostProcessors()).thenReturn(asList(mockedPermissionPostProcessor));
when(mockedPermissionPostProcessor.process(AccessStatus.UNDETERMINED, nodeRef, perm, configuredReadPermissions, configuredFilePermissions)).thenReturn(AccessStatus.ALLOWED);
AccessStatus result = extendedPermissionServiceImpl.hasPermission(nodeRef, perm);
assertEquals(AccessStatus.ALLOWED, result);
verify(mockedPermissionPostProcessor).process(AccessStatus.UNDETERMINED, nodeRef, perm, configuredReadPermissions, configuredFilePermissions);
verify(extendedPermissionServiceImpl).hasPermissionImpl(nodeRef, perm);
}
use of org.alfresco.service.cmr.security.AccessStatus 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);
}
use of org.alfresco.service.cmr.security.AccessStatus in project records-management by Alfresco.
the class CapabilityServiceImpl method getCapabilitiesAccessState.
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService#getCapabilitiesAccessState(org.alfresco.service.cmr.repository.NodeRef, java.util.List)
*/
public Map<Capability, AccessStatus> getCapabilitiesAccessState(NodeRef nodeRef, List<String> capabilityNames) {
ParameterCheck.mandatory("nodeRef", nodeRef);
ParameterCheck.mandatory("capabilityNames", capabilityNames);
HashMap<Capability, AccessStatus> answer = new HashMap<Capability, AccessStatus>();
for (String capabilityName : capabilityNames) {
Capability capability = capabilities.get(capabilityName);
if (capability != null) {
AccessStatus status = capability.hasPermission(nodeRef);
if (answer.put(capability, status) != null) {
throw new IllegalStateException();
}
}
}
return answer;
}
use of org.alfresco.service.cmr.security.AccessStatus in project records-management by Alfresco.
the class ExtendedPermissionServiceImpl method hasPermission.
/**
* Override to deal with the possibility of hard coded permission checks in core code. Note: Eventually we need to
* merge the RM permission model into the core to make this more robust.
*
* @see org.alfresco.repo.security.permissions.impl.ExtendedPermissionService#hasPermission(org.alfresco.service.cmr.repository.NodeRef,
* java.lang.String)
*/
@Override
public AccessStatus hasPermission(NodeRef nodeRef, String perm) {
AccessStatus result = AccessStatus.UNDETERMINED;
if (nodeService.exists(nodeRef)) {
// permission pre-processors
List<PermissionPreProcessor> preProcessors = permissionProcessorRegistry.getPermissionPreProcessors();
for (PermissionPreProcessor preProcessor : preProcessors) {
// pre process permission
result = preProcessor.process(nodeRef, perm);
// veto if denied
if (AccessStatus.DENIED.equals(result)) {
return result;
}
}
// evaluate permission
result = hasPermissionImpl(nodeRef, perm);
// permission post-processors
List<PermissionPostProcessor> postProcessors = permissionProcessorRegistry.getPermissionPostProcessors();
for (PermissionPostProcessor postProcessor : postProcessors) {
// post process permission
result = postProcessor.process(result, nodeRef, perm, this.configuredReadPermissions, this.configuredFilePermissions);
}
}
return result;
}
Aggregations