]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5771 Allow admins to mark a tenant to be createdDisabled. This minimizes resou...
authorPatrick Schmitz <pschmitz@berkeley.edu>
Mon, 14 Jan 2013 17:27:07 +0000 (09:27 -0800)
committerPatrick Schmitz <pschmitz@berkeley.edu>
Mon, 14 Jan 2013 17:27:07 +0000 (09:27 -0800)
services/authorization-mgt/import/src/main/java/org/collectionspace/services/authorization/importer/AuthorizationGen.java
services/common/src/main/java/org/collectionspace/services/common/authorization_mgt/AuthorizationCommon.java
services/common/src/main/java/org/collectionspace/services/common/config/TenantBindingConfigReaderImpl.java
services/config/src/main/resources/tenant.xsd

index b45d1defd28c02d842fa6e08fbd4946494533861..a56db9cac8a6a300db7ddde66ac194935db9032d 100644 (file)
@@ -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()) {
index e8e878889f702e2c6d87f5dfac92934304adbe05..300c0e3ad24c4fd0f3044a749c2cf6e4ee051c4f 100644 (file)
@@ -381,6 +381,7 @@ public class AuthorizationCommon {
     \r
     private static Hashtable<String, String> getTenantNamesFromConfig(TenantBindingConfigReaderImpl tenantBindingConfigReader) {\r
 \r
+       // Note that this only handles tenants not marked as "createDisabled"\r
        Hashtable<String, TenantBindingType> tenantBindings =\r
                        tenantBindingConfigReader.getTenantBindings();\r
        Hashtable<String, String> tenantInfo = new Hashtable<String, String>();\r
@@ -934,6 +935,7 @@ public class AuthorizationCommon {
                conn = getConnection();\r
                ArrayList<String> existingTenants = compileExistingTenants(conn, tenantInfo);\r
                \r
+               // Note that this only creates tenants not marked as "createDisabled"\r
                createMissingTenants(conn, tenantInfo, existingTenants);\r
                \r
                ArrayList<String> usersInRepo = findOrCreateDefaultUsers(conn, tenantInfo);\r
index 103cecc2f483df708273f1b7086f5a12b04669dd..166758222b4307606619b98c24211e18b5079863 100644 (file)
@@ -56,6 +56,10 @@ import org.slf4j.LoggerFactory;
  */
 public class TenantBindingConfigReaderImpl
         extends AbstractConfigReaderImpl<List<TenantBindingType>> {
+       
+       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<TenantBindingType> tenantBindingTypeList;
+    //tenant id, tenant binding, for tenants not marked as createDisabled
+    private Hashtable<String, TenantBindingType> enabledTenantBindings =
+            new Hashtable<String, TenantBindingType>();
     //tenant id, tenant binding
-    private Hashtable<String, TenantBindingType> tenantBindings =
+    private Hashtable<String, TenantBindingType> allTenantBindings =
             new Hashtable<String, TenantBindingType>();
     //repository domains
     private Hashtable<String, RepositoryDomainType> 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<String, TenantBindingType> getTenantBindings() {
-        return tenantBindings;
+        return getTenantBindings(EXCLUDE_CREATE_DISABLED_TENANTS);
+    }
+
+    /**
+     * getTenantBindings returns all the tenant bindings read from configuration
+     * @return
+     */
+    public Hashtable<String, TenantBindingType> 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<ServiceBindingType> getServiceBindingsByType(
             String tenantId, List<String> serviceTypes) {
         ArrayList<ServiceBindingType> 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<String> getTenantIds() {
+       return getTenantIds(EXCLUDE_CREATE_DISABLED_TENANTS);
+    }
+    /**
+     * Returns a list of tenant identifiers (tenant IDs).
+     * 
+     * @return a list of tenant IDs
+     */
+    public List<String> getTenantIds(boolean includeDisabled) {
         List<String> tenantIds = new ArrayList<String>();
         String tenantId;
-        Hashtable<String, TenantBindingType> tenantBindings = getTenantBindings();
+        Hashtable<String, TenantBindingType> tenantBindings = getTenantBindings(includeDisabled);
         if (tenantBindings != null && !tenantBindings.isEmpty()) {
             Enumeration keys = tenantBindings.keys();
             while (keys.hasMoreElements()) {
index 5fd98c885d157781a85a46509db342af9b1ff37a..b1b3b7ae2f8827556779f0a5eaf5bce7a77ef46d 100644 (file)
@@ -56,6 +56,7 @@
         <!-- display name as Museum of Moving Images -->
         <xs:attribute name="displayName" type="xs:string" use="required"/>
         <xs:attribute name="version" type="types:VersionType" use="required"/>
+        <xs:attribute name="createDisabled" type="xs:boolean" use="optional" default="false"/>
 
     </xs:complexType>