mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
RM-2396 (Upload record via WebDAV fails with org.alfresco.repo.security.permissions.AccessDeniedException)
This commit is contained in:
@@ -29,6 +29,9 @@ package org.alfresco.module.org_alfresco_module_rm.record;
|
|||||||
|
|
||||||
import static com.google.common.collect.Lists.newArrayList;
|
import static com.google.common.collect.Lists.newArrayList;
|
||||||
|
|
||||||
|
import static org.alfresco.repo.policy.Behaviour.NotificationFrequency.FIRST_EVENT;
|
||||||
|
import static org.alfresco.repo.policy.annotation.BehaviourKind.ASSOCIATION;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -70,9 +73,7 @@ import org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityServi
|
|||||||
import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionModel;
|
import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionModel;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService;
|
import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService;
|
||||||
import org.alfresco.repo.node.NodeServicePolicies;
|
import org.alfresco.repo.node.NodeServicePolicies;
|
||||||
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
|
|
||||||
import org.alfresco.repo.policy.ClassPolicyDelegate;
|
import org.alfresco.repo.policy.ClassPolicyDelegate;
|
||||||
import org.alfresco.repo.policy.JavaBehaviour;
|
|
||||||
import org.alfresco.repo.policy.PolicyComponent;
|
import org.alfresco.repo.policy.PolicyComponent;
|
||||||
import org.alfresco.repo.policy.annotation.Behaviour;
|
import org.alfresco.repo.policy.annotation.Behaviour;
|
||||||
import org.alfresco.repo.policy.annotation.BehaviourBean;
|
import org.alfresco.repo.policy.annotation.BehaviourBean;
|
||||||
@@ -84,16 +85,13 @@ import org.alfresco.repo.security.permissions.impl.ExtendedPermissionService;
|
|||||||
import org.alfresco.service.cmr.dictionary.AspectDefinition;
|
import org.alfresco.service.cmr.dictionary.AspectDefinition;
|
||||||
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||||
import org.alfresco.service.cmr.model.FileExistsException;
|
|
||||||
import org.alfresco.service.cmr.model.FileFolderService;
|
import org.alfresco.service.cmr.model.FileFolderService;
|
||||||
import org.alfresco.service.cmr.model.FileInfo;
|
import org.alfresco.service.cmr.model.FileInfo;
|
||||||
import org.alfresco.service.cmr.model.FileNotFoundException;
|
import org.alfresco.service.cmr.model.FileNotFoundException;
|
||||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||||
import org.alfresco.service.cmr.repository.ContentData;
|
|
||||||
import org.alfresco.service.cmr.repository.ContentReader;
|
import org.alfresco.service.cmr.repository.ContentReader;
|
||||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.rule.RuleService;
|
import org.alfresco.service.cmr.rule.RuleService;
|
||||||
import org.alfresco.service.cmr.security.AccessPermission;
|
import org.alfresco.service.cmr.security.AccessPermission;
|
||||||
@@ -128,7 +126,6 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
|||||||
RecordsManagementModel,
|
RecordsManagementModel,
|
||||||
RecordsManagementCustomModel,
|
RecordsManagementCustomModel,
|
||||||
NodeServicePolicies.OnCreateChildAssociationPolicy,
|
NodeServicePolicies.OnCreateChildAssociationPolicy,
|
||||||
NodeServicePolicies.OnAddAspectPolicy,
|
|
||||||
NodeServicePolicies.OnRemoveAspectPolicy,
|
NodeServicePolicies.OnRemoveAspectPolicy,
|
||||||
NodeServicePolicies.OnUpdatePropertiesPolicy
|
NodeServicePolicies.OnUpdatePropertiesPolicy
|
||||||
{
|
{
|
||||||
@@ -137,7 +134,6 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
|||||||
|
|
||||||
/** transation data key */
|
/** transation data key */
|
||||||
private static final String KEY_IGNORE_ON_UPDATE = "ignoreOnUpdate";
|
private static final String KEY_IGNORE_ON_UPDATE = "ignoreOnUpdate";
|
||||||
private static final String KEY_PENDING_FILLING = "pendingFilling";
|
|
||||||
public static final String KEY_NEW_RECORDS = "newRecords";
|
public static final String KEY_NEW_RECORDS = "newRecords";
|
||||||
|
|
||||||
/** I18N */
|
/** I18N */
|
||||||
@@ -249,12 +245,6 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
|||||||
private ClassPolicyDelegate<BeforeFileRecord> beforeFileRecord;
|
private ClassPolicyDelegate<BeforeFileRecord> beforeFileRecord;
|
||||||
private ClassPolicyDelegate<OnFileRecord> onFileRecord;
|
private ClassPolicyDelegate<OnFileRecord> onFileRecord;
|
||||||
|
|
||||||
/** Behaviours */
|
|
||||||
private JavaBehaviour onCreateChildAssociation = new JavaBehaviour(
|
|
||||||
this,
|
|
||||||
"onCreateChildAssociation",
|
|
||||||
NotificationFrequency.FIRST_EVENT);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param identifierService identifier service
|
* @param identifierService identifier service
|
||||||
*/
|
*/
|
||||||
@@ -407,13 +397,6 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
|||||||
// bind policies
|
// bind policies
|
||||||
beforeFileRecord = policyComponent.registerClassPolicy(BeforeFileRecord.class);
|
beforeFileRecord = policyComponent.registerClassPolicy(BeforeFileRecord.class);
|
||||||
onFileRecord = policyComponent.registerClassPolicy(OnFileRecord.class);
|
onFileRecord = policyComponent.registerClassPolicy(OnFileRecord.class);
|
||||||
|
|
||||||
// bind behaviours
|
|
||||||
policyComponent.bindAssociationBehaviour(
|
|
||||||
NodeServicePolicies.OnCreateChildAssociationPolicy.QNAME,
|
|
||||||
TYPE_RECORD_FOLDER,
|
|
||||||
ContentModel.ASSOC_CONTAINS,
|
|
||||||
onCreateChildAssociation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -427,82 +410,41 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
|||||||
)
|
)
|
||||||
public void onRemoveAspect(NodeRef nodeRef, QName aspect)
|
public void onRemoveAspect(NodeRef nodeRef, QName aspect)
|
||||||
{
|
{
|
||||||
|
if (nodeService.hasAspect(nodeRef, ASPECT_RECORD) && !nodeService.hasAspect(nodeRef, ContentModel.ASPECT_HIDDEN))
|
||||||
if (nodeService.hasAspect(nodeRef, ASPECT_RECORD))
|
|
||||||
{
|
{
|
||||||
ContentData contentData = (ContentData) nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
|
// get the record id
|
||||||
|
String recordId = (String) nodeService.getProperty(nodeRef, PROP_IDENTIFIER);
|
||||||
|
|
||||||
// Only switch name back to the format of "name (identifierId)" if content size is non-zero, else leave it as the original name to avoid CIFS shuffling issues.
|
// get the record name
|
||||||
if (contentData != null && contentData.getSize() > 0)
|
String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
|
||||||
|
|
||||||
|
// rename the record
|
||||||
|
int dotIndex = name.lastIndexOf('.');
|
||||||
|
String prefix = name;
|
||||||
|
String postfix = "";
|
||||||
|
if (dotIndex > 0)
|
||||||
{
|
{
|
||||||
switchNames(nodeRef);
|
prefix = name.substring(0, dotIndex);
|
||||||
|
postfix = name.substring(dotIndex);
|
||||||
}
|
}
|
||||||
}
|
String recordName = prefix + " (" + recordId + ")" + postfix;
|
||||||
else
|
behaviourFilter.disableBehaviour();
|
||||||
{
|
try
|
||||||
// check whether filling is pending aspect removal
|
|
||||||
Set<NodeRef> pendingFilling = transactionalResourceHelper.getSet(KEY_PENDING_FILLING);
|
|
||||||
if (pendingFilling.contains(nodeRef))
|
|
||||||
{
|
{
|
||||||
file(nodeRef);
|
fileFolderService.rename(nodeRef, recordName);
|
||||||
}
|
}
|
||||||
}
|
catch (FileNotFoundException e)
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see org.alfresco.repo.node.NodeServicePolicies.OnAddAspectPolicy#onAddAspect(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@Behaviour
|
|
||||||
(
|
|
||||||
kind = BehaviourKind.CLASS,
|
|
||||||
type = "sys:noContent"
|
|
||||||
)
|
|
||||||
public void onAddAspect(NodeRef nodeRef, QName aspect)
|
|
||||||
{
|
|
||||||
switchNames(nodeRef);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper method to switch the name of the record around. Used to support record creation via
|
|
||||||
* file protocols.
|
|
||||||
*
|
|
||||||
* @param nodeRef node reference (record)
|
|
||||||
*/
|
|
||||||
private void switchNames(NodeRef nodeRef)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (nodeService.hasAspect(nodeRef, ASPECT_RECORD))
|
|
||||||
{
|
{
|
||||||
String origionalName = (String)nodeService.getProperty(nodeRef, PROP_ORIGIONAL_NAME);
|
throw new AlfrescoRuntimeException("Unable to make record, because rename failed.", e);
|
||||||
if (origionalName != null)
|
|
||||||
{
|
|
||||||
String name = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
|
|
||||||
fileFolderService.rename(nodeRef, origionalName);
|
|
||||||
nodeService.setProperty(nodeRef, PROP_ORIGIONAL_NAME, name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
finally
|
||||||
catch (FileExistsException e)
|
{
|
||||||
{
|
behaviourFilter.enableBehaviour();
|
||||||
|
}
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
logger.debug(e.getMessage());
|
logger.debug("Rename " + name + " to " + recordName);
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (InvalidNodeRefException e)
|
|
||||||
{
|
|
||||||
if (logger.isDebugEnabled())
|
|
||||||
{
|
|
||||||
logger.debug(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (FileNotFoundException e)
|
|
||||||
{
|
|
||||||
if (logger.isDebugEnabled())
|
|
||||||
{
|
|
||||||
logger.debug(e.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -513,6 +455,12 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
|||||||
* @see org.alfresco.repo.node.NodeServicePolicies.OnCreateChildAssociationPolicy#onCreateChildAssociation(org.alfresco.service.cmr.repository.ChildAssociationRef, boolean)
|
* @see org.alfresco.repo.node.NodeServicePolicies.OnCreateChildAssociationPolicy#onCreateChildAssociation(org.alfresco.service.cmr.repository.ChildAssociationRef, boolean)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Behaviour
|
||||||
|
(
|
||||||
|
kind = ASSOCIATION,
|
||||||
|
type = "rma:recordFolder",
|
||||||
|
notificationFrequency = FIRST_EVENT
|
||||||
|
)
|
||||||
public void onCreateChildAssociation(final ChildAssociationRef childAssocRef, final boolean bNew)
|
public void onCreateChildAssociation(final ChildAssociationRef childAssocRef, final boolean bNew)
|
||||||
{
|
{
|
||||||
AuthenticationUtil.runAs(new RunAsWork<Void>()
|
AuthenticationUtil.runAs(new RunAsWork<Void>()
|
||||||
@@ -520,7 +468,6 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
|||||||
@Override
|
@Override
|
||||||
public Void doWork()
|
public Void doWork()
|
||||||
{
|
{
|
||||||
onCreateChildAssociation.disable();
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
NodeRef nodeRef = childAssocRef.getChildRef();
|
NodeRef nodeRef = childAssocRef.getChildRef();
|
||||||
@@ -529,38 +476,29 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
|||||||
!nodeService.getType(nodeRef).equals(TYPE_RECORD_FOLDER) &&
|
!nodeService.getType(nodeRef).equals(TYPE_RECORD_FOLDER) &&
|
||||||
!nodeService.getType(nodeRef).equals(TYPE_RECORD_CATEGORY))
|
!nodeService.getType(nodeRef).equals(TYPE_RECORD_CATEGORY))
|
||||||
{
|
{
|
||||||
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_NO_CONTENT))
|
// store information about the 'new' record in the transaction
|
||||||
|
// @since 2.3
|
||||||
|
// @see https://issues.alfresco.com/jira/browse/RM-1956
|
||||||
|
if (bNew)
|
||||||
{
|
{
|
||||||
// we need to postpone filling until the NO_CONTENT aspect is removed
|
Set<NodeRef> newRecords = transactionalResourceHelper.getSet(KEY_NEW_RECORDS);
|
||||||
Set<NodeRef> pendingFilling = transactionalResourceHelper.getSet(KEY_PENDING_FILLING);
|
newRecords.add(nodeRef);
|
||||||
pendingFilling.add(nodeRef);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// store information about the 'new' record in the transaction
|
// if we are linking a record
|
||||||
// @since 2.3
|
NodeRef parentNodeRef = childAssocRef.getParentRef();
|
||||||
// @see https://issues.alfresco.com/jira/browse/RM-1956
|
if (isRecord(nodeRef) && isRecordFolder(parentNodeRef))
|
||||||
if (bNew)
|
|
||||||
{
|
{
|
||||||
Set<NodeRef> newRecords = transactionalResourceHelper.getSet(KEY_NEW_RECORDS);
|
// validate the link conditions
|
||||||
newRecords.add(nodeRef);
|
validateLinkConditions(nodeRef, parentNodeRef);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// if we are linking a record
|
|
||||||
NodeRef parentNodeRef = childAssocRef.getParentRef();
|
|
||||||
if (isRecord(nodeRef) && isRecordFolder(parentNodeRef))
|
|
||||||
{
|
|
||||||
// validate the link conditions
|
|
||||||
validateLinkConditions(nodeRef, parentNodeRef);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// create and file the content as a record
|
|
||||||
file(nodeRef);
|
|
||||||
// recalculate disposition schedule for the record when linking it
|
|
||||||
dispositionService.recalculateNextDispositionStep(nodeRef);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create and file the content as a record
|
||||||
|
file(nodeRef);
|
||||||
|
// recalculate disposition schedule for the record when linking it
|
||||||
|
dispositionService.recalculateNextDispositionStep(nodeRef);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (RecordLinkRuntimeException e)
|
catch (RecordLinkRuntimeException e)
|
||||||
@@ -576,10 +514,6 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
|||||||
logger.warn("Unable to file pending record.", e);
|
logger.warn("Unable to file pending record.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
onCreateChildAssociation.enable();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -1184,31 +1118,6 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
|||||||
// get the record name
|
// get the record name
|
||||||
String name = (String)nodeService.getProperty(document, ContentModel.PROP_NAME);
|
String name = (String)nodeService.getProperty(document, ContentModel.PROP_NAME);
|
||||||
|
|
||||||
// rename the record
|
|
||||||
int dotIndex = name.lastIndexOf('.');
|
|
||||||
String prefix = name;
|
|
||||||
String postfix = "";
|
|
||||||
if (dotIndex != -1)
|
|
||||||
{
|
|
||||||
prefix = name.substring(0, dotIndex);
|
|
||||||
postfix = name.substring(dotIndex);
|
|
||||||
}
|
|
||||||
String recordName = prefix + " (" + recordId + ")" + postfix;
|
|
||||||
behaviourFilter.disableBehaviour();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
fileFolderService.rename(document, recordName);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
behaviourFilter.enableBehaviour();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
|
||||||
{
|
|
||||||
logger.debug("Rename " + name + " to " + recordName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// add the record aspect
|
// add the record aspect
|
||||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>(2);
|
Map<QName, Serializable> props = new HashMap<QName, Serializable>(2);
|
||||||
props.put(PROP_IDENTIFIER, recordId);
|
props.put(PROP_IDENTIFIER, recordId);
|
||||||
@@ -1221,10 +1130,6 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
|||||||
// remove the owner
|
// remove the owner
|
||||||
ownableService.setOwner(document, OwnableService.NO_OWNER);
|
ownableService.setOwner(document, OwnableService.NO_OWNER);
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException e)
|
|
||||||
{
|
|
||||||
throw new AlfrescoRuntimeException("Unable to make record, because rename failed.", e);
|
|
||||||
}
|
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
ruleService.enableRules();
|
ruleService.enableRules();
|
||||||
|
Reference in New Issue
Block a user