MT - tenant bootstrap nows runs in 'System' ctx (rather than tenant 'admin' ctx) + minor cleanup.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@8137 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2008-01-31 10:58:47 +00:00
parent 06541ab85a
commit fd46bb7add
8 changed files with 132 additions and 158 deletions

View File

@@ -222,6 +222,10 @@ public class AuditableAspect
String currentUserName = authenticationService.getCurrentUserName();
if (currentUserName != null)
{
if (tenantService.isEnabled() && authenticationService.isCurrentUserTheSystemUser())
{
return tenantService.getBaseNameUser(currentUserName);
}
return currentUserName;
}
return USERNAME_UNKNOWN;

View File

@@ -101,7 +101,7 @@ public class TenantRoutingFileContentStore extends AbstractRoutingContentStore i
public void init()
{
String tenantDomain = "";
String tenantDomain = TenantService.DEFAULT_DOMAIN;
String rootDir = defaultRootDirectory;
Tenant tenant = tenantService.getTenant(tenantService.getCurrentUserDomain());

View File

@@ -189,16 +189,6 @@ public class DictionaryDAOImpl implements DictionaryDAO
logger.debug("Resetting dictionary ...");
}
String userName;
if (tenantDomain == "")
{
userName = AuthenticationUtil.getSystemUserName();
}
else
{
userName = tenantService.getDomainUser(TenantService.ADMIN_BASENAME, tenantDomain);
}
AuthenticationUtil.runAs(new RunAsWork<Object>()
{
public Object doWork()
@@ -208,7 +198,7 @@ public class DictionaryDAOImpl implements DictionaryDAO
return null;
}
}, userName);
}, tenantService.getDomainUser(AuthenticationUtil.getSystemUserName(), tenantDomain));
if (logger.isDebugEnabled())
{

View File

@@ -585,13 +585,9 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda
{
// shared model - need to check all tenants (whether enabled or disabled) unless they have overridden
List<Tenant> tenants = tenantDeployerService.getAllTenants();
if (tenants != null)
{
for (Tenant tenant : tenants)
{
// switch to admin in order to validate model delete within context of tenant domain
// assumes each tenant has default "admin" user
// validate model delete within context of tenant domain
AuthenticationUtil.runAs(new RunAsWork<Object>()
{
public Object doWork()
@@ -602,18 +598,17 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda
}
return null;
}
}, tenantService.getDomainUser(TenantService.ADMIN_BASENAME, tenant.getTenantDomain()));
}
}, tenantService.getDomainUser(AuthenticationUtil.getSystemUserName(), tenant.getTenantDomain()));
}
}
}
private void validateModelDelete(QName modelName, boolean sharedModel)
{
String tenantDomainCtx = "";
String tenantDomain = TenantService.DEFAULT_DOMAIN;
if (sharedModel)
{
tenantDomainCtx = " for tenant [" + tenantService.getCurrentUserDomain() + "]";
tenantDomain = " for tenant [" + tenantService.getCurrentUserDomain() + "]";
}
// check workflow namespace usage
@@ -625,7 +620,7 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda
{
if (workflowNamespaceURI.equals(namespace.getUri()))
{
throw new AlfrescoRuntimeException("Failed to validate model delete" + tenantDomainCtx + " - found workflow process definition " + workflowDefName + " using model namespace '" + namespace.getUri() + "'");
throw new AlfrescoRuntimeException("Failed to validate model delete" + tenantDomain + " - found workflow process definition " + workflowDefName + " using model namespace '" + namespace.getUri() + "'");
}
}
}
@@ -633,17 +628,17 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda
// check for type usages
for (TypeDefinition type : dictionaryDAO.getTypes(modelName))
{
validateClass(tenantDomainCtx, type);
validateClass(tenantDomain, type);
}
// check for aspect usages
for (AspectDefinition aspect : dictionaryDAO.getAspects(modelName))
{
validateClass(tenantDomainCtx, aspect);
validateClass(tenantDomain, aspect);
}
}
private void validateClass(String tenantDomainCtx, ClassDefinition classDef)
private void validateClass(String tenantDomain, ClassDefinition classDef)
{
QName className = classDef.getName();
@@ -661,7 +656,7 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda
ResultSet rs = searchService.query(store, SearchService.LANGUAGE_LUCENE, classType+":\""+className+"\"");
if (rs.length() > 0)
{
throw new AlfrescoRuntimeException("Failed to validate model delete" + tenantDomainCtx + " - found " + rs.length() + " nodes in store " + store + " with " + classType + " '" + className + "'" );
throw new AlfrescoRuntimeException("Failed to validate model delete" + tenantDomain + " - found " + rs.length() + " nodes in store " + store + " with " + classType + " '" + className + "'" );
}
}
@@ -673,7 +668,7 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda
TypeDefinition workflowTypeDef = workflowTaskDef.metadata;
if (workflowTypeDef.getName().toString().equals(className))
{
throw new AlfrescoRuntimeException("Failed to validate model delete" + tenantDomainCtx + " - found task definition in workflow " + workflowDef.getName() + " with " + classType + " '" + className + "'");
throw new AlfrescoRuntimeException("Failed to validate model delete" + tenantDomain + " - found task definition in workflow " + workflowDef.getName() + " with " + classType + " '" + className + "'");
}
}
}

View File

@@ -816,16 +816,6 @@ public class MessageServiceImpl implements MessageService
logger.debug("Resetting messages ...");
}
String userName;
if (tenantDomain == "")
{
userName = AuthenticationUtil.getSystemUserName();
}
else
{
userName = tenantService.getDomainUser(TenantService.ADMIN_BASENAME, tenantDomain);
}
AuthenticationUtil.runAs(new RunAsWork<Object>()
{
public Object doWork()
@@ -840,7 +830,7 @@ public class MessageServiceImpl implements MessageService
return null;
}
}, userName);
}, tenantService.getDomainUser(AuthenticationUtil.getSystemUserName(), tenantDomain));
if (logger.isDebugEnabled())
{

View File

@@ -224,8 +224,6 @@ public class MultiTAdminServiceImpl extends AbstractLifecycleBean implements Ten
int enabledCount = 0;
int disabledCount = 0;
if (tenants != null)
{
for (Tenant tenant : tenants)
{
if (tenant.isEnabled())
@@ -243,7 +241,6 @@ public class MultiTAdminServiceImpl extends AbstractLifecycleBean implements Ten
}
tenantService.register(this); // callback to refresh tenantStatus cache
}
userTransaction.commit();
@@ -336,7 +333,7 @@ public class MultiTAdminServiceImpl extends AbstractLifecycleBean implements Ten
return null;
}
}, getTenantAdminUser(tenantDomain));
}, getSystemUser(tenantDomain));
}
logger.info("Tenant created: " + tenantDomain);
@@ -354,7 +351,7 @@ public class MultiTAdminServiceImpl extends AbstractLifecycleBean implements Ten
repositoryExporterService.export(directoryDestination, tenantDomain);
return null;
}
}, getTenantAdminUser(tenantDomain));
}, getSystemUser(tenantDomain));
logger.info("Tenant exported: " + tenantDomain);
}
@@ -409,7 +406,7 @@ public class MultiTAdminServiceImpl extends AbstractLifecycleBean implements Ten
return null;
}
}, getTenantAdminUser(tenantDomain));
}, getSystemUser(tenantDomain));
}
logger.info("Tenant imported: " + tenantDomain);
@@ -489,7 +486,7 @@ public class MultiTAdminServiceImpl extends AbstractLifecycleBean implements Ten
}
return null;
}
}, getTenantAdminUser(tenantDomain));
}, getSystemUser(tenantDomain));
}
logger.info("Tenant enabled: " + tenantDomain);
@@ -520,7 +517,7 @@ public class MultiTAdminServiceImpl extends AbstractLifecycleBean implements Ten
}
return null;
}
}, getTenantAdminUser(tenantDomain));
}, getSystemUser(tenantDomain));
}
// update tenant attributes / tenant cache - need to disable after notifying listeners (else they cannot disable)
@@ -580,7 +577,7 @@ public class MultiTAdminServiceImpl extends AbstractLifecycleBean implements Ten
workflowDeployer.init();
return null;
}
}, getTenantAdminUser(tenantDomain));
}, getSystemUser(tenantDomain));
logger.info("Tenant workflows bootstrapped: " + tenantDomain);
}
@@ -598,8 +595,6 @@ public class MultiTAdminServiceImpl extends AbstractLifecycleBean implements Ten
{
try
{
final String tenantAdminUser = getTenantAdminUser(tenantDomain);
AuthenticationUtil.runAs(new RunAsWork<Object>()
{
public Object doWork()
@@ -633,8 +628,9 @@ public class MultiTAdminServiceImpl extends AbstractLifecycleBean implements Ten
return null;
}
}, tenantAdminUser);
}, getSystemUser(tenantDomain));
final String tenantAdminUser = getTenantAdminUser(tenantDomain);
// delete tenant-specific stores
nodeService.deleteStore(tenantService.getName(tenantAdminUser, new StoreRef(PROTOCOL_STORE_WORKSPACE, STORE_BASE_ID_SPACES)));
@@ -655,7 +651,7 @@ public class MultiTAdminServiceImpl extends AbstractLifecycleBean implements Ten
}
return null;
}
}, tenantAdminUser);
}, getSystemUser(tenantDomain));
// remove tenant
attributeService.removeAttribute(TENANTS_ATTRIBUTE_PATH, tenantDomain);
@@ -911,8 +907,6 @@ public class MultiTAdminServiceImpl extends AbstractLifecycleBean implements Ten
String currentUser = AuthenticationUtil.getCurrentUserName();
if (tenants != null)
{
try
{
for (Tenant tenant : tenants)
@@ -931,7 +925,7 @@ public class MultiTAdminServiceImpl extends AbstractLifecycleBean implements Ten
deployer.init();
return null;
}
}, getTenantAdminUser(tenant.getTenantDomain()));
}, getSystemUser(tenant.getTenantDomain()));
}
catch (Throwable e)
@@ -953,7 +947,6 @@ public class MultiTAdminServiceImpl extends AbstractLifecycleBean implements Ten
}
}
}
}
public void undeployTenants(final TenantDeployer deployer, Log logger)
{
@@ -988,8 +981,6 @@ public class MultiTAdminServiceImpl extends AbstractLifecycleBean implements Ten
String currentUser = AuthenticationUtil.getCurrentUserName();
if (tenants != null)
{
try
{
for (Tenant tenant : tenants)
@@ -1008,7 +999,7 @@ public class MultiTAdminServiceImpl extends AbstractLifecycleBean implements Ten
deployer.destroy();
return null;
}
}, getTenantAdminUser(tenant.getTenantDomain()));
}, getSystemUser(tenant.getTenantDomain()));
}
catch (Throwable e)
@@ -1030,7 +1021,6 @@ public class MultiTAdminServiceImpl extends AbstractLifecycleBean implements Ten
}
}
}
}
public void register(TenantDeployer deployer)
{
@@ -1114,13 +1104,18 @@ public class MultiTAdminServiceImpl extends AbstractLifecycleBean implements Ten
}
}
// local helper
// local helpers
private String getSystemUser(String tenantDomain)
{
return tenantService.getDomainUser(AuthenticationUtil.getSystemUserName(), tenantDomain);
}
private String getTenantAdminUser(String tenantDomain)
{
return tenantService.getDomainUser(ADMIN_BASENAME, tenantDomain);
}
// local helper
private String getTenantGuestUser(String tenantDomain)
{
return tenantService.getDomainUser(authenticationComponent.getGuestUserName(), tenantDomain);

View File

@@ -485,9 +485,12 @@ public class MultiTServiceImpl implements TenantService
{
// Check that all the passed values are not null
ParameterCheck.mandatory("baseUsername", baseUsername);
ParameterCheck.mandatory("tenantDomain", tenantDomain);
if (! tenantDomain.equals(DEFAULT_DOMAIN))
if ((tenantDomain == null) || (tenantDomain.equals(DEFAULT_DOMAIN)))
{
return baseUsername;
}
else
{
if (baseUsername.contains(SEPARATOR))
{
@@ -501,10 +504,6 @@ public class MultiTServiceImpl implements TenantService
return baseUsername + SEPARATOR + tenantDomain;
}
else
{
return baseUsername;
}
}
protected void checkTenantEnabled(String tenantDomain)

View File

@@ -24,6 +24,7 @@
*/
package org.alfresco.repo.tenant;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
@@ -56,6 +57,6 @@ public class SingleTDeployerServiceImpl implements TenantDeployerService
public List<Tenant> getAllTenants()
{
return null;
return new ArrayList<Tenant>(0); // empty list
}
}