From: Patrick Schmitz Date: Mon, 14 Jan 2013 17:27:07 +0000 (-0800) Subject: CSPACE-5771 Allow admins to mark a tenant to be createdDisabled. This minimizes resou... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=c4d658c50ac2bd39c1a0b8eb3beb3d6d910468f3;p=tmp%2Fjakarta-migration.git CSPACE-5771 Allow admins to mark a tenant to be createdDisabled. This minimizes resources devoted to the tenant, and it will remain disabled until this setting is altered and the system restarted (the webapp reloaded). Permissions are created, as this cannot currently be done incrementally. --- diff --git a/services/authorization-mgt/import/src/main/java/org/collectionspace/services/authorization/importer/AuthorizationGen.java b/services/authorization-mgt/import/src/main/java/org/collectionspace/services/authorization/importer/AuthorizationGen.java index b45d1defd..a56db9cac 100644 --- a/services/authorization-mgt/import/src/main/java/org/collectionspace/services/authorization/importer/AuthorizationGen.java +++ b/services/authorization-mgt/import/src/main/java/org/collectionspace/services/authorization/importer/AuthorizationGen.java @@ -91,7 +91,10 @@ public class AuthorizationGen { TenantBindingConfigReaderImpl tenantBindingConfigReader = new TenantBindingConfigReaderImpl(tenantRootDirPath); tenantBindingConfigReader.read(); - tenantBindings = tenantBindingConfigReader.getTenantBindings(); + // Note that we build permissions for all tenants, whether or not they are marked create disabled. + // This is a hack until we can correctly run an incremental import. + tenantBindings = tenantBindingConfigReader.getTenantBindings( + TenantBindingConfigReaderImpl.INCLUDE_CREATE_DISABLED_TENANTS); cspaceTenantMgmntRole = buildTenantMgmntRole(); if (logger.isDebugEnabled()) { diff --git a/services/common/src/main/java/org/collectionspace/services/common/authorization_mgt/AuthorizationCommon.java b/services/common/src/main/java/org/collectionspace/services/common/authorization_mgt/AuthorizationCommon.java index e8e878889..300c0e3ad 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/authorization_mgt/AuthorizationCommon.java +++ b/services/common/src/main/java/org/collectionspace/services/common/authorization_mgt/AuthorizationCommon.java @@ -381,6 +381,7 @@ public class AuthorizationCommon { private static Hashtable getTenantNamesFromConfig(TenantBindingConfigReaderImpl tenantBindingConfigReader) { + // Note that this only handles tenants not marked as "createDisabled" Hashtable tenantBindings = tenantBindingConfigReader.getTenantBindings(); Hashtable tenantInfo = new Hashtable(); @@ -934,6 +935,7 @@ public class AuthorizationCommon { conn = getConnection(); ArrayList existingTenants = compileExistingTenants(conn, tenantInfo); + // Note that this only creates tenants not marked as "createDisabled" createMissingTenants(conn, tenantInfo, existingTenants); ArrayList usersInRepo = findOrCreateDefaultUsers(conn, tenantInfo); diff --git a/services/common/src/main/java/org/collectionspace/services/common/config/TenantBindingConfigReaderImpl.java b/services/common/src/main/java/org/collectionspace/services/common/config/TenantBindingConfigReaderImpl.java index 103cecc2f..166758222 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/config/TenantBindingConfigReaderImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/config/TenantBindingConfigReaderImpl.java @@ -56,6 +56,10 @@ import org.slf4j.LoggerFactory; */ public class TenantBindingConfigReaderImpl extends AbstractConfigReaderImpl> { + + final public static boolean INCLUDE_CREATE_DISABLED_TENANTS = true; + final public static boolean EXCLUDE_CREATE_DISABLED_TENANTS = false; + final private static String TENANT_BINDINGS_ERROR = "Tenant bindings error: "; final private static String TENANT_BINDINGS_ROOTDIRNAME = "tenants"; final private static String TENANT_BINDINGS_FILENAME_PREFIX = "tenant-bindings"; @@ -65,8 +69,11 @@ public class TenantBindingConfigReaderImpl final Logger logger = LoggerFactory.getLogger(TenantBindingConfigReaderImpl.class); private List tenantBindingTypeList; + //tenant id, tenant binding, for tenants not marked as createDisabled + private Hashtable enabledTenantBindings = + new Hashtable(); //tenant id, tenant binding - private Hashtable tenantBindings = + private Hashtable allTenantBindings = new Hashtable(); //repository domains private Hashtable domains = @@ -179,20 +186,26 @@ public class TenantBindingConfigReaderImpl tenantBindingTypeList = readTenantConfigs(protoBindingsFile, tenantDirs); for (TenantBindingType tenantBinding : tenantBindingTypeList) { - if(tenantBindings.get(tenantBinding.getId()) != null) { - TenantBindingType tenantBindingOld = tenantBindings.get(tenantBinding.getId()); + if(allTenantBindings.get(tenantBinding.getId()) != null) { + TenantBindingType tenantBindingOld = allTenantBindings.get(tenantBinding.getId()); logger.error("Ignoring duplicate binding definition for tenant id=" + tenantBinding.getId() + " existing name=" + tenantBindingOld.getName() + " conflicting (ignored) name=" + tenantBinding.getName()); continue; } - tenantBindings.put(tenantBinding.getId(), tenantBinding); + allTenantBindings.put(tenantBinding.getId(), tenantBinding); + if(!tenantBinding.isCreateDisabled()) { + enabledTenantBindings.put(tenantBinding.getId(), tenantBinding); + } else { + } readDomains(tenantBinding); readServiceBindings(tenantBinding); if (logger.isInfoEnabled()) { logger.info("Finished reading tenant bindings for tenant id=" + tenantBinding.getId() + " name=" + tenantBinding.getName()); + if(tenantBinding.isCreateDisabled()) + logger.info("Tenant tenant id={} is marked createDisabled.", tenantBinding.getId()); } } } @@ -324,7 +337,15 @@ public class TenantBindingConfigReaderImpl * @return */ public Hashtable getTenantBindings() { - return tenantBindings; + return getTenantBindings(EXCLUDE_CREATE_DISABLED_TENANTS); + } + + /** + * getTenantBindings returns all the tenant bindings read from configuration + * @return + */ + public Hashtable getTenantBindings(boolean includeDisabled) { + return includeDisabled?allTenantBindings:enabledTenantBindings; } /** @@ -334,7 +355,7 @@ public class TenantBindingConfigReaderImpl */ public TenantBindingType getTenantBinding( String tenantId) { - return tenantBindings.get(tenantId); + return allTenantBindings.get(tenantId); } /** @@ -416,7 +437,7 @@ public class TenantBindingConfigReaderImpl public List getServiceBindingsByType( String tenantId, List serviceTypes) { ArrayList list = null; - TenantBindingType tenant = tenantBindings.get(tenantId); + TenantBindingType tenant = allTenantBindings.get(tenantId); if (tenant != null) { for (ServiceBindingType sb : tenant.getServiceBindings()) { if (serviceTypes.contains(sb.getType())) { @@ -458,7 +479,7 @@ public class TenantBindingConfigReaderImpl if (propList == null || propList.isEmpty()) { return; } - for (TenantBindingType tenant : tenantBindings.values()) { + for (TenantBindingType tenant : allTenantBindings.values()) { for (PropertyItemType prop : propList) { TenantBindingUtils.setPropertyValue(tenant, prop, TenantBindingUtils.SET_PROP_IF_MISSING); @@ -481,9 +502,17 @@ public class TenantBindingConfigReaderImpl * @return a list of tenant IDs */ public List getTenantIds() { + return getTenantIds(EXCLUDE_CREATE_DISABLED_TENANTS); + } + /** + * Returns a list of tenant identifiers (tenant IDs). + * + * @return a list of tenant IDs + */ + public List getTenantIds(boolean includeDisabled) { List tenantIds = new ArrayList(); String tenantId; - Hashtable tenantBindings = getTenantBindings(); + Hashtable tenantBindings = getTenantBindings(includeDisabled); if (tenantBindings != null && !tenantBindings.isEmpty()) { Enumeration keys = tenantBindings.keys(); while (keys.hasMoreElements()) { diff --git a/services/config/src/main/resources/tenant.xsd b/services/config/src/main/resources/tenant.xsd index 5fd98c885..b1b3b7ae2 100644 --- a/services/config/src/main/resources/tenant.xsd +++ b/services/config/src/main/resources/tenant.xsd @@ -56,6 +56,7 @@ +