use of org.alfresco.service.cmr.security.AccessStatus in project records-management by Alfresco.
the class RMSecurityCommon method hasViewCapability.
/**
* Helper method to determine whether the current user has view capability on the file plan
*
* @param filePlan file plan
* @return {@link AccessStatus}
*/
private AccessStatus hasViewCapability(NodeRef filePlan) {
Map<Pair<String, NodeRef>, AccessStatus> transactionCache = TransactionalResourceHelper.getMap("rm.security.hasViewCapability");
Pair<String, NodeRef> key = new Pair<String, NodeRef>(AuthenticationUtil.getRunAsUser(), filePlan);
if (transactionCache.containsKey(key)) {
return transactionCache.get(key);
} else {
AccessStatus result = permissionService.hasPermission(filePlan, ViewRecordsCapability.NAME);
transactionCache.put(key, result);
return result;
}
}
use of org.alfresco.service.cmr.security.AccessStatus in project records-management by Alfresco.
the class RecordsManagementPermissionPostProcessorUnitTest method configurePermissionsDenied.
/**
* Given the configured permissions are not set
* When process is called
* Then access is denied
*/
@Test
public void configurePermissionsDenied() {
AccessStatus accessStatus = AccessStatus.DENIED;
NodeRef nodeRef = new NodeRef("node://ref/");
String perm = AlfMock.generateText();
// permissions do not include perm created above
List<String> configuredReadPermissions = asList("ReadProperties", "ReadChildren");
List<String> configuredFilePermissions = asList("WriteProperties", "AddChildren");
when(mockNodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_FILE_PLAN_COMPONENT)).thenReturn(true);
when(mockPermissionService.hasPermission(nodeRef, RMPermissionModel.READ_RECORDS)).thenReturn(AccessStatus.ALLOWED);
AccessStatus result = recordsManagementPermissionPostProcessor.process(accessStatus, nodeRef, perm, configuredReadPermissions, configuredFilePermissions);
assertEquals(AccessStatus.DENIED, result);
}
use of org.alfresco.service.cmr.security.AccessStatus in project records-management by Alfresco.
the class RecordsManagementPermissionPostProcessorUnitTest method configurePermissionsAllowed.
/**
* Given the configured permissions are set
* When process is called
* Then access is allowed
*/
@Test
public void configurePermissionsAllowed() {
AccessStatus accessStatus = AccessStatus.DENIED;
NodeRef nodeRef = new NodeRef("node://ref/");
String perm = AlfMock.generateText();
// permissions includes the perm created above
List<String> configuredReadPermissions = asList("ReadProperties", "ReadChildren", perm);
List<String> configuredFilePermissions = asList("WriteProperties", "AddChildren");
when(mockNodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_FILE_PLAN_COMPONENT)).thenReturn(true);
when(mockPermissionService.hasPermission(nodeRef, RMPermissionModel.READ_RECORDS)).thenReturn(AccessStatus.ALLOWED);
AccessStatus result = recordsManagementPermissionPostProcessor.process(accessStatus, nodeRef, perm, configuredReadPermissions, configuredFilePermissions);
assertEquals(AccessStatus.ALLOWED, result);
}
use of org.alfresco.service.cmr.security.AccessStatus in project records-management by Alfresco.
the class ExtendedPermissionServiceImplUnitTest method preProcessorDenys.
/**
* Given a permission pre-processor has been registered
* And DENY's
* When hasPermission is called
* Then the pre-processor is executed
* And the remaining permission evaluations do not take place
*/
@Test
public void preProcessorDenys() {
NodeRef nodeRef = generateCmContent("anyname");
String perm = AlfMock.generateText();
when(mockedPermissionProcessorRegistry.getPermissionPreProcessors()).thenReturn(asList(mockedPermissionPreProcessor));
when(mockedPermissionPreProcessor.process(nodeRef, perm)).thenReturn(AccessStatus.DENIED);
AccessStatus result = extendedPermissionServiceImpl.hasPermission(nodeRef, perm);
assertEquals(AccessStatus.DENIED, result);
verify(mockedPermissionPreProcessor).process(nodeRef, perm);
verify(extendedPermissionServiceImpl, never()).hasPermissionImpl(nodeRef, perm);
}
use of org.alfresco.service.cmr.security.AccessStatus in project records-management by Alfresco.
the class RmSubstitutionSuggestionsGet method isNodeRefAppropriateForPathSuggestion.
/**
* Identifies record category and record folder types of nodeRef
*
* @param nodeRef Instance of NodeRef to be tested
* @return True if the passed NodeRef instance is a record category or record folder
*/
private boolean isNodeRefAppropriateForPathSuggestion(NodeRef nodeRef, boolean unfiled) {
// check node type
QName type = nodeService.getType(nodeRef);
boolean isCorrectType = (!unfiled && (RecordsManagementModel.TYPE_RECORD_FOLDER.equals(type) || RecordsManagementModel.TYPE_RECORD_CATEGORY.equals(type)) || (unfiled && RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER.equals(type)));
// check permissions
boolean canView = false;
if (isCorrectType) {
Capability createCapability = capabilityService.getCapability(CREATE_CAPABILITY);
Capability viewCapability = capabilityService.getCapability(VIEW_CAPABILITY);
if ((createCapability != null) && (viewCapability != null)) {
List<String> requiredCapabilities = new ArrayList<String>();
requiredCapabilities.add(CREATE_CAPABILITY);
requiredCapabilities.add(VIEW_CAPABILITY);
Map<Capability, AccessStatus> map = capabilityService.getCapabilitiesAccessState(nodeRef, requiredCapabilities);
if (map.containsKey(createCapability) && map.containsKey(viewCapability)) {
AccessStatus createAccessStatus = map.get(createCapability);
AccessStatus viewAccessStatus = map.get(viewCapability);
if (createAccessStatus.equals(AccessStatus.ALLOWED) && viewAccessStatus.equals(AccessStatus.ALLOWED)) {
canView = true;
}
}
}
}
return isCorrectType && canView;
}
Aggregations