MT fix to ensure behaviour is triggered. Also fixes AR-1745.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6782 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2007-09-14 08:30:44 +00:00
parent fc1533b4a3
commit f68cccd7b6
6 changed files with 56 additions and 74 deletions

View File

@@ -35,6 +35,7 @@ import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.policy.PolicyScope;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
@@ -65,6 +66,7 @@ public class AuditableAspect
private NodeService nodeService;
private AuthenticationService authenticationService;
private PolicyComponent policyComponent;
private TenantService tenantService;
// Behaviours
private Behaviour onCreateAudit;
@@ -96,6 +98,15 @@ public class AuditableAspect
this.authenticationService = authenticationService;
}
/**
* @param tenantService the tenant service
*/
public void setTenantService(TenantService tenantService)
{
this.tenantService = tenantService;
}
/**
* Initialise the Auditable Aspect
*/
@@ -155,7 +166,9 @@ public class AuditableAspect
{
// Set the updated property values (but do not cascade to update audit behaviour)
onUpdateAudit.disable();
AuthenticationUtil.runAs(new SetAuditProperties(nodeService, nodeRef, properties), AuthenticationUtil.getSystemUserName());
// note: special MT case - need to run in context of user's domain ... although checkForLock requires System
AuthenticationUtil.runAs(new SetAuditProperties(nodeService, nodeRef, properties), tenantService.getDomainUser(AuthenticationUtil.getSystemUserName(), tenantService.getCurrentUserDomain()));
}
finally
{
@@ -187,7 +200,9 @@ public class AuditableAspect
properties.put(ContentModel.PROP_MODIFIER, modifier);
// Set the updated property values
AuthenticationUtil.runAs(new SetAuditProperties(nodeService, nodeRef, properties), AuthenticationUtil.getSystemUserName());
// note: special MT case - need to run in context of user's domain ... although checkForLock requires System
AuthenticationUtil.runAs(new SetAuditProperties(nodeService, nodeRef, properties), tenantService.getDomainUser(AuthenticationUtil.getSystemUserName(), tenantService.getCurrentUserDomain()));
if (logger.isDebugEnabled())
logger.debug("Auditable node " + nodeRef + " updated [modified=" + now + ";modifier=" + modifier + "]");

View File

@@ -346,58 +346,42 @@ public class DictionaryDAOImpl implements DictionaryDAO
String tenantDomain = tenantService.getCurrentUserDomain();
if (tenantDomain != "")
{
// note: special case, if running as System - e.g. addAuditAspect
String currentUserName = AuthenticationUtil.getCurrentUserName();
// get non-tenant models (if any)
List<CompiledModel> models = getUriToModels("").get(uri);
if (currentUserName != null)
List<CompiledModel> filteredModels = new ArrayList<CompiledModel>();
if (models != null)
{
if ((tenantService.isTenantUser(currentUserName)) ||
(currentUserName.equals(AuthenticationUtil.getSystemUserName()) && tenantService.isTenantName(uri)))
{
if (currentUserName.equals(AuthenticationUtil.getSystemUserName()))
{
tenantDomain = tenantService.getDomain(uri);
}
uri = tenantService.getBaseName(uri, true);
// get non-tenant models (if any)
List<CompiledModel> models = getUriToModels("").get(uri);
List<CompiledModel> filteredModels = new ArrayList<CompiledModel>();
if (models != null)
{
filteredModels.addAll(models);
}
// get tenant models (if any)
List<CompiledModel> tenantModels = getUriToModels(tenantDomain).get(uri);
if (tenantModels != null)
{
if (models != null)
{
// check to see if tenant model overrides a non-tenant model
for (CompiledModel tenantModel : tenantModels)
{
for (CompiledModel model : models)
{
if (tenantModel.getM2Model().getName().equals(model.getM2Model().getName()))
{
filteredModels.remove(model);
}
}
}
}
filteredModels.addAll(tenantModels);
models = filteredModels;
}
if (models == null)
{
models = Collections.emptyList();
}
return models;
}
filteredModels.addAll(models);
}
// get tenant models (if any)
List<CompiledModel> tenantModels = getUriToModels(tenantDomain).get(uri);
if (tenantModels != null)
{
if (models != null)
{
// check to see if tenant model overrides a non-tenant model
for (CompiledModel tenantModel : tenantModels)
{
for (CompiledModel model : models)
{
if (tenantModel.getM2Model().getName().equals(model.getM2Model().getName()))
{
filteredModels.remove(model);
}
}
}
}
filteredModels.addAll(tenantModels);
models = filteredModels;
}
if (models == null)
{
models = Collections.emptyList();
}
return models;
}
List<CompiledModel> models = getUriToModels().get(uri);
@@ -553,10 +537,6 @@ public class DictionaryDAOImpl implements DictionaryDAO
public ClassDefinition getClass(QName className)
{
List<CompiledModel> models = getModelsForUri(className.getNamespaceURI());
// note: special case, if running as System - e.g. addAuditAspect
// now force, even for System user
className = tenantService.getBaseName(className, true);
for (CompiledModel model : models)
{

View File

@@ -474,8 +474,8 @@ public class LockServiceImpl implements LockService,
// Ensure we have found a node reference
if (nodeRef != null && userName != null)
{
// Check to see if should just ignore this node
if (!(this.ignoreNodeRefs.contains(nodeRef) || userName.equals(AuthenticationUtil.getSystemUserName())))
// Check to see if should just ignore this node - note: special MT System due to AuditableAspect
if (!(this.ignoreNodeRefs.contains(nodeRef) || tenantService.getBaseNameUser(userName).equals(AuthenticationUtil.getSystemUserName())))
{
try
{

View File

@@ -534,8 +534,7 @@ public abstract class AbstractNodeServiceImpl implements NodeService
{
Set<QName> aspectQNames = getAspects(nodeRef);
// special case, e.g. when onAuditAspect runs as System
QName typeQName = getTypeInternal(nodeRef);
QName typeQName = getType(nodeRef);
qnames = new HashSet<QName>(aspectQNames.size() + 1);
qnames.addAll(aspectQNames);
@@ -548,12 +547,6 @@ public abstract class AbstractNodeServiceImpl implements NodeService
// done
return qnames;
}
// default implementation, should be overridden to support MT
protected QName getTypeInternal(NodeRef nodeRef)
{
return getType(nodeRef);
}
/**
* Generates a GUID for the node using either the creation properties or just by

View File

@@ -567,15 +567,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
return node.getTypeQName();
}
@Override
protected QName getTypeInternal(NodeRef nodeRef)
{
Node node = getNodeNotNull(nodeRef);
// special case, e.g. when onAuditAspect runs as System
return tenantService.getName(nodeRef, node.getTypeQName());
}
/**
* @see org.alfresco.service.cmr.repository.NodeService#setType(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
*/