MT - extra validation when creating/importing new tenants

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@8239 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka 2008-02-11 10:07:06 +00:00
parent 83ab25f486
commit 1041c6ceb0

View File

@ -281,28 +281,9 @@ public class MultiTAdminServiceImpl extends AbstractLifecycleBean implements Ten
*/
public void createTenant(final String tenantDomain, final char[] tenantAdminRawPassword, String rootContentStoreDir)
{
// Check that all the passed values are not null
ParameterCheck.mandatory("tenantDomain", tenantDomain);
ParameterCheck.mandatory("tenantAdminRawPassword", tenantAdminRawPassword);
validateTenantName(tenantDomain);
if (existsTenant(tenantDomain))
{
throw new AlfrescoRuntimeException("Tenant already exists: " + tenantDomain);
}
else
{
authenticationComponent.setSystemUserAsCurrentUser();
if (rootContentStoreDir == null)
{
rootContentStoreDir = tenantFileContentStore.getDefaultRootDir();
}
// init - need to enable tenant (including tenant service) before stores bootstrap
Tenant tenant = new Tenant(tenantDomain, true, rootContentStoreDir);
putTenantAttributes(tenantDomain, tenant);
initTenant(tenantDomain, rootContentStoreDir);
AuthenticationUtil.runAs(new RunAsWork<Object>()
{
@ -336,7 +317,6 @@ public class MultiTAdminServiceImpl extends AbstractLifecycleBean implements Ten
return null;
}
}, getSystemUser(tenantDomain));
}
logger.info("Tenant created: " + tenantDomain);
}
@ -363,27 +343,7 @@ public class MultiTAdminServiceImpl extends AbstractLifecycleBean implements Ten
*/
public void importTenant(final String tenantDomain, final File directorySource, String rootContentStoreDir)
{
// Check that all the passed values are not null
ParameterCheck.mandatory("tenantDomain", tenantDomain);
validateTenantName(tenantDomain);
if (existsTenant(tenantDomain))
{
throw new AlfrescoRuntimeException("Tenant already exists: " + tenantDomain);
}
else
{
authenticationComponent.setSystemUserAsCurrentUser();
if (rootContentStoreDir == null)
{
rootContentStoreDir = tenantFileContentStore.getDefaultRootDir();
}
// init - need to enable tenant (including tenant service) before stores bootstrap
Tenant tenant = new Tenant(tenantDomain, true, rootContentStoreDir);
putTenantAttributes(tenantDomain, tenant);
initTenant(tenantDomain, rootContentStoreDir);
AuthenticationUtil.runAs(new RunAsWork<Object>()
{
@ -409,7 +369,6 @@ public class MultiTAdminServiceImpl extends AbstractLifecycleBean implements Ten
return null;
}
}, getSystemUser(tenantDomain));
}
logger.info("Tenant imported: " + tenantDomain);
}
@ -1078,8 +1037,37 @@ public class MultiTAdminServiceImpl extends AbstractLifecycleBean implements Ten
}
}
private void initTenant(String tenantDomain, String rootContentStoreDir)
{
validateTenantName(tenantDomain);
if (existsTenant(tenantDomain))
{
throw new AlfrescoRuntimeException("Tenant already exists: " + tenantDomain);
}
if (rootContentStoreDir == null)
{
rootContentStoreDir = tenantFileContentStore.getDefaultRootDir();
}
else
{
File tenantRootDir = new File(rootContentStoreDir);
if ((tenantRootDir.exists()) && (tenantRootDir.list().length != 0))
{
throw new AlfrescoRuntimeException("Tenant root directory is not empty: " + rootContentStoreDir);
}
}
// init - need to enable tenant (including tenant service) before stores bootstrap
Tenant tenant = new Tenant(tenantDomain, true, rootContentStoreDir);
putTenantAttributes(tenantDomain, tenant);
}
private void validateTenantName(String tenantDomain)
{
ParameterCheck.mandatory("tenantDomain", tenantDomain);
if (tenantDomain.length() > MAX_LEN)
{
throw new IllegalArgumentException(tenantDomain + " is not a valid tenant name (must be less than " + MAX_LEN + " characters)");