use of org.alfresco.module.org_alfresco_module_rm.model.security.ModelAccessDeniedException in project records-management by Alfresco.
the class RecordServiceImpl method onUpdateProperties.
/**
* Ensure that the user only updates record properties that they have permission to.
*
* @see org.alfresco.repo.node.NodeServicePolicies.OnUpdatePropertiesPolicy#onUpdateProperties(org.alfresco.service.cmr.repository.NodeRef, java.util.Map, java.util.Map)
*/
@Override
@Behaviour(name = "onUpdateProperties", kind = BehaviourKind.CLASS, type = "rma:record")
public void onUpdateProperties(final NodeRef nodeRef, final Map<QName, Serializable> before, final Map<QName, Serializable> after) {
if (AuthenticationUtil.getFullyAuthenticatedUser() != null && !AuthenticationUtil.isRunAsUserTheSystemUser() && nodeService.exists(nodeRef) && isRecord(nodeRef) && !transactionalResourceHelper.getSet(KEY_IGNORE_ON_UPDATE).contains(nodeRef)) {
for (Map.Entry<QName, Serializable> entry : after.entrySet()) {
Serializable beforeValue = null;
QName property = entry.getKey();
if (before != null) {
beforeValue = before.get(property);
}
Serializable afterValue = entry.getValue();
boolean propertyUnchanged = false;
if (beforeValue instanceof Date && afterValue instanceof Date) {
// deal with date values, remove the seconds and milliseconds for the
// comparison as they are removed from the submitted for data
Calendar beforeCal = Calendar.getInstance();
beforeCal.setTime((Date) beforeValue);
Calendar afterCal = Calendar.getInstance();
afterCal.setTime((Date) afterValue);
beforeCal.set(Calendar.SECOND, 0);
beforeCal.set(Calendar.MILLISECOND, 0);
afterCal.set(Calendar.SECOND, 0);
afterCal.set(Calendar.MILLISECOND, 0);
propertyUnchanged = (beforeCal.compareTo(afterCal) == 0);
} else if ((afterValue instanceof Boolean) && (beforeValue == null) && (afterValue.equals(Boolean.FALSE))) {
propertyUnchanged = true;
} else {
// otherwise
propertyUnchanged = EqualsHelper.nullSafeEquals(beforeValue, afterValue);
}
if (!propertyUnchanged && !(ContentModel.PROP_CONTENT.equals(property) && beforeValue == null) && !isPropertyEditable(nodeRef, property)) {
// the user can't edit the record property
throw new ModelAccessDeniedException("The user " + AuthenticationUtil.getFullyAuthenticatedUser() + " does not have the permission to edit the record property " + property.toString() + " on the node " + nodeRef.toString());
}
}
}
}
Aggregations