From: Sanjay Dalal Date: Wed, 26 May 2010 23:18:24 +0000 (+0000) Subject: CSPACE-1935 moved import driver out of test framework into a standalone utility X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=e42e8bc561d136f2be4569a861f62a08e621c086;p=tmp%2Fjakarta-migration.git CSPACE-1935 moved import driver out of test framework into a standalone utility use ant import at any level to invoke the driver. requires build. !!NOTE!! this change overrides req. of mvn test (at authorization-mgt/import) as described in r2225 to import default permissions cd trunk mvn test -DskipTests ant import ant undeploy deploy mvn test D trunk/services/authorization-mgt/import/src/test/java/org/collectionspace/services/authorization/importer/AuthorizationSeedTest.java D trunk/services/authorization-mgt/import/src/test/java/org/collectionspace/services/authorization/importer/AbstractAuthorizationTestImpl.java D trunk/services/authorization-mgt/import/src/test/resources/applicationContext-authorization-test.xml D trunk/services/authorization-mgt/import/src/test/resources/log4j.properties A trunk/services/authorization-mgt/import/src/main/java/org/collectionspace/services/authorization/driver A + trunk/services/authorization-mgt/import/src/main/java/org/collectionspace/services/authorization/driver/AuthorizationSeedDriver.java A trunk/services/authorization-mgt/import/src/main/java/org/collectionspace/ImportAuthz.java M trunk/services/authorization-mgt/import/src/main/resources/import-data/import-permissions.xml M trunk/services/authorization-mgt/import/src/main/resources/import-data/import-permissions-roles.xml A + trunk/services/authorization-mgt/import/src/main/resources/applicationContext-authorization-test.xml A + trunk/services/authorization-mgt/import/src/main/resources/log4j.properties M trunk/services/authorization-mgt/import/pom.xml M trunk/services/authorization-mgt/import/build.xml M trunk/services/authorization-mgt/build.xml M trunk/services/pom.xml M trunk/services/build.xml M trunk/build.xml --- diff --git a/build.xml b/build.xml index 0e51cdb26..849b79fb2 100644 --- a/build.xml +++ b/build.xml @@ -222,6 +222,10 @@ + + + diff --git a/services/authorization-mgt/build.xml b/services/authorization-mgt/build.xml index db79361bf..d3d59c4b5 100644 --- a/services/authorization-mgt/build.xml +++ b/services/authorization-mgt/build.xml @@ -115,6 +115,11 @@ description="create tables(s), indices for authorization service"> + + + + diff --git a/services/authorization-mgt/import/build.xml b/services/authorization-mgt/import/build.xml index 8c3f0950c..00a232e9e 100644 --- a/services/authorization-mgt/import/build.xml +++ b/services/authorization-mgt/import/build.xml @@ -110,6 +110,29 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/authorization-mgt/import/pom.xml b/services/authorization-mgt/import/pom.xml index afaff3a63..2cbd6c92c 100644 --- a/services/authorization-mgt/import/pom.xml +++ b/services/authorization-mgt/import/pom.xml @@ -48,8 +48,10 @@ testng 5.6 - - + + commons-cli + commons-cli + org.springframework.security spring-security-core @@ -113,48 +115,51 @@ mysql mysql-connector-java - test - - - cspace-services-authorization-mgt-import - - - org.apache.maven.plugins - maven-surefire-plugin - - - - log4j.configuration - file:${project.build.directory}/test-classes/log4j.properties - - - importdir - ${basedir}/src/main/resources/import-data/ - - - exportdir - ${basedir}/src/main/resources/import-data/ - - - tenantbindings - ${basedir}/../../common/src/main/config/services/tenant-bindings.xml - - - spring-beans-config - applicationContext-authorization-test.xml - - - - - - - + + + cspace-services-authorization-mgt-import + + + org.codehaus.mojo + exec-maven-plugin + + + + java + + + + + org.collectionspace.ImportAuthz + + -u + test + -p + test + -b + ${basedir}/../../common/src/main/config/services/tenant-bindings.xml + -idir + ${basedir}/src/main/resources/import-data/ + -edir + ${basedir}/src/main/resources/import-data/ + + + + + + + mysql + mysql-connector-java + 5.1.5 + + + + + + diff --git a/services/authorization-mgt/import/src/main/java/org/collectionspace/ImportAuthz.java b/services/authorization-mgt/import/src/main/java/org/collectionspace/ImportAuthz.java new file mode 100644 index 000000000..39358525d --- /dev/null +++ b/services/authorization-mgt/import/src/main/java/org/collectionspace/ImportAuthz.java @@ -0,0 +1,80 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + + * http://www.collectionspace.org + * http://wiki.collectionspace.org + + * Copyright 2010 University of California at Berkeley + + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + + * You may obtain a copy of the ECL 2.0 License at + + * https://source.collectionspace.org/collection-space/LICENSE.txt + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.collectionspace; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.collectionspace.services.authorization.driver.AuthorizationSeedDriver; + +/** + * ImportAuthz imports default permissions and roles for a tenant(s) + * @authorF + */ +public class ImportAuthz { + + public static void main(String[] args) { + + Options options = createOptions(); + + CommandLineParser parser = new GnuParser(); + try { + // parse the command line arguments + CommandLine line = parser.parse(options, args); + String user = line.getOptionValue("u"); + String password = line.getOptionValue("p"); + String tenantBinding = line.getOptionValue("b"); + String importDir = line.getOptionValue("idir"); + String exportDir = line.getOptionValue("edir"); + System.out.println("user=" + user + + " password=" + password + + " tenantBinding=" + tenantBinding + + " importDir=" + importDir + + " exportDir=" + exportDir); + AuthorizationSeedDriver driver = new AuthorizationSeedDriver( + user, password, tenantBinding, importDir, exportDir); + driver.seedData(); + } catch (ParseException exp) { + // oops, something went wrong + System.err.println("Parsing failed. Reason: " + exp.getMessage()); + } + + } + + private static Options createOptions() { + Options options = new Options(); + options.addOption("u", true, "username"); + options.addOption("p", true, "password"); + options.addOption("b", true, "tenant binding file"); + options.addOption("idir", true, "import dir"); + options.addOption("edir", true, "export dir"); + return options; + } +} diff --git a/services/authorization-mgt/import/src/main/java/org/collectionspace/services/authorization/driver/AuthorizationSeedDriver.java b/services/authorization-mgt/import/src/main/java/org/collectionspace/services/authorization/driver/AuthorizationSeedDriver.java new file mode 100644 index 000000000..34cac1756 --- /dev/null +++ b/services/authorization-mgt/import/src/main/java/org/collectionspace/services/authorization/driver/AuthorizationSeedDriver.java @@ -0,0 +1,168 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + + * http://www.collectionspace.org + * http://wiki.collectionspace.org + + * Copyright 2009 University of California at Berkeley + + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + + * You may obtain a copy of the ECL 2.0 License at + + * https://source.collectionspace.org/collection-space/LICENSE.txt + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.authorization.driver; + +import java.io.File; +import java.util.HashSet; +import org.collectionspace.services.authorization.AuthZ; +import org.collectionspace.services.authorization.importer.AuthorizationGen; +import org.collectionspace.services.authorization.importer.AuthorizationSeed; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.GrantedAuthorityImpl; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.transaction.TransactionDefinition; +import org.springframework.transaction.TransactionStatus; +import org.springframework.transaction.support.DefaultTransactionDefinition; + +/** + * A driver for seeding authorization + * @author + */ +public class AuthorizationSeedDriver { + + final Logger logger = LoggerFactory.getLogger(AuthorizationSeedDriver.class); + final static private String SPRING_SECURITY_METADATA = "applicationContext-authorization-test.xml"; + final static private String PERMISSION_FILE = "import-permissions.xml"; + final static private String PERMISSION_ROLE_FILE = "import-permissions-roles.xml"; + private String user = "test"; + private String password = "test"; + private String tenantBindingFile; + private String importDir; + private String exportDir; + private org.springframework.jdbc.datasource.DataSourceTransactionManager txManager; + + /** + * AuthorizationSeedDriver + * @param user to use to establish security context. should be in ROLE_ADMINISTRATOR + * @param password + * @param tenantBindingFile + * @param importDir dir to import permisison/permission role file from. same as + * export dir by default + * @param exportDir dir to export permission/permission role file to + */ + public AuthorizationSeedDriver(String user, String password, + String tenantBindingFile, + String importDir, String exportDir) { + if (user == null || user.isEmpty()) { + this.user = user; + } + if (password == null || password.isEmpty()) { + this.password = password; + } + if (tenantBindingFile == null || tenantBindingFile.isEmpty()) { + throw new IllegalStateException("tenantbindings are required."); + } + this.tenantBindingFile = tenantBindingFile; + if (exportDir == null || exportDir.isEmpty()) { + throw new IllegalStateException("exportdir required."); + } + this.exportDir = exportDir; + if (importDir == null || importDir.isEmpty()) { + importDir = exportDir; + } else { + this.importDir = importDir; + } + + } + + public void seedData() { + setup(); + TransactionStatus status = null; + try { + AuthorizationGen authzGen = new AuthorizationGen(); + authzGen.initialize(tenantBindingFile); + authzGen.createDefaultServicePermissions(); + //create default role(s) for the tenant and assign permissions + authzGen.createDefaultPermissionsRoles(); + authzGen.exportPermissions(exportDir + File.separator + PERMISSION_FILE); + authzGen.exportPermissionRoles(exportDir + File.separator + PERMISSION_ROLE_FILE); + if (logger.isDebugEnabled()) { + logger.debug("authroization generation completed "); + } + status = beginTransaction("seedData"); + AuthorizationSeed authzSeed = new AuthorizationSeed(); + authzSeed.seedPermissions(importDir + File.separator + PERMISSION_FILE, + importDir + File.separator + PERMISSION_ROLE_FILE); + if (logger.isDebugEnabled()) { + logger.debug("authroization seeding completed "); + } + } catch (Exception ex) { + if (status != null) { + rollbackTransaction(status); + } + if (logger.isDebugEnabled()) { + ex.printStackTrace(); + } + throw new RuntimeException(ex); + } finally { + if (status != null) { + commitTransaction(status); + } + logout(); + } + } + + private void setup() { + + ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( + new String[]{SPRING_SECURITY_METADATA}); + login(); + System.setProperty("spring-beans-config", SPRING_SECURITY_METADATA); + AuthZ authZ = AuthZ.get(); + txManager = (org.springframework.jdbc.datasource.DataSourceTransactionManager) appContext.getBean("transactionManager"); + } + + private void login() { + GrantedAuthority gauth = new GrantedAuthorityImpl("ROLE_ADMINISTRATOR"); + HashSet gauths = new HashSet(); + gauths.add(gauth); + Authentication authRequest = new UsernamePasswordAuthenticationToken(user, password, gauths); + SecurityContextHolder.getContext().setAuthentication(authRequest); + } + + private void logout() { + SecurityContextHolder.getContext().setAuthentication(null); + } + + private TransactionStatus beginTransaction(String name) { + DefaultTransactionDefinition def = new DefaultTransactionDefinition(); + // explicitly setting the transaction name is something that can only be done programmatically + def.setName(name); + def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); + return txManager.getTransaction(def); + } + + private void rollbackTransaction(TransactionStatus status) { + txManager.rollback(status); + } + + private void commitTransaction(TransactionStatus status) { + txManager.commit(status); + } +} diff --git a/services/authorization-mgt/import/src/test/resources/applicationContext-authorization-test.xml b/services/authorization-mgt/import/src/main/resources/applicationContext-authorization-test.xml similarity index 100% rename from services/authorization-mgt/import/src/test/resources/applicationContext-authorization-test.xml rename to services/authorization-mgt/import/src/main/resources/applicationContext-authorization-test.xml diff --git a/services/authorization-mgt/import/src/main/resources/import-data/import-permissions-roles.xml b/services/authorization-mgt/import/src/main/resources/import-data/import-permissions-roles.xml index ba1894f87..e13af6a5e 100644 --- a/services/authorization-mgt/import/src/main/resources/import-data/import-permissions-roles.xml +++ b/services/authorization-mgt/import/src/main/resources/import-data/import-permissions-roles.xml @@ -3,7 +3,7 @@ ROLE - 6d0904e3-1c2a-4944-ad0a-af81137ad241 + 2bfb81c6-6d08-4928-aa56-1b3c22f52af1 idgenerators @@ -14,7 +14,7 @@ ROLE - 7ca72d08-8540-406f-a209-635260a3e2e3 + 69302e5e-2600-45e3-937b-b18cd1a1009d id @@ -25,7 +25,7 @@ ROLE - 98df1810-145f-4366-9f38-8081daf99aba + cd9da6b0-672a-445a-8c91-8eb60790c163 /idgenerators/*/ids @@ -38,7 +38,7 @@ ROLE - 1ceb338a-be76-4913-86dc-bb51f29228c9 + 5a39680a-a76c-4c35-88ce-01ce78f70866 collectionobjects @@ -49,7 +49,7 @@ ROLE - 43ebe549-645a-4c0a-9b77-630d26120a6a + c7adacd4-d663-4979-af33-309cff3c1d5b /collectionobjects/*/authorityrefs/ @@ -62,7 +62,7 @@ ROLE - 447f0bbf-9025-4fbf-bc1e-e94b33e4fab4 + 026c638d-7b59-4e07-9ac8-55f4cf5bcf88 intakes @@ -73,7 +73,7 @@ ROLE - 6ae8ba20-9d5c-4022-82fb-2147aaad5db5 + afd64e21-5e85-4103-a005-ebdd1768689e /intakes/*/authorityrefs/ @@ -86,7 +86,7 @@ ROLE - 457959c6-26b4-4c27-9ef2-702b46388322 + 2e9ceeeb-df32-4f8a-94ad-064b2e56c35e loansin @@ -97,7 +97,7 @@ ROLE - b6cf71bc-f0f9-429e-b1f8-2179174c26b4 + 74e0498d-86ff-4e2e-812f-7f894c7a0842 /loansin/*/authorityrefs/ @@ -110,7 +110,7 @@ ROLE - 5ed1e42d-ac29-457e-b120-4e90ae64e5c0 + 6b1dd0f9-6eb4-40fb-b8d4-c68f85d992fc loansout @@ -121,7 +121,7 @@ ROLE - 51398d80-c7cb-42bc-ae19-f8785e760d8a + 835ddebc-ab0c-46ca-9bed-7cd65901fec9 /loansout/*/authorityrefs/ @@ -134,7 +134,7 @@ ROLE - f243161f-b4f7-49d3-a677-011aff503e4b + cb18affd-0c86-4c80-85ab-cd01fc0169e4 movements @@ -145,7 +145,7 @@ ROLE - a4c44ee5-a2e4-4ae1-96f2-d518b52c671d + 73c7c7e1-d652-4b1b-8c2f-a0f6d31e861d /movements/*/authorityrefs/ @@ -158,7 +158,7 @@ ROLE - 05683f59-425c-4905-a409-afc431575f00 + 75d80adc-5dc5-4044-b463-ca549f920d12 vocabularies @@ -169,7 +169,7 @@ ROLE - 871a2940-e0f5-4b1e-883f-5c82f8b54bc1 + 7ed9eb73-fe3c-4f34-be69-40c7dd4c8cfe vocabularyitems @@ -180,7 +180,7 @@ ROLE - 59308529-1b27-4b64-a416-0e7c4111298d + ba430b16-d4c2-455d-a5f0-a006c56fba40 /vocabularies/*/items/ @@ -193,7 +193,7 @@ ROLE - ba1e62dc-a307-43ac-9bf4-c5ebd5b2c5a9 + e51f2c07-8cec-423e-909d-f7e26b708250 orgauthorities @@ -204,7 +204,7 @@ ROLE - ea432445-4b14-4f95-8c7c-9df78aca1014 + 6057bcf9-6130-42fb-9a39-6912fa337861 /orgauthorities/*/items/*/authorityrefs/ @@ -217,7 +217,7 @@ ROLE - eb0fcb27-0fa4-4bef-926a-4d2c61fab1ae + 719809d0-3afb-48b2-bd35-76690eb409d4 organizations @@ -228,7 +228,7 @@ ROLE - c1dd9142-3b30-4eda-a0ad-1500363d46f8 + fd8483fb-8ddc-432f-88fe-6f1f858f5b8d /orgauthorities/*/items/ @@ -241,7 +241,7 @@ ROLE - 96f95210-28ab-4afc-bac9-60f36fac7f62 + 20fad09b-86b3-4fc4-9f77-e6f0c83e3b4f /orgauthorities/*/items/*/refobjs @@ -254,7 +254,7 @@ ROLE - 7edd3f7a-5c1a-49fa-8637-a3a6060f774c + 0f5f7073-6ad7-4149-9c7d-522759d08619 personauthorities @@ -265,7 +265,7 @@ ROLE - b349723a-b280-4529-9aec-65cc2c27ff7e + 0bbcae28-a9f8-4093-b797-ec61f4777243 /personauthorities/*/items/ @@ -278,7 +278,7 @@ ROLE - d984acd2-ece2-4237-9e09-a9338c8911dd + 30e5b4c8-853d-406e-9053-7b3689f38e13 /personauthorities/*/items/*/refobjs @@ -291,7 +291,7 @@ ROLE - 3f497baa-d97f-433b-8a01-b01e8b5a583e + cee68b4a-5d74-4c7b-99b5-79ea1d6d84e6 persons @@ -302,7 +302,7 @@ ROLE - cc6ed459-a4c9-4126-8753-ebdef3f6ab56 + e6166551-917f-4802-bb8f-33e9a26897a6 /personauthorities/*/items/ @@ -315,7 +315,7 @@ ROLE - a045f459-84e0-4f1d-ba4d-33b976b58dac + cd071fb9-93ab-4d84-9a48-2763cb5505d2 locationauthorities @@ -326,7 +326,7 @@ ROLE - da805588-5f6d-4ae5-8626-8c3d4fcbd6c2 + e66aca29-4fb6-4800-a776-93988d5ae16a /locationauthorities/*/items/ @@ -339,7 +339,7 @@ ROLE - 3521bf00-a2b9-4a61-98c6-f46157bd70e5 + 6b961b0d-1cb6-4358-a469-4c3b058fee3f locations @@ -350,7 +350,7 @@ ROLE - 29bbddcd-64e3-4c72-8d4e-c7d2686ee30f + 51a94926-b603-43f8-9e2d-a371c0e42fc4 acquisitions @@ -361,7 +361,7 @@ ROLE - a497fed0-b2f9-49f1-aeac-e3a148ce8cde + 3387d9e0-f942-436e-8f15-8a2b53d6669c /acquisitions/*/authorityrefs/ @@ -374,7 +374,7 @@ ROLE - 3203c248-2ad3-4b5c-8c9f-04d3608e2370 + 01a98695-da9a-4e94-b94a-f1c18228a520 relations @@ -385,7 +385,7 @@ ROLE - 78ee728f-35e0-41d1-ae87-af1a84846bc8 + 8703dd4c-72b6-46a6-8c35-fb5bf86a6c92 relations/subject/*/type/*/object/* @@ -398,7 +398,7 @@ ROLE - 749e6ff2-db57-40a2-8888-922c516a66db + 97f34c8a-e978-467e-9881-15ebc2d11f05 accounts @@ -409,7 +409,7 @@ ROLE - 75c36eaa-ccf5-4122-b3cd-5a4b9a071a15 + eb0e3f69-96db-4f05-9316-021094bbcfec dimensions @@ -420,7 +420,7 @@ ROLE - 3d1b9ce5-2ad7-4e6a-a7d8-a125bdf2c8b6 + 10d0cf8b-1759-4692-8553-391e2bb568f3 contacts @@ -431,7 +431,7 @@ ROLE - c0937cac-e60d-4d61-b1cc-6ba119e40faa + 4da515c5-cf33-4eb7-b0ab-3ace1d3192a6 /personauthorities/*/items/*/contacts @@ -444,7 +444,7 @@ ROLE - 3c04ae32-03ff-4ef5-a6ed-13af7394417b + 7a00e318-ea14-4ebb-906f-8aea1bc9f0c4 /orgauthorities/*/items/*/contacts @@ -457,7 +457,7 @@ ROLE - 6fc381f7-3220-4fab-a382-76bd1e56d8bf + bda263c9-148f-452d-8e87-98b7427fc054 notes @@ -468,7 +468,7 @@ ROLE - b9a7f2b4-443e-4b9c-8a0c-f21885001e10 + 180ab379-d045-43f9-8ce0-6e7bbc23ce72 authorization/roles @@ -479,7 +479,7 @@ ROLE - 3978c246-704e-4a13-83f7-90c8f8c0e677 + 1874f2cd-17ce-407a-ae12-31206906ae18 authorization/permissions @@ -490,7 +490,7 @@ ROLE - 09a1e617-e852-4f42-a4c5-0c30388cd1f2 + cfe9fa81-c846-4025-b212-5c4a1f51298b authorization/permissions/permroles @@ -501,7 +501,7 @@ ROLE - e8260135-bd04-472b-b19b-0a2859ce4710 + 39872df7-2f7b-4f80-859a-ee01e3c5c995 /authorization/permissions/*/permroles/ @@ -514,7 +514,7 @@ ROLE - fa6547b0-9539-4cee-b4e0-0110da144f47 + 7376c78f-faef-40f2-a22a-ee1b4790d951 accounts/accountroles @@ -525,7 +525,7 @@ ROLE - 9c3fdc8d-907b-4de9-99fd-3b3fe6e20296 + 305b230d-f5cf-43c4-bdc4-474c0520aeed /accounts/*/accountroles/ diff --git a/services/authorization-mgt/import/src/main/resources/import-data/import-permissions.xml b/services/authorization-mgt/import/src/main/resources/import-data/import-permissions.xml index afa860c8d..2d6f074ef 100644 --- a/services/authorization-mgt/import/src/main/resources/import-data/import-permissions.xml +++ b/services/authorization-mgt/import/src/main/resources/import-data/import-permissions.xml @@ -1,6 +1,6 @@ - + idgenerators CREATE @@ -20,7 +20,7 @@ PERMIT 1 - + id CREATE @@ -40,7 +40,7 @@ PERMIT 1 - + /idgenerators/*/ids @@ -62,7 +62,7 @@ PERMIT 1 - + collectionobjects CREATE @@ -82,7 +82,7 @@ PERMIT 1 - + /collectionobjects/*/authorityrefs/ @@ -104,7 +104,7 @@ PERMIT 1 - + intakes CREATE @@ -124,7 +124,7 @@ PERMIT 1 - + /intakes/*/authorityrefs/ @@ -146,7 +146,7 @@ PERMIT 1 - + loansin CREATE @@ -166,7 +166,7 @@ PERMIT 1 - + /loansin/*/authorityrefs/ @@ -188,7 +188,7 @@ PERMIT 1 - + loansout CREATE @@ -208,7 +208,7 @@ PERMIT 1 - + /loansout/*/authorityrefs/ @@ -230,7 +230,7 @@ PERMIT 1 - + movements CREATE @@ -250,7 +250,7 @@ PERMIT 1 - + /movements/*/authorityrefs/ @@ -272,7 +272,7 @@ PERMIT 1 - + vocabularies CREATE @@ -292,7 +292,7 @@ PERMIT 1 - + vocabularyitems CREATE @@ -312,7 +312,7 @@ PERMIT 1 - + /vocabularies/*/items/ @@ -334,7 +334,7 @@ PERMIT 1 - + orgauthorities CREATE @@ -354,7 +354,7 @@ PERMIT 1 - + /orgauthorities/*/items/*/authorityrefs/ @@ -376,7 +376,7 @@ PERMIT 1 - + organizations CREATE @@ -396,7 +396,7 @@ PERMIT 1 - + /orgauthorities/*/items/ @@ -418,7 +418,7 @@ PERMIT 1 - + /orgauthorities/*/items/*/refobjs @@ -440,7 +440,7 @@ PERMIT 1 - + personauthorities CREATE @@ -460,7 +460,7 @@ PERMIT 1 - + /personauthorities/*/items/ @@ -482,7 +482,7 @@ PERMIT 1 - + /personauthorities/*/items/*/refobjs @@ -504,7 +504,7 @@ PERMIT 1 - + persons CREATE @@ -524,7 +524,7 @@ PERMIT 1 - + /personauthorities/*/items/ @@ -546,7 +546,7 @@ PERMIT 1 - + locationauthorities CREATE @@ -566,7 +566,7 @@ PERMIT 1 - + /locationauthorities/*/items/ @@ -588,7 +588,7 @@ PERMIT 1 - + locations CREATE @@ -608,7 +608,7 @@ PERMIT 1 - + acquisitions CREATE @@ -628,7 +628,7 @@ PERMIT 1 - + /acquisitions/*/authorityrefs/ @@ -650,7 +650,7 @@ PERMIT 1 - + relations CREATE @@ -670,7 +670,7 @@ PERMIT 1 - + relations/subject/*/type/*/object/* @@ -692,7 +692,7 @@ PERMIT 1 - + accounts CREATE @@ -712,7 +712,7 @@ PERMIT 1 - + dimensions CREATE @@ -732,7 +732,7 @@ PERMIT 1 - + contacts CREATE @@ -752,7 +752,7 @@ PERMIT 1 - + /personauthorities/*/items/*/contacts @@ -774,7 +774,7 @@ PERMIT 1 - + /orgauthorities/*/items/*/contacts @@ -796,7 +796,7 @@ PERMIT 1 - + notes CREATE @@ -816,7 +816,7 @@ PERMIT 1 - + authorization/roles CREATE @@ -836,7 +836,7 @@ PERMIT 1 - + authorization/permissions CREATE @@ -856,7 +856,7 @@ PERMIT 1 - + authorization/permissions/permroles CREATE @@ -876,7 +876,7 @@ PERMIT 1 - + /authorization/permissions/*/permroles/ @@ -898,7 +898,7 @@ PERMIT 1 - + accounts/accountroles CREATE @@ -918,7 +918,7 @@ PERMIT 1 - + /accounts/*/accountroles/ diff --git a/services/authorization-mgt/import/src/test/resources/log4j.properties b/services/authorization-mgt/import/src/main/resources/log4j.properties similarity index 100% rename from services/authorization-mgt/import/src/test/resources/log4j.properties rename to services/authorization-mgt/import/src/main/resources/log4j.properties diff --git a/services/authorization-mgt/import/src/test/java/org/collectionspace/services/authorization/importer/AbstractAuthorizationTestImpl.java b/services/authorization-mgt/import/src/test/java/org/collectionspace/services/authorization/importer/AbstractAuthorizationTestImpl.java deleted file mode 100644 index 3a6da68a1..000000000 --- a/services/authorization-mgt/import/src/test/java/org/collectionspace/services/authorization/importer/AbstractAuthorizationTestImpl.java +++ /dev/null @@ -1,147 +0,0 @@ -/** - * This document is a part of the source code and related artifacts - * for CollectionSpace, an open source collections management system - * for museums and related institutions: - - * http://www.collectionspace.org - * http://wiki.collectionspace.org - - * Copyright 2009 University of California at Berkeley - - * Licensed under the Educational Community License (ECL), Version 2.0. - * You may not use this file except in compliance with this License. - - * You may obtain a copy of the ECL 2.0 License at - - * https://source.collectionspace.org/collection-space/LICENSE.txt - - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *//** - * This document is a part of the source code and related artifacts - * for CollectionSpace, an open source collections management system - * for museums and related institutions: - - * http://www.collectionspace.org - * http://wiki.collectionspace.org - - * Copyright 2009 University of California at Berkeley - - * Licensed under the Educational Community License (ECL), Version 2.0. - * You may not use this file except in compliance with this License. - - * You may obtain a copy of the ECL 2.0 License at - - * https://source.collectionspace.org/collection-space/LICENSE.txt - - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package org.collectionspace.services.authorization.importer; - -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import java.lang.reflect.Method; -import java.util.HashSet; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; -import org.collectionspace.services.authorization.AuthZ; -import org.collectionspace.services.authorization.PermissionsList; -import org.collectionspace.services.authorization.PermissionsRolesList; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.GrantedAuthorityImpl; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.transaction.TransactionDefinition; -import org.springframework.transaction.TransactionStatus; -import org.springframework.transaction.support.DefaultTransactionDefinition; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - -/** - * - * @author - */ -public abstract class AbstractAuthorizationTestImpl { - - final Logger logger = LoggerFactory.getLogger(AbstractAuthorizationTestImpl.class); - private org.springframework.jdbc.datasource.DataSourceTransactionManager txManager; - - /** - * Returns the name of the currently running test. - * - * Note: although the return type is listed as Object[][], - * this method instead returns a String. - * - * @param m The currently running test method. - * - * @return The name of the currently running test method. - */ - @DataProvider(name = "testName") - protected static Object[][] testName(Method m) { - return new Object[][]{ - new Object[]{m.getName()} - }; - } - - protected void setup() { - ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( - new String[]{"applicationContext-authorization-test.xml"}); - login(); - AuthZ authZ = AuthZ.get(); - txManager = (org.springframework.jdbc.datasource.DataSourceTransactionManager) appContext.getBean("transactionManager"); - } - - protected void login() { - GrantedAuthority gauth = new GrantedAuthorityImpl("ROLE_ADMINISTRATOR"); - HashSet gauths = new HashSet(); - gauths.add(gauth); - Authentication authRequest = new UsernamePasswordAuthenticationToken("test", "test", gauths); - SecurityContextHolder.getContext().setAuthentication(authRequest); - } - - protected void logout() { - SecurityContextHolder.getContext().setAuthentication(null); - } - - protected TransactionStatus beginTransaction(String name) { - DefaultTransactionDefinition def = new DefaultTransactionDefinition(); - // explicitly setting the transaction name is something that can only be done programmatically - def.setName(name); - def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); - return txManager.getTransaction(def); - } - - protected void rollbackTransaction(TransactionStatus status) { - txManager.rollback(status); - } - - protected void commitTransaction(TransactionStatus status) { - txManager.commit(status); - } - - - - @Test(dataProvider = "testName", dataProviderClass = AbstractAuthorizationTestImpl.class) - public void test(String testName) { - if (logger.isDebugEnabled()) { - logger.debug(testName); - } - } -} diff --git a/services/authorization-mgt/import/src/test/java/org/collectionspace/services/authorization/importer/AuthorizationSeedTest.java b/services/authorization-mgt/import/src/test/java/org/collectionspace/services/authorization/importer/AuthorizationSeedTest.java deleted file mode 100644 index fdbef7311..000000000 --- a/services/authorization-mgt/import/src/test/java/org/collectionspace/services/authorization/importer/AuthorizationSeedTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/** - * This document is a part of the source code and related artifacts - * for CollectionSpace, an open source collections management system - * for museums and related institutions: - - * http://www.collectionspace.org - * http://wiki.collectionspace.org - - * Copyright 2009 University of California at Berkeley - - * Licensed under the Educational Community License (ECL), Version 2.0. - * You may not use this file except in compliance with this License. - - * You may obtain a copy of the ECL 2.0 License at - - * https://source.collectionspace.org/collection-space/LICENSE.txt - - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.collectionspace.services.authorization.importer; - -import java.io.File; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.transaction.TransactionStatus; -import org.testng.annotations.BeforeClass; - -/** - * - * @author - */ -public class AuthorizationSeedTest extends AbstractAuthorizationTestImpl { - - final Logger logger = LoggerFactory.getLogger(AuthorizationSeedTest.class); - final static String PERMISSION_FILE = "import-permissions.xml"; - final static String PERMISSION_ROLE_FILE = "import-permissions-roles.xml"; - - @BeforeClass(alwaysRun = true) - public void seedData() { - setup(); - TransactionStatus status = null; - try { - AuthorizationGen authzGen = new AuthorizationGen(); - String tenantBindingFile = getTenantBindingFile(); - authzGen.initialize(tenantBindingFile); - authzGen.createDefaultServicePermissions(); - //create default role(s) for the tenant and assign permissions - authzGen.createDefaultPermissionsRoles(); - String exportDir = getExportDir(); - authzGen.exportPermissions(exportDir + PERMISSION_FILE); - authzGen.exportPermissionRoles(exportDir + PERMISSION_ROLE_FILE); - if (logger.isDebugEnabled()) { - logger.debug("authroization generation completed "); - } - status = beginTransaction("seedData"); - AuthorizationSeed authzSeed = new AuthorizationSeed(); - String importDir = getImportDir(); - authzSeed.seedPermissions(importDir + PERMISSION_FILE, - importDir + PERMISSION_ROLE_FILE); - if (logger.isDebugEnabled()) { - logger.debug("authroization seeding completed "); - } - } catch (Exception ex) { - if (status != null) { - rollbackTransaction(status); - } - if (logger.isDebugEnabled()) { - ex.printStackTrace(); - } - throw new RuntimeException(ex); - } finally { - if (status != null) { - commitTransaction(status); - } - } - } - - 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; - } -} diff --git a/services/build.xml b/services/build.xml index 649eb068d..b40362135 100644 --- a/services/build.xml +++ b/services/build.xml @@ -140,6 +140,11 @@ + + + + diff --git a/services/pom.xml b/services/pom.xml index 3ff05b87f..8ee77d226 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -150,6 +150,19 @@ + + org.codehaus.mojo + exec-maven-plugin + 1.1 + + + + log4j.configuration + file:${project.build.directory}/classes/log4j.properties + + + + @@ -269,6 +282,11 @@ commons-io 1.4 + + commons-cli + commons-cli + 1.2 + com.sun.xml.bind jaxb-impl