Merged BRANCHES/DEV/V4.1-BUG-FIX to HEAD:

41618: MT: ALF-14354 - Repository.getRootHome() is not tenant-safe !!


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@41620 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2012-09-14 15:44:23 +00:00
parent 6ec5fe4f27
commit 2b8870c772
2 changed files with 64 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2005-2010 Alfresco Software Limited. * Copyright (C) 2005-2012 Alfresco Software Limited.
* *
* This file is part of Alfresco * This file is part of Alfresco
* *
@@ -28,9 +28,10 @@ import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.avm.AVMNodeConverter; import org.alfresco.repo.avm.AVMNodeConverter;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.tenant.TenantAdminService; import org.alfresco.repo.tenant.TenantAdminService;
import org.alfresco.repo.tenant.TenantDeployer; import org.alfresco.repo.tenant.TenantDeployer;
import org.alfresco.repo.tenant.TenantUtil;
import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
import org.alfresco.repo.transaction.RetryingTransactionHelper; import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor; import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
@@ -76,7 +77,8 @@ public class Repository implements ApplicationContextAware, ApplicationListener,
private StoreRef companyHomeStore; private StoreRef companyHomeStore;
private String companyHomePath; private String companyHomePath;
private Map<String, NodeRef> companyHomeRefs; private Map<String, NodeRef> companyHomeRefs;
private NodeRef rootRef;
private Map<String, NodeRef> rootRefs;
/** /**
@@ -199,7 +201,12 @@ public class Repository implements ApplicationContextAware, ApplicationListener,
if (companyHomeRefs == null) if (companyHomeRefs == null)
{ {
companyHomeRefs = new ConcurrentHashMap<String, NodeRef>(4); companyHomeRefs = new ConcurrentHashMap<String, NodeRef>(4);
}
if (rootRefs == null)
{
rootRefs = new ConcurrentHashMap<String, NodeRef>(4);
} }
getCompanyHome(); getCompanyHome();
@@ -213,9 +220,18 @@ public class Repository implements ApplicationContextAware, ApplicationListener,
*/ */
public NodeRef getRootHome() public NodeRef getRootHome()
{ {
String tenantDomain = tenantAdminService.getCurrentUserDomain();
NodeRef rootRef = rootRefs.get(tenantDomain);
if (rootRef == null) if (rootRef == null)
{ {
rootRef = nodeService.getRootNode(companyHomeStore); rootRef = TenantUtil.runAsSystemTenant(new TenantRunAsWork<NodeRef>()
{
public NodeRef doWork() throws Exception
{
return nodeService.getRootNode(companyHomeStore);
}
}, tenantDomain);
rootRefs.put(tenantDomain, rootRef);
} }
return rootRef; return rootRef;
} }
@@ -231,8 +247,8 @@ public class Repository implements ApplicationContextAware, ApplicationListener,
NodeRef companyHomeRef = companyHomeRefs.get(tenantDomain); NodeRef companyHomeRef = companyHomeRefs.get(tenantDomain);
if (companyHomeRef == null) if (companyHomeRef == null)
{ {
companyHomeRef = AuthenticationUtil.runAs(new RunAsWork<NodeRef>() companyHomeRef = TenantUtil.runAsSystemTenant(new TenantRunAsWork<NodeRef>()
{ {
public NodeRef doWork() throws Exception public NodeRef doWork() throws Exception
{ {
return retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>() return retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>()
@@ -243,13 +259,13 @@ public class Repository implements ApplicationContextAware, ApplicationListener,
if (refs.size() != 1) if (refs.size() != 1)
{ {
throw new IllegalStateException("Invalid company home path: " + companyHomePath + " - found: " + refs.size()); throw new IllegalStateException("Invalid company home path: " + companyHomePath + " - found: " + refs.size());
}
return refs.get(0);
} }
}, true); return refs.get(0);
} }
}, AuthenticationUtil.getSystemUserName()); }, true);
companyHomeRefs.put(tenantDomain, companyHomeRef); }
}, tenantDomain);
companyHomeRefs.put(tenantDomain, companyHomeRef);
} }
return companyHomeRef; return companyHomeRef;
} }

View File

@@ -1280,6 +1280,41 @@ public class MultiTDemoTest extends TestCase
}, tenantAdminName); }, tenantAdminName);
} }
public void test_ALF_14354()
{
final String tenantDomain1 = TEST_RUN+".one.alf14354";
final String tenantDomain2 = TEST_RUN+".two.alf14354";
createTenant(tenantDomain1);
createTenant(tenantDomain2);
String tenantAdminName = tenantService.getDomainUser(AuthenticationUtil.getAdminUserName(), tenantDomain1);
AuthenticationUtil.runAs(new RunAsWork<Object>()
{
public Object doWork() throws Exception
{
NodeRef rootNodeRef = repositoryHelper.getRootHome();
assertTrue(nodeService.exists(rootNodeRef));
return null;
}
}, tenantAdminName);
tenantAdminName = tenantService.getDomainUser(AuthenticationUtil.getAdminUserName(), tenantDomain2);
AuthenticationUtil.runAs(new RunAsWork<Object>()
{
public Object doWork() throws Exception
{
NodeRef rootNodeRef = repositoryHelper.getRootHome();
assertTrue(nodeService.exists(rootNodeRef));
return null;
}
}, tenantAdminName);
}
private void createGroup(String shortName, String parentShortName) private void createGroup(String shortName, String parentShortName)
{ {
// create new Group using authority Service // create new Group using authority Service