]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-1482 import module with the help of tenant bindings now generates and imports...
authorSanjay Dalal <sanjay.dalal@berkeley.edu>
Wed, 19 May 2010 18:17:34 +0000 (18:17 +0000)
committerSanjay Dalal <sanjay.dalal@berkeley.edu>
Wed, 19 May 2010 18:17:34 +0000 (18:17 +0000)
services/authorization-mgt/import/pom.xml
services/authorization-mgt/import/src/main/resources/import-data/import-permissions-roles.xml
services/authorization-mgt/import/src/main/resources/import-data/import-permissions.xml
services/authorization-mgt/import/src/test/java/org/collectionspace/services/authorization/generator/AuthorizationGen.java
services/authorization-mgt/import/src/test/java/org/collectionspace/services/authorization/importer/AbstractAuthorizationTestImpl.java
services/authorization-mgt/import/src/test/java/org/collectionspace/services/authorization/importer/AuthorizationSeedTest.java
services/common/src/main/java/org/collectionspace/services/common/config/AbstractConfigReaderImpl.java
services/common/src/main/java/org/collectionspace/services/common/config/ConfigReader.java
services/common/src/main/java/org/collectionspace/services/common/config/ServicesConfigReaderImpl.java
services/common/src/main/java/org/collectionspace/services/common/config/TenantBindingConfigReaderImpl.java

index a2ceb0b21e78176ebf31fb9bdf3b973c0600ea89..56da2d4810218e3f6dc0f028641e492165f55007 100644 (file)
             <groupId>org.slf4j</groupId>\r
             <artifactId>slf4j-log4j12</artifactId>\r
         </dependency>\r
-        <dependency>\r
-            <groupId>org.collectionspace.services</groupId>\r
-            <artifactId>org.collectionspace.services.authentication.service</artifactId>\r
-            <version>${project.version}</version>\r
-            <scope>provided</scope>\r
-        </dependency>\r
         <dependency>\r
             <groupId>org.collectionspace.services</groupId>\r
             <artifactId>org.collectionspace.services.authorization.service</artifactId>\r
             <version>${project.version}</version>\r
             <scope>provided</scope>\r
         </dependency>\r
-        <dependency>\r
-            <groupId>org.collectionspace.services</groupId>\r
-            <artifactId>org.collectionspace.services.client</artifactId>\r
-            <version>${project.version}</version>\r
-        </dependency>\r
-\r
-        <!-- Needed if/when client test framework files are moved into -->\r
-        <!-- /services/client/src/test from /services/client/src/main -->\r
-\r
-        <!-- <dependency>\r
-            <groupId>org.collectionspace.services</groupId>\r
-            <artifactId>org.collectionspace.services.client</artifactId>\r
-            <version>${project.version}</version>\r
-            <scope>test</scope>\r
-            <type>test-jar</type>\r
-        </dependency> -->\r
         <dependency>\r
             <groupId>org.testng</groupId>\r
             <artifactId>testng</artifactId>\r
             <version>5.6</version>\r
         </dependency>\r
-        <dependency>\r
-            <groupId>org.jboss.resteasy</groupId>\r
-            <artifactId>resteasy-jaxrs</artifactId>\r
-            <exclusions>\r
-                <exclusion>\r
-                    <groupId>tjws</groupId>\r
-                    <artifactId>webserver</artifactId>\r
-                </exclusion>\r
-            </exclusions>\r
-        </dependency>\r
-        <dependency>\r
-            <groupId>org.jboss.resteasy</groupId>\r
-            <artifactId>resteasy-jaxb-provider</artifactId>\r
-        </dependency>\r
-        <dependency>\r
-            <groupId>org.jboss.resteasy</groupId>\r
-            <artifactId>resteasy-multipart-provider</artifactId>\r
-        </dependency>\r
-        <dependency>\r
-            <groupId>commons-httpclient</groupId>\r
-            <artifactId>commons-httpclient</artifactId>\r
-            <version>3.1</version>\r
-        </dependency>\r
+\r
 \r
         <dependency>\r
             <groupId>org.springframework.security</groupId>\r
                 <artifactId>maven-surefire-plugin</artifactId>\r
                 <configuration>\r
                     <systemProperties>\r
-                        <property>\r
-                            <name>maven.basedir</name>\r
-                            <value>${basedir}</value>\r
-                        </property>\r
                         <property>\r
                             <name>log4j.configuration</name>\r
                             <value>file:${project.build.directory}/test-classes/log4j.properties</value>\r
                         </property>\r
+                        <property>\r
+                            <name>importdir</name>\r
+                            <value>${basedir}/src/main/resources/import-data/</value>\r
+                        </property>\r
+                        <property>\r
+                            <name>exportdir</name>\r
+                            <value>${basedir}/src/main/resources/import-data/</value>\r
+                        </property>\r
+                        <property>\r
+                            <name>tenantbindings</name>\r
+                            <value>${basedir}/../../common/src/main/config/services/tenant-bindings.xml</value>\r
+                        </property>\r
                         <property>\r
                             <name>spring-beans-config</name>\r
                             <value>applicationContext-authorization-test.xml</value>\r
index ef35f5a0f4c4a887016c338c691442539817182d..53ff7fd92149315a58b4b5e74e2e546aab0f03a2 100644 (file)
@@ -3,7 +3,150 @@
     <permissionRole>
         <subject>ROLE</subject>
         <permission>
-            <permissionId>1</permissionId>
+            <permissionId>d517250a-91a8-4b19-b1a4-75ad56d3012a</permissionId>
+            <resourceName>collectionobjects</resourceName>
+        </permission>
+        <role>
+            <roleId>1</roleId>
+            <roleName>ROLE_ADMINISTRATOR</roleName>
+        </role>
+    </permissionRole>
+    <permissionRole>
+        <subject>ROLE</subject>
+        <permission>
+            <permissionId>eb155cad-cfac-4bcd-bdb3-34c8406bb6c7</permissionId>
+            <resourceName>intakes</resourceName>
+        </permission>
+        <role>
+            <roleId>1</roleId>
+            <roleName>ROLE_ADMINISTRATOR</roleName>
+        </role>
+    </permissionRole>
+    <permissionRole>
+        <subject>ROLE</subject>
+        <permission>
+            <permissionId>04383c28-f9d0-4628-bd8d-90c07963630d</permissionId>
+            <resourceName>loansin</resourceName>
+        </permission>
+        <role>
+            <roleId>1</roleId>
+            <roleName>ROLE_ADMINISTRATOR</roleName>
+        </role>
+    </permissionRole>
+    <permissionRole>
+        <subject>ROLE</subject>
+        <permission>
+            <permissionId>1280b13b-0e02-4c11-955d-5151ac15cb16</permissionId>
+            <resourceName>loansout</resourceName>
+        </permission>
+        <role>
+            <roleId>1</roleId>
+            <roleName>ROLE_ADMINISTRATOR</roleName>
+        </role>
+    </permissionRole>
+    <permissionRole>
+        <subject>ROLE</subject>
+        <permission>
+            <permissionId>86ed3672-c338-4537-893d-69bbef22ea7e</permissionId>
+            <resourceName>movements</resourceName>
+        </permission>
+        <role>
+            <roleId>1</roleId>
+            <roleName>ROLE_ADMINISTRATOR</roleName>
+        </role>
+    </permissionRole>
+    <permissionRole>
+        <subject>ROLE</subject>
+        <permission>
+            <permissionId>293a5a00-e2ca-49f9-9f52-6cefbceae1a7</permissionId>
+            <resourceName>vocabularies</resourceName>
+        </permission>
+        <role>
+            <roleId>1</roleId>
+            <roleName>ROLE_ADMINISTRATOR</roleName>
+        </role>
+    </permissionRole>
+    <permissionRole>
+        <subject>ROLE</subject>
+        <permission>
+            <permissionId>1c1152e4-2e7b-4744-bf86-8c47f62f6b2a</permissionId>
+            <resourceName>vocabularyitems</resourceName>
+        </permission>
+        <role>
+            <roleId>1</roleId>
+            <roleName>ROLE_ADMINISTRATOR</roleName>
+        </role>
+    </permissionRole>
+    <permissionRole>
+        <subject>ROLE</subject>
+        <permission>
+            <permissionId>29e217f7-d1a0-463b-9f3e-1804be23f127</permissionId>
+            <resourceName>orgauthorities</resourceName>
+        </permission>
+        <role>
+            <roleId>1</roleId>
+            <roleName>ROLE_ADMINISTRATOR</roleName>
+        </role>
+    </permissionRole>
+    <permissionRole>
+        <subject>ROLE</subject>
+        <permission>
+            <permissionId>34197256-031f-4218-bb8d-c02a9d202986</permissionId>
+            <resourceName>organizations</resourceName>
+        </permission>
+        <role>
+            <roleId>1</roleId>
+            <roleName>ROLE_ADMINISTRATOR</roleName>
+        </role>
+    </permissionRole>
+    <permissionRole>
+        <subject>ROLE</subject>
+        <permission>
+            <permissionId>d327da0e-da21-4716-a01c-47ad828ec2b4</permissionId>
+            <resourceName>personauthorities</resourceName>
+        </permission>
+        <role>
+            <roleId>1</roleId>
+            <roleName>ROLE_ADMINISTRATOR</roleName>
+        </role>
+    </permissionRole>
+    <permissionRole>
+        <subject>ROLE</subject>
+        <permission>
+            <permissionId>d2746267-4ade-4e12-8dc4-11ee151c7f2e</permissionId>
+            <resourceName>persons</resourceName>
+        </permission>
+        <role>
+            <roleId>1</roleId>
+            <roleName>ROLE_ADMINISTRATOR</roleName>
+        </role>
+    </permissionRole>
+    <permissionRole>
+        <subject>ROLE</subject>
+        <permission>
+            <permissionId>5dcbce71-bc19-4da0-8072-d994c8854007</permissionId>
+            <resourceName>acquisitions</resourceName>
+        </permission>
+        <role>
+            <roleId>1</roleId>
+            <roleName>ROLE_ADMINISTRATOR</roleName>
+        </role>
+    </permissionRole>
+    <permissionRole>
+        <subject>ROLE</subject>
+        <permission>
+            <permissionId>a2cd134f-c418-4c9c-8a85-bb530a97cea8</permissionId>
+            <resourceName>relations</resourceName>
+        </permission>
+        <role>
+            <roleId>1</roleId>
+            <roleName>ROLE_ADMINISTRATOR</roleName>
+        </role>
+    </permissionRole>
+    <permissionRole>
+        <subject>ROLE</subject>
+        <permission>
+            <permissionId>bfd8768d-64bc-47b7-9193-edfb5fc17884</permissionId>
             <resourceName>accounts</resourceName>
         </permission>
         <role>
     <permissionRole>
         <subject>ROLE</subject>
         <permission>
-            <permissionId>2</permissionId>
+            <permissionId>eb77d422-5019-470f-9670-b62bcd8eb9be</permissionId>
             <resourceName>dimensions</resourceName>
         </permission>
         <role>
             <roleName>ROLE_ADMINISTRATOR</roleName>
         </role>
     </permissionRole>
+    <permissionRole>
+        <subject>ROLE</subject>
+        <permission>
+            <permissionId>c66becf5-0670-4e6f-83be-283ca28b9220</permissionId>
+            <resourceName>contacts</resourceName>
+        </permission>
+        <role>
+            <roleId>1</roleId>
+            <roleName>ROLE_ADMINISTRATOR</roleName>
+        </role>
+    </permissionRole>
+    <permissionRole>
+        <subject>ROLE</subject>
+        <permission>
+            <permissionId>9ce72e7a-dded-4b92-b0c1-3333e117a152</permissionId>
+            <resourceName>authorization/roles</resourceName>
+        </permission>
+        <role>
+            <roleId>1</roleId>
+            <roleName>ROLE_ADMINISTRATOR</roleName>
+        </role>
+    </permissionRole>
+    <permissionRole>
+        <subject>ROLE</subject>
+        <permission>
+            <permissionId>407df950-207a-4490-a122-61ab43984956</permissionId>
+            <resourceName>authorization/permissions</resourceName>
+        </permission>
+        <role>
+            <roleId>1</roleId>
+            <roleName>ROLE_ADMINISTRATOR</roleName>
+        </role>
+    </permissionRole>
+    <permissionRole>
+        <subject>ROLE</subject>
+        <permission>
+            <permissionId>5e16a57f-8c6d-4c93-b167-85c2c7881f02</permissionId>
+            <resourceName>authorization/permroles</resourceName>
+        </permission>
+        <role>
+            <roleId>1</roleId>
+            <roleName>ROLE_ADMINISTRATOR</roleName>
+        </role>
+    </permissionRole>
+    <permissionRole>
+        <subject>ROLE</subject>
+        <permission>
+            <permissionId>d1a3663a-645b-4ac4-86b8-c6ecd05e1e12</permissionId>
+            <resourceName>accounts/accountroles</resourceName>
+        </permission>
+        <role>
+            <roleId>1</roleId>
+            <roleName>ROLE_ADMINISTRATOR</roleName>
+        </role>
+    </permissionRole>
 </ns2:permissions_roles_list>
index 3287d54ff5b280b96423e583ec0e596a0ad79060..f1f501c89add109b7329f3dd370c53bc1f5031db 100644 (file)
@@ -1,6 +1,266 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <ns2:permissions_list xmlns:ns2="http://collectionspace.org/services/authorization">
-    <permission csid="1">
+    <permission csid="d517250a-91a8-4b19-b1a4-75ad56d3012a">
+        <resourceName>collectionobjects</resourceName>
+        <action>
+            <name>CREATE</name>
+        </action>
+        <action>
+            <name>READ</name>
+        </action>
+        <action>
+            <name>UPDATE</name>
+        </action>
+        <action>
+            <name>DELETE</name>
+        </action>
+        <action>
+            <name>SEARCH</name>
+        </action>
+        <effect>PERMIT</effect>
+        <tenant_id>1</tenant_id>
+    </permission>
+    <permission csid="eb155cad-cfac-4bcd-bdb3-34c8406bb6c7">
+        <resourceName>intakes</resourceName>
+        <action>
+            <name>CREATE</name>
+        </action>
+        <action>
+            <name>READ</name>
+        </action>
+        <action>
+            <name>UPDATE</name>
+        </action>
+        <action>
+            <name>DELETE</name>
+        </action>
+        <action>
+            <name>SEARCH</name>
+        </action>
+        <effect>PERMIT</effect>
+        <tenant_id>1</tenant_id>
+    </permission>
+    <permission csid="04383c28-f9d0-4628-bd8d-90c07963630d">
+        <resourceName>loansin</resourceName>
+        <action>
+            <name>CREATE</name>
+        </action>
+        <action>
+            <name>READ</name>
+        </action>
+        <action>
+            <name>UPDATE</name>
+        </action>
+        <action>
+            <name>DELETE</name>
+        </action>
+        <action>
+            <name>SEARCH</name>
+        </action>
+        <effect>PERMIT</effect>
+        <tenant_id>1</tenant_id>
+    </permission>
+    <permission csid="1280b13b-0e02-4c11-955d-5151ac15cb16">
+        <resourceName>loansout</resourceName>
+        <action>
+            <name>CREATE</name>
+        </action>
+        <action>
+            <name>READ</name>
+        </action>
+        <action>
+            <name>UPDATE</name>
+        </action>
+        <action>
+            <name>DELETE</name>
+        </action>
+        <action>
+            <name>SEARCH</name>
+        </action>
+        <effect>PERMIT</effect>
+        <tenant_id>1</tenant_id>
+    </permission>
+    <permission csid="86ed3672-c338-4537-893d-69bbef22ea7e">
+        <resourceName>movements</resourceName>
+        <action>
+            <name>CREATE</name>
+        </action>
+        <action>
+            <name>READ</name>
+        </action>
+        <action>
+            <name>UPDATE</name>
+        </action>
+        <action>
+            <name>DELETE</name>
+        </action>
+        <action>
+            <name>SEARCH</name>
+        </action>
+        <effect>PERMIT</effect>
+        <tenant_id>1</tenant_id>
+    </permission>
+    <permission csid="293a5a00-e2ca-49f9-9f52-6cefbceae1a7">
+        <resourceName>vocabularies</resourceName>
+        <action>
+            <name>CREATE</name>
+        </action>
+        <action>
+            <name>READ</name>
+        </action>
+        <action>
+            <name>UPDATE</name>
+        </action>
+        <action>
+            <name>DELETE</name>
+        </action>
+        <action>
+            <name>SEARCH</name>
+        </action>
+        <effect>PERMIT</effect>
+        <tenant_id>1</tenant_id>
+    </permission>
+    <permission csid="1c1152e4-2e7b-4744-bf86-8c47f62f6b2a">
+        <resourceName>vocabularyitems</resourceName>
+        <action>
+            <name>CREATE</name>
+        </action>
+        <action>
+            <name>READ</name>
+        </action>
+        <action>
+            <name>UPDATE</name>
+        </action>
+        <action>
+            <name>DELETE</name>
+        </action>
+        <action>
+            <name>SEARCH</name>
+        </action>
+        <effect>PERMIT</effect>
+        <tenant_id>1</tenant_id>
+    </permission>
+    <permission csid="29e217f7-d1a0-463b-9f3e-1804be23f127">
+        <resourceName>orgauthorities</resourceName>
+        <action>
+            <name>CREATE</name>
+        </action>
+        <action>
+            <name>READ</name>
+        </action>
+        <action>
+            <name>UPDATE</name>
+        </action>
+        <action>
+            <name>DELETE</name>
+        </action>
+        <action>
+            <name>SEARCH</name>
+        </action>
+        <effect>PERMIT</effect>
+        <tenant_id>1</tenant_id>
+    </permission>
+    <permission csid="34197256-031f-4218-bb8d-c02a9d202986">
+        <resourceName>organizations</resourceName>
+        <action>
+            <name>CREATE</name>
+        </action>
+        <action>
+            <name>READ</name>
+        </action>
+        <action>
+            <name>UPDATE</name>
+        </action>
+        <action>
+            <name>DELETE</name>
+        </action>
+        <action>
+            <name>SEARCH</name>
+        </action>
+        <effect>PERMIT</effect>
+        <tenant_id>1</tenant_id>
+    </permission>
+    <permission csid="d327da0e-da21-4716-a01c-47ad828ec2b4">
+        <resourceName>personauthorities</resourceName>
+        <action>
+            <name>CREATE</name>
+        </action>
+        <action>
+            <name>READ</name>
+        </action>
+        <action>
+            <name>UPDATE</name>
+        </action>
+        <action>
+            <name>DELETE</name>
+        </action>
+        <action>
+            <name>SEARCH</name>
+        </action>
+        <effect>PERMIT</effect>
+        <tenant_id>1</tenant_id>
+    </permission>
+    <permission csid="d2746267-4ade-4e12-8dc4-11ee151c7f2e">
+        <resourceName>persons</resourceName>
+        <action>
+            <name>CREATE</name>
+        </action>
+        <action>
+            <name>READ</name>
+        </action>
+        <action>
+            <name>UPDATE</name>
+        </action>
+        <action>
+            <name>DELETE</name>
+        </action>
+        <action>
+            <name>SEARCH</name>
+        </action>
+        <effect>PERMIT</effect>
+        <tenant_id>1</tenant_id>
+    </permission>
+    <permission csid="5dcbce71-bc19-4da0-8072-d994c8854007">
+        <resourceName>acquisitions</resourceName>
+        <action>
+            <name>CREATE</name>
+        </action>
+        <action>
+            <name>READ</name>
+        </action>
+        <action>
+            <name>UPDATE</name>
+        </action>
+        <action>
+            <name>DELETE</name>
+        </action>
+        <action>
+            <name>SEARCH</name>
+        </action>
+        <effect>PERMIT</effect>
+        <tenant_id>1</tenant_id>
+    </permission>
+    <permission csid="a2cd134f-c418-4c9c-8a85-bb530a97cea8">
+        <resourceName>relations</resourceName>
+        <action>
+            <name>CREATE</name>
+        </action>
+        <action>
+            <name>READ</name>
+        </action>
+        <action>
+            <name>UPDATE</name>
+        </action>
+        <action>
+            <name>DELETE</name>
+        </action>
+        <action>
+            <name>SEARCH</name>
+        </action>
+        <effect>PERMIT</effect>
+        <tenant_id>1</tenant_id>
+    </permission>
+    <permission csid="bfd8768d-64bc-47b7-9193-edfb5fc17884">
         <resourceName>accounts</resourceName>
         <action>
             <name>CREATE</name>
         <action>
             <name>DELETE</name>
         </action>
+        <action>
+            <name>SEARCH</name>
+        </action>
         <effect>PERMIT</effect>
         <tenant_id>1</tenant_id>
     </permission>
-    <permission csid="2">
+    <permission csid="eb77d422-5019-470f-9670-b62bcd8eb9be">
         <resourceName>dimensions</resourceName>
         <action>
             <name>CREATE</name>
         <action>
             <name>DELETE</name>
         </action>
+        <action>
+            <name>SEARCH</name>
+        </action>
+        <effect>PERMIT</effect>
+        <tenant_id>1</tenant_id>
+    </permission>
+    <permission csid="c66becf5-0670-4e6f-83be-283ca28b9220">
+        <resourceName>contacts</resourceName>
+        <action>
+            <name>CREATE</name>
+        </action>
+        <action>
+            <name>READ</name>
+        </action>
+        <action>
+            <name>UPDATE</name>
+        </action>
+        <action>
+            <name>DELETE</name>
+        </action>
+        <action>
+            <name>SEARCH</name>
+        </action>
+        <effect>PERMIT</effect>
+        <tenant_id>1</tenant_id>
+    </permission>
+    <permission csid="9ce72e7a-dded-4b92-b0c1-3333e117a152">
+        <resourceName>authorization/roles</resourceName>
+        <action>
+            <name>CREATE</name>
+        </action>
+        <action>
+            <name>READ</name>
+        </action>
+        <action>
+            <name>UPDATE</name>
+        </action>
+        <action>
+            <name>DELETE</name>
+        </action>
+        <action>
+            <name>SEARCH</name>
+        </action>
+        <effect>PERMIT</effect>
+        <tenant_id>1</tenant_id>
+    </permission>
+    <permission csid="407df950-207a-4490-a122-61ab43984956">
+        <resourceName>authorization/permissions</resourceName>
+        <action>
+            <name>CREATE</name>
+        </action>
+        <action>
+            <name>READ</name>
+        </action>
+        <action>
+            <name>UPDATE</name>
+        </action>
+        <action>
+            <name>DELETE</name>
+        </action>
+        <action>
+            <name>SEARCH</name>
+        </action>
+        <effect>PERMIT</effect>
+        <tenant_id>1</tenant_id>
+    </permission>
+    <permission csid="5e16a57f-8c6d-4c93-b167-85c2c7881f02">
+        <resourceName>authorization/permroles</resourceName>
+        <action>
+            <name>CREATE</name>
+        </action>
+        <action>
+            <name>READ</name>
+        </action>
+        <action>
+            <name>UPDATE</name>
+        </action>
+        <action>
+            <name>DELETE</name>
+        </action>
+        <action>
+            <name>SEARCH</name>
+        </action>
+        <effect>PERMIT</effect>
+        <tenant_id>1</tenant_id>
+    </permission>
+    <permission csid="d1a3663a-645b-4ac4-86b8-c6ecd05e1e12">
+        <resourceName>accounts/accountroles</resourceName>
+        <action>
+            <name>CREATE</name>
+        </action>
+        <action>
+            <name>READ</name>
+        </action>
+        <action>
+            <name>UPDATE</name>
+        </action>
+        <action>
+            <name>DELETE</name>
+        </action>
+        <action>
+            <name>SEARCH</name>
+        </action>
         <effect>PERMIT</effect>
         <tenant_id>1</tenant_id>
     </permission>
index da0a05f5e000b1f3f4b26a0fba6cd4c1ec1eedf8..73633d03df59cb27841af57c2077b5e566468f81 100644 (file)
  */
 package org.collectionspace.services.authorization.generator;
 
+import java.io.File;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import java.util.ArrayList;
+import java.util.Hashtable;
 import java.util.List;
+import java.util.UUID;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
 import org.collectionspace.services.authorization.ActionType;
 import org.collectionspace.services.authorization.Permission;
 import org.collectionspace.services.authorization.EffectType;
@@ -37,6 +42,9 @@ import org.collectionspace.services.authorization.PermissionsList;
 import org.collectionspace.services.authorization.PermissionsRolesList;
 import org.collectionspace.services.authorization.RoleValue;
 import org.collectionspace.services.authorization.SubjectType;
+import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;
+import org.collectionspace.services.common.service.ServiceBindingType;
+import org.collectionspace.services.common.tenant.TenantBindingType;
 
 /**
  *
@@ -45,27 +53,42 @@ import org.collectionspace.services.authorization.SubjectType;
 public class AuthorizationGen {
 
     final Logger logger = LoggerFactory.getLogger(AuthorizationGen.class);
-    private PermissionsList pcList = new PermissionsList();
-    PermissionsRolesList psrsl = new PermissionsRolesList();
+    private List<Permission> permList = new ArrayList<Permission>();
+    private List<PermissionRole> permRoleList = new ArrayList<PermissionRole>();
+    private Hashtable<String, TenantBindingType> tenantBindings =
+            new Hashtable<String, TenantBindingType>();
+
+    public void initialize(String tenantBindingFile) throws Exception {
+        TenantBindingConfigReaderImpl tenantBindingConfigReader =
+                new TenantBindingConfigReaderImpl(null);
+        tenantBindingConfigReader.read(tenantBindingFile);
+        tenantBindings = tenantBindingConfigReader.getTenantBindings();
+    }
 
-    public PermissionsList genPermissions() {
-        ArrayList<Permission> apcList = new ArrayList<Permission>();
-        pcList.setPermissions(apcList);
+    public void createDefaultServicePermissions() {
+        for (String tenantId : tenantBindings.keySet()) {
+            List<Permission> perms = createDefaultServicePermissions(tenantId);
+            permList.addAll(perms);
+        }
+    }
 
-        Permission accPerm = buildCommonPermission("1", "1", "accounts");
-        apcList.add(accPerm);
-        Permission dimPerm = buildCommonPermission("1", "2", "dimensions");
-        apcList.add(dimPerm);
-        return pcList;
+    public List<Permission> createDefaultServicePermissions(String tenantId) {
+        ArrayList<Permission> apcList = new ArrayList<Permission>();
+        TenantBindingType tbinding = tenantBindings.get(tenantId);
+        for (ServiceBindingType sbinding : tbinding.getServiceBindings()) {
+            Permission accPerm = buildCommonPermission(tbinding.getId(),
+                    sbinding.getName());
+            apcList.add(accPerm);
+        }
+        return apcList;
 
     }
 
-
-    private Permission buildCommonPermission(String tenantId, String permId, String resourceName) {
-        //String id = UUID.randomUUID().toString();
+    private Permission buildCommonPermission(String tenantId, String resourceName) {
+        String id = UUID.randomUUID().toString();
         Permission perm = new Permission();
-        perm.setCsid(permId);
-        perm.setResourceName(resourceName);
+        perm.setCsid(id);
+        perm.setResourceName(resourceName.toLowerCase());
         perm.setEffect(EffectType.PERMIT);
         perm.setTenantId(tenantId);
         ArrayList<PermissionAction> pas = new ArrayList<PermissionAction>();
@@ -83,37 +106,86 @@ public class AuthorizationGen {
         PermissionAction pa3 = new PermissionAction();
         pa3.setName(ActionType.DELETE);
         pas.add(pa3);
+        PermissionAction pa4 = new PermissionAction();
+        pa4.setName(ActionType.SEARCH);
+        pas.add(pa4);
         return perm;
     }
 
-    public PermissionsRolesList genPermissionsRoles(PermissionsList pcList) {
-        ArrayList<PermissionRole> prl = new ArrayList<PermissionRole>();
-        prl.add(buildCommonPermissionRoles("1", "1", "accounts"));
-        prl.add(buildCommonPermissionRoles("1", "2", "dimensions"));
-        psrsl.setPermissionRoles(prl);
-        return psrsl;
+    public List<Permission> getDefaultServicePermissions() {
+        return permList;
+    }
+
+    public void createDefaultPermissionsRoles(String roleName) {
+        for (Permission p : permList) {
+            PermissionRole permRole = buildCommonPermissionRoles(p.getTenantId(), p.getCsid(),
+                    p.getResourceName(), roleName);
+            permRoleList.add(permRole);
+        }
+    }
+
+    public List<PermissionRole> createPermissionsRoles(List<Permission> perms, String roleName) {
+        List<PermissionRole> permRoles = new ArrayList<PermissionRole>();
+        for (Permission p : perms) {
+            PermissionRole permRole = buildCommonPermissionRoles(p.getTenantId(), p.getCsid(),
+                    p.getResourceName(), roleName);
+            permRoles.add(permRole);
+        }
+        return permRoles;
     }
 
-    private PermissionRole buildCommonPermissionRoles(String tenantId, String permissionId,
-            String resName) {
+    private PermissionRole buildCommonPermissionRoles(String tenantId, String permId,
+            String resName, String roleName) {
 
         PermissionRole pr = new PermissionRole();
         pr.setSubject(SubjectType.ROLE);
         List<PermissionValue> permValues = new ArrayList<PermissionValue>();
         pr.setPermissions(permValues);
         PermissionValue permValue = new PermissionValue();
-        permValue.setPermissionId(permissionId);
-        permValue.setResourceName(resName);
+        permValue.setPermissionId(permId);
+        permValue.setResourceName(resName.toLowerCase());
         permValues.add(permValue);
 
         List<RoleValue> roleValues = new ArrayList<RoleValue>();
         RoleValue radmin = new RoleValue();
-        radmin.setRoleName("ROLE_ADMINISTRATOR");
+        radmin.setRoleName(roleName.toUpperCase());
         radmin.setRoleId(tenantId);
         roleValues.add(radmin);
         pr.setRoles(roleValues);
 
         return pr;
+    }
+
+    public List<PermissionRole> getDefaultServicePermissionRoles() {
+        return permRoleList;
+    }
+
+    public void exportPermissions(String fileName) {
+        PermissionsList pcList = new PermissionsList();
+        pcList.setPermissions(permList);
+        toFile(pcList, PermissionsList.class,
+                fileName);
+        logger.info("exported permissions to " + fileName);
+    }
+
+    public void exportPermissionRoles(String fileName) {
+        PermissionsRolesList psrsl = new PermissionsRolesList();
+        psrsl.setPermissionRoles(permRoleList);
+        toFile(psrsl, PermissionsRolesList.class,
+                fileName);
+        logger.info("exported permissions-roles to " + fileName);
+    }
 
+    private void toFile(Object o, Class jaxbClass, String fileName) {
+        File f = new File(fileName);
+        try {
+            JAXBContext jc = JAXBContext.newInstance(jaxbClass);
+            Marshaller m = jc.createMarshaller();
+            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
+                    Boolean.TRUE);
+            m.marshal(o, f);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
     }
 }
index 0a3d7965b79e13e47f3cedb7a34b0116c53f6000..039241090cc9815804a4a1f955101cb6472f48cf 100644 (file)
@@ -80,19 +80,8 @@ import org.testng.annotations.Test;
  */
 public abstract class AbstractAuthorizationTestImpl {
 
-    static protected final String MAVEN_BASEDIR_PROPERTY = "maven.basedir";
     final Logger logger = LoggerFactory.getLogger(AbstractAuthorizationTestImpl.class);
     private org.springframework.jdbc.datasource.DataSourceTransactionManager txManager;
-    final static String importDataDir = "src/main/resources/import-data/";
-    static String baseDir;
-
-    static {
-        baseDir = System.getProperty(AbstractAuthorizationTestImpl.MAVEN_BASEDIR_PROPERTY);
-        if (baseDir == null || baseDir.isEmpty()) {
-            baseDir = System.getProperty("user.dir");
-        }
-        baseDir = baseDir + System.getProperty("file.separator");
-    }
 
     /**
      * Returns the name of the currently running test.
@@ -147,18 +136,6 @@ public abstract class AbstractAuthorizationTestImpl {
         txManager.commit(status);
     }
 
-    static void toFile(Object o, Class jaxbClass, String fileName) {
-        File f = new File(fileName);
-        try {
-            JAXBContext jc = JAXBContext.newInstance(jaxbClass);
-            Marshaller m = jc.createMarshaller();
-            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
-                    Boolean.TRUE);
-            m.marshal(o, f);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
 
     static Object fromFile(Class jaxbClass, String fileName) throws Exception {
         InputStream is = new FileInputStream(fileName);
@@ -179,21 +156,6 @@ public abstract class AbstractAuthorizationTestImpl {
     }
 
 
-    public void writePermissions(PermissionsList pcList, String fileName) {
-        AbstractAuthorizationTestImpl.toFile(pcList, PermissionsList.class,
-                AbstractAuthorizationTestImpl.importDataDir + fileName);
-        logger.info("generated permissions to "
-                + AbstractAuthorizationTestImpl.importDataDir + fileName);
-    }
-
-    
-    public void writePermissionRoles(PermissionsRolesList psrsl, String fileName) {
-        AbstractAuthorizationTestImpl.toFile(psrsl, PermissionsRolesList.class,
-                AbstractAuthorizationTestImpl.importDataDir + fileName);
-        logger.info("generated permissions-roles to "
-                + AbstractAuthorizationTestImpl.importDataDir + fileName);
-    }
-
     @Test(dataProvider = "testName", dataProviderClass = AbstractAuthorizationTestImpl.class)
     public void test(String testName) {
         if (logger.isDebugEnabled()) {
index 0f5997ee5340cc46f0b9fc2eeed1b6b57b5e885d..292ad614baf79efd19c97469cf06df8da71eb655 100644 (file)
@@ -25,8 +25,8 @@ package org.collectionspace.services.authorization.importer;
 
 //import java.util.ArrayList;
 //import java.util.List;
+import java.io.File;
 import org.collectionspace.services.authorization.generator.AuthorizationGen;
-import org.collectionspace.services.authorization.importer.AbstractAuthorizationTestImpl;
 import java.util.ArrayList;
 import java.util.List;
 import org.collectionspace.services.authorization.ActionType;
@@ -62,10 +62,13 @@ public class AuthorizationSeedTest extends AbstractAuthorizationTestImpl {
         TransactionStatus status = beginTransaction("seedData");
         try {
             AuthorizationGen authzGen = new AuthorizationGen();
-            PermissionsList pl = authzGen.genPermissions();
-            writePermissions(pl, PERMISSION_FILE);
-            PermissionsRolesList prl = authzGen.genPermissionsRoles(pl);
-            writePermissionRoles(prl, PERMISSION_ROLE_FILE);
+            String tenantBindingFile = getTenantBindingFile();
+            authzGen.initialize(tenantBindingFile);
+            authzGen.createDefaultServicePermissions();
+            authzGen.createDefaultPermissionsRoles("ROLE_ADMINISTRATOR");
+            String exportDir = getExportDir();
+            authzGen.exportPermissions(exportDir + PERMISSION_FILE);
+            authzGen.exportPermissionRoles(exportDir + PERMISSION_ROLE_FILE);
             seedRoles();
             seedPermissions();
         } catch (Exception ex) {
@@ -81,16 +84,17 @@ public class AuthorizationSeedTest extends AbstractAuthorizationTestImpl {
     }
 
     public void seedPermissions() throws Exception {
+        String importDir = getImportDir();
         PermissionsList pcList =
-                (PermissionsList) fromFile(PermissionsList.class, baseDir
-                + AbstractAuthorizationTestImpl.importDataDir + PERMISSION_FILE);
+                (PermissionsList) fromFile(PermissionsList.class,
+                importDir + PERMISSION_FILE);
         logger.info("read permissions from "
-                + baseDir + AbstractAuthorizationTestImpl.importDataDir +  PERMISSION_FILE);
+                + importDir + PERMISSION_FILE);
         PermissionsRolesList pcrList =
-                (PermissionsRolesList) fromFile(PermissionsRolesList.class, baseDir
-                + AbstractAuthorizationTestImpl.importDataDir + PERMISSION_ROLE_FILE);
+                (PermissionsRolesList) fromFile(PermissionsRolesList.class,
+                importDir + PERMISSION_ROLE_FILE);
         logger.info("read permissions-roles from "
-                + baseDir + AbstractAuthorizationTestImpl.importDataDir +  PERMISSION_ROLE_FILE);
+                + importDir + PERMISSION_ROLE_FILE);
         AuthZ authZ = AuthZ.get();
         for (Permission p : pcList.getPermissions()) {
             if (logger.isDebugEnabled()) {
@@ -157,4 +161,31 @@ public class AuthorizationSeedTest extends AbstractAuthorizationTestImpl {
         }
         throw new IllegalArgumentException("action = " + action.toString());
     }
+
+    private String getTenantBindingFile() {
+        String tenantBindingFile = System.getProperty("tenantbindings");
+        if (tenantBindingFile == null || tenantBindingFile.isEmpty()) {
+            throw new IllegalStateException("tenantbindings are required."
+                    + " System property tenantbindings is missing or empty");
+        }
+        return tenantBindingFile;
+    }
+
+    private String getImportDir() {
+        String importDir = System.getProperty("importdir");
+        if (importDir == null || importDir.isEmpty()) {
+            throw new IllegalStateException("importdir required."
+                    + " System property importdir is missing or empty");
+        }
+        return importDir + File.separator;
+    }
+
+    private String getExportDir() {
+        String exportDir = System.getProperty("exportdir");
+        if (exportDir == null || exportDir.isEmpty()) {
+            throw new IllegalStateException("exportdir required."
+                    + " System property exportdir is missing or empty");
+        }
+        return exportDir + File.separator;
+    }
 }
index ed79fa52a689abefb4c8d311a0f302ecdf86e9ed..034ba5770a27e96075871ff9efd6e9b768a96c88 100644 (file)
@@ -52,8 +52,10 @@ public abstract class AbstractConfigReaderImpl<T>
     abstract public void read() throws Exception;
 
     @Override
-    abstract public T getConfiguration();
+    abstract public void read(String configFile) throws Exception;
 
+    @Override
+    abstract public T getConfiguration();
 
     /**
      * parse parses given configuration file from the disk based on given class
@@ -67,17 +69,17 @@ public abstract class AbstractConfigReaderImpl<T>
         JAXBContext jc = JAXBContext.newInstance(clazz);
         Unmarshaller um = jc.createUnmarshaller();
         Object readObject = um.unmarshal(configFile);
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug("read() read file " + configFile.getAbsolutePath());
         }
         return readObject;
     }
 
     protected String getAbsoluteFileName(String configFileName) {
-        return serverRootDir +
-                File.separator + CSPACE_DIR_NAME +
-                File.separator + CONFIG_DIR_NAME +
-                File.separator + configFileName;
+        return serverRootDir
+                + File.separator + CSPACE_DIR_NAME
+                + File.separator + CONFIG_DIR_NAME
+                File.separator + configFileName;
     }
 
     protected String getServerRootDir() {
index 689841cf82d4368f29114ac413d3ab7968254916..74bf767d2bdde499692850d29b029c079ac57464 100644 (file)
@@ -21,7 +21,6 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
 package org.collectionspace.services.common.config;
 
 import java.io.File;
@@ -41,11 +40,18 @@ public interface ConfigReader<T> {
     public String getFileName();
 
     /**
-     * read parse and read the configruation file.
+     * read parse and read the default configruation file from default location
      * @throws Exception
      */
     public void read() throws Exception;
 
+    /**
+     * read parse and read the given configruation file.
+     * @param configFile fully qualified file name
+     * @throws Exception
+     */
+    public void read(String configFile) throws Exception;
+
     /**
      * getConfig get configuration binding
      * @return
index 7a15ab37498c681baa84a0898e531e262040e9a5..e1621d062847da5d11a7e22aa1ec0dd4fc28dc72 100644 (file)
@@ -55,26 +55,34 @@ public class ServicesConfigReaderImpl
     @Override
     public void read() throws Exception {
         String configFileName = getAbsoluteFileName(CONFIG_FILE_NAME);
+        read(configFileName);
+    }
+
+    @Override
+    public void read(String configFileName) throws Exception {
+        if (logger.isDebugEnabled()) {
+            logger.debug("read() config file=" + configFileName);
+        }
         File configFile = new File(configFileName);
-        if(!configFile.exists()){
+        if (!configFile.exists()) {
             String msg = "Could not find configuration file " + configFileName;
             logger.error(msg);
             throw new RuntimeException(msg);
         }
         serviceConfig = (ServiceConfig) parse(configFile, ServiceConfig.class);
         clientType = serviceConfig.getRepositoryClient().getClientType();
-        if(clientType == null){
+        if (clientType == null) {
             String msg = "Missing <client-type> in <repository-client>";
             logger.error(msg);
             throw new IllegalArgumentException(msg);
         }
         clientClassName = serviceConfig.getRepositoryClient().getClientClass();
-        if(clientClassName == null){
+        if (clientClassName == null) {
             String msg = "Missing <client-class> in <repository-client>";
             logger.error(msg);
             throw new IllegalArgumentException(msg);
         }
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug("using client=" + clientType.toString() + " class=" + clientClassName);
         }
     }
index df575594aae1b4a04eb165812352f4a2ce1cc14a..38bd41569111b765315e016c300f6bf79b39c421 100644 (file)
@@ -47,7 +47,7 @@ public class TenantBindingConfigReaderImpl
     final private static String CONFIG_FILE_NAME = "tenant-bindings.xml";
     final Logger logger = LoggerFactory.getLogger(TenantBindingConfigReaderImpl.class);
     private TenantBindingConfig tenantBindingConfig;
-    //tenant name, tenant binding
+    //tenant id, tenant binding
     private Hashtable<String, TenantBindingType> tenantBindings =
             new Hashtable<String, TenantBindingType>();
     //tenant-qualified servicename, service binding
@@ -66,6 +66,14 @@ public class TenantBindingConfigReaderImpl
     @Override
     public void read() throws Exception {
         String configFileName = getAbsoluteFileName(CONFIG_FILE_NAME);
+        read(configFileName);
+    }
+
+    @Override
+    public void read(String configFileName) throws Exception {
+        if (logger.isDebugEnabled()) {
+            logger.debug("read() config file=" + configFileName);
+        }
         File configFile = new File(configFileName);
         if (!configFile.exists()) {
             String msg = "Could not find configuration file " + configFileName;
@@ -108,7 +116,7 @@ public class TenantBindingConfigReaderImpl
     public Hashtable<String, TenantBindingType> getTenantBindings() {
         return tenantBindings;
     }
-    
+
     /**
      * getTenantBinding gets tenant binding for given tenant
      * @param tenantId
@@ -154,7 +162,6 @@ public class TenantBindingConfigReaderImpl
         return list;
     }
 
-
     /**
      * @param tenantId
      * @param serviceName