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
*
@@ -28,9 +28,10 @@ import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.avm.AVMNodeConverter;
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.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.RetryingTransactionCallback;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
@@ -76,7 +77,8 @@ public class Repository implements ApplicationContextAware, ApplicationListener,
private StoreRef companyHomeStore;
private String companyHomePath;
private Map<String, NodeRef> companyHomeRefs;
private NodeRef rootRef;
private Map<String, NodeRef> rootRefs;
/**
@@ -202,6 +204,11 @@ public class Repository implements ApplicationContextAware, ApplicationListener,
companyHomeRefs = new ConcurrentHashMap<String, NodeRef>(4);
}
if (rootRefs == null)
{
rootRefs = new ConcurrentHashMap<String, NodeRef>(4);
}
getCompanyHome();
}
@@ -213,9 +220,18 @@ public class Repository implements ApplicationContextAware, ApplicationListener,
*/
public NodeRef getRootHome()
{
String tenantDomain = tenantAdminService.getCurrentUserDomain();
NodeRef rootRef = rootRefs.get(tenantDomain);
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;
}
@@ -231,7 +247,7 @@ public class Repository implements ApplicationContextAware, ApplicationListener,
NodeRef companyHomeRef = companyHomeRefs.get(tenantDomain);
if (companyHomeRef == null)
{
companyHomeRef = AuthenticationUtil.runAs(new RunAsWork<NodeRef>()
companyHomeRef = TenantUtil.runAsSystemTenant(new TenantRunAsWork<NodeRef>()
{
public NodeRef doWork() throws Exception
{
@@ -248,7 +264,7 @@ public class Repository implements ApplicationContextAware, ApplicationListener,
}
}, true);
}
}, AuthenticationUtil.getSystemUserName());
}, tenantDomain);
companyHomeRefs.put(tenantDomain, companyHomeRef);
}
return companyHomeRef;

View File

@@ -1280,6 +1280,41 @@ public class MultiTDemoTest extends TestCase
}, 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)
{
// create new Group using authority Service