]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-1364 allow user test in ROLE_ADMINISTRATOR to access (CRUDL) dimension service
authorSanjay Dalal <sanjay.dalal@berkeley.edu>
Wed, 12 May 2010 18:05:35 +0000 (18:05 +0000)
committerSanjay Dalal <sanjay.dalal@berkeley.edu>
Wed, 12 May 2010 18:05:35 +0000 (18:05 +0000)
CSPACE-1365 deny user bigbird2010 in ROLE_MMI_CM access (C) to the dimension service
moved authorization generation and seeding to authorization-mgt/client from authorization service
enabled access control for the dimension service only in the security interceptor
added setAuth convenience method into client test framework to change authn properites, httpclient and proxy
test: all service tests, specifically security/client and authorization-mgt/client tests

!!REQUIRES the following sequence of actions at the services level
- mvn clean install -DskipTests
- ant undeploy deploy
- mvn test (note that authorization-mgt/client tests have to run before running dimension/client and security/client tests)

A    services/authorization-mgt/service/src/test/javadoc
A    services/authorization-mgt/service/src/test/javadoc/org
A    services/authorization-mgt/service/src/test/javadoc/org/collectionspace
A    services/authorization-mgt/service/src/test/javadoc/org/collectionspace/services
A    services/authorization-mgt/service/src/test/javadoc/org/collectionspace/services/authorization
A    services/authorization-mgt/service/src/test/javadoc/org/collectionspace/services/authorization/test
A  + services/authorization-mgt/service/src/test/javadoc/org/collectionspace/services/authorization/test/package.html
M    services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/AuthorizationDelegate.java
A    services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/test
A  + services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/test/AuthorizationSeedTest.java
A  + services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/test/AbstractAuthorizationTestImpl.java
A  + services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/test/AuthorizationGen.java
A  + services/authorization-mgt/client/src/test/resources/applicationContext-authorization-test.xml
A    services/authorization-mgt/client/src/test/resources/test-data
A  + services/authorization-mgt/client/src/test/resources/test-data/test-permissions.xml
A  + services/authorization-mgt/client/src/test/resources/test-data/test-permissions-roles.xml
M    services/authorization-mgt/client/pom.xml
M    services/dimension/client/src/test/java/org/collectionspace/services/client/test/DimensionServiceTest.java
A    services/dimension/client/src/main/java/org/collectionspace/services/client/DimensionFactory.java
M    services/dimension/client/pom.xml
D    services/authorization/service/src/test/java/org/collectionspace/services/authorization/test/AuthorizationSeedTest.java
D    services/authorization/service/src/test/java/org/collectionspace/services/authorization/test/AbstractAuthorizationTestImpl.java
D    services/authorization/service/src/test/java/org/collectionspace/services/authorization/test/AuthorizationGen.java
D    services/authorization/service/src/test/javadoc/org/collectionspace/services/authorization/test/package.html
D    services/authorization/service/src/test/resources/applicationContext-authorization-test.xml
D    services/authorization/service/src/test/resources/test-data/test-permissions.xml
D    services/authorization/service/src/test/resources/test-data/test-permissions-roles.xml
M    services/authorization/service/pom.xml
M    services/authorization/pstore/src/main/resources/db/mysql/test_authorization.sql
M    services/common/src/main/java/org/collectionspace/services/common/security/SecurityInterceptor.java
M    services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthenticationServiceTest.java
A    services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthorizationServiceTest.java
M    services/security/client/pom.xml
M    services/client/src/main/java/org/collectionspace/services/client/test/BaseServiceTest.java
M    services/client/src/main/java/org/collectionspace/services/client/TestServiceClient.java
M    services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java
M    services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClient.java

22 files changed:
services/authorization-mgt/client/pom.xml
services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/test/AbstractAuthorizationTestImpl.java [moved from services/authorization/service/src/test/java/org/collectionspace/services/authorization/test/AbstractAuthorizationTestImpl.java with 100% similarity]
services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/test/AuthorizationGen.java [moved from services/authorization/service/src/test/java/org/collectionspace/services/authorization/test/AuthorizationGen.java with 97% similarity]
services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/test/AuthorizationSeedTest.java [moved from services/authorization/service/src/test/java/org/collectionspace/services/authorization/test/AuthorizationSeedTest.java with 55% similarity]
services/authorization-mgt/client/src/test/resources/applicationContext-authorization-test.xml [moved from services/authorization/service/src/test/resources/applicationContext-authorization-test.xml with 98% similarity]
services/authorization-mgt/client/src/test/resources/test-data/test-permissions-roles.xml [moved from services/authorization/service/src/test/resources/test-data/test-permissions-roles.xml with 94% similarity]
services/authorization-mgt/client/src/test/resources/test-data/test-permissions.xml [moved from services/authorization/service/src/test/resources/test-data/test-permissions.xml with 94% similarity]
services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/AuthorizationDelegate.java
services/authorization-mgt/service/src/test/javadoc/org/collectionspace/services/authorization/test/package.html [moved from services/authorization/service/src/test/javadoc/org/collectionspace/services/authorization/test/package.html with 100% similarity]
services/authorization/pstore/src/main/resources/db/mysql/test_authorization.sql
services/authorization/service/pom.xml
services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java
services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClient.java
services/client/src/main/java/org/collectionspace/services/client/TestServiceClient.java
services/client/src/main/java/org/collectionspace/services/client/test/BaseServiceTest.java
services/common/src/main/java/org/collectionspace/services/common/security/SecurityInterceptor.java
services/dimension/client/pom.xml
services/dimension/client/src/main/java/org/collectionspace/services/client/DimensionFactory.java [new file with mode: 0644]
services/dimension/client/src/test/java/org/collectionspace/services/client/test/DimensionServiceTest.java
services/security/client/pom.xml
services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthenticationServiceTest.java
services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthorizationServiceTest.java [new file with mode: 0644]

index e0554bef54698dfc5377927c26c5579a90f7db62..0e694320a963f9d79e4df2455018b6ddbd140a43 100644 (file)
     <groupId>org.collectionspace.services</groupId>\r
     <artifactId>org.collectionspace.services.authorization-mgt.client</artifactId>\r
     <name>services.authorization-mgt.client</name>\r
-    \r
+    <properties>\r
+        <spring.version>3.0.0.RELEASE</spring.version>\r
+        <spring.security.version>3.0.2.RELEASE</spring.security.version>\r
+    </properties>\r
     <dependencies>\r
         <!-- keep slf4j dependencies on the top -->\r
         <dependency>\r
             <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.authorization.jaxb</artifactId>\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>mysql</groupId>\r
-            <artifactId>mysql-connector-java</artifactId>\r
-            <scope>test</scope>\r
-        </dependency>        \r
         <!-- <dependency>\r
             <groupId>org.collectionspace.services</groupId>\r
             <artifactId>org.collectionspace.services.client</artifactId>\r
@@ -53,7 +63,7 @@
             <groupId>org.testng</groupId>\r
             <artifactId>testng</artifactId>\r
             <version>5.6</version>\r
-        </dependency>       \r
+        </dependency>\r
         <dependency>\r
             <groupId>org.jboss.resteasy</groupId>\r
             <artifactId>resteasy-jaxrs</artifactId>\r
             <artifactId>commons-httpclient</artifactId>\r
             <version>3.1</version>\r
         </dependency>\r
+\r
+        <dependency>\r
+            <groupId>org.springframework.security</groupId>\r
+            <artifactId>spring-security-core</artifactId>\r
+            <version>${spring.security.version}</version>\r
+            <scope>provided</scope>\r
+        </dependency>\r
+        <dependency>\r
+            <groupId>org.springframework.security</groupId>\r
+            <artifactId>spring-security-config</artifactId>\r
+            <version>${spring.security.version}</version>\r
+            <scope>provided</scope>\r
+        </dependency>\r
+        <dependency>\r
+            <groupId>org.springframework.security</groupId>\r
+            <artifactId>spring-security-acl</artifactId>\r
+            <version>${spring.security.version}</version>\r
+            <scope>provided</scope>\r
+        </dependency>\r
+        <dependency>\r
+            <groupId>org.springframework.security</groupId>\r
+            <artifactId>spring-security-web</artifactId>\r
+            <version>${spring.security.version}</version>\r
+            <scope>provided</scope>\r
+        </dependency>\r
+        <dependency>\r
+            <groupId>org.springframework</groupId>\r
+            <artifactId>spring-context</artifactId>\r
+            <version>${spring.version}</version>\r
+            <scope>provided</scope>\r
+        </dependency>\r
+        <dependency>\r
+            <groupId>org.springframework</groupId>\r
+            <artifactId>spring-context-support</artifactId>\r
+            <version>${spring.version}</version>\r
+            <scope>provided</scope>\r
+        </dependency>\r
+        <dependency>\r
+            <groupId>org.springframework</groupId>\r
+            <artifactId>spring-aop</artifactId>\r
+            <version>${spring.version}</version>\r
+            <scope>provided</scope>\r
+        </dependency>\r
+        <dependency>\r
+            <groupId>aopalliance</groupId>\r
+            <artifactId>aopalliance</artifactId>\r
+            <version>1.0</version>\r
+            <scope>provided</scope>\r
+        </dependency>\r
+        <!--dependency>\r
+            <groupId>org.springframework</groupId>\r
+            <artifactId>spring-tx</artifactId>\r
+            <version>${spring.version}</version>\r
+            <scope>provided</scope>\r
+        </dependency-->\r
+        <dependency>\r
+            <groupId>net.sf.ehcache</groupId>\r
+            <artifactId>ehcache</artifactId>\r
+            <version>1.6.2</version>\r
+            <optional>true</optional>\r
+        </dependency>\r
+        <dependency>\r
+            <groupId>mysql</groupId>\r
+            <artifactId>mysql-connector-java</artifactId>\r
+            <scope>test</scope>\r
+        </dependency>\r
     </dependencies>\r
 \r
     <build>\r
         <finalName>cspace-services-authorization-mgt-client</finalName>\r
-        <plugins>            \r
+        <plugins>\r
+            <plugin>\r
+                <groupId>org.apache.maven.plugins</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>spring-beans-config</name>\r
+                            <value>applicationContext-authorization-test.xml</value>\r
+                        </property>\r
+                    </systemProperties>\r
+                </configuration>\r
+            </plugin>\r
         </plugins>\r
     </build>\r
 \r
@@ -75,8 +75,8 @@ public class AuthorizationGen {
 
         Permission accPerm = buildCommonPermission("1", "accounts");
         apcList.add(accPerm);
-        Permission coPerm = buildCommonPermission("2", "collectionobjects");
-        apcList.add(coPerm);
+        Permission dimPerm = buildCommonPermission("2", "dimensions");
+        apcList.add(dimPerm);
         AbstractAuthorizationTestImpl.toFile(pcList, PermissionsList.class,
                 AbstractAuthorizationTestImpl.testDataDir + "test-permissions.xml");
         logger.info("generated permissions to "
@@ -112,7 +112,7 @@ public class AuthorizationGen {
         PermissionsRolesList psrsl = new PermissionsRolesList();
         ArrayList<PermissionRole> prl = new ArrayList<PermissionRole>();
         prl.add(buildCommonPermissionRoles("1", "accounts"));
-        prl.add(buildCommonPermissionRoles("2", "collectionobjects"));
+        prl.add(buildCommonPermissionRoles("2", "dimensions"));
         psrsl.setPermissionRoles(prl);
         AbstractAuthorizationTestImpl.toFile(psrsl, PermissionsRolesList.class,
                 AbstractAuthorizationTestImpl.testDataDir + "test-permissions-roles.xml");
@@ -25,14 +25,22 @@ package org.collectionspace.services.authorization.test;
 
 //import java.util.ArrayList;
 //import java.util.List;
+import java.util.ArrayList;
+import java.util.List;
+import org.collectionspace.services.authorization.ActionType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 //import org.collectionspace.services.client.test.BaseServiceTest;
 import org.collectionspace.services.authorization.AuthZ;
+import org.collectionspace.services.authorization.CSpaceAction;
 import org.collectionspace.services.authorization.Permission;
+import org.collectionspace.services.authorization.PermissionAction;
+import org.collectionspace.services.authorization.PermissionException;
 import org.collectionspace.services.authorization.PermissionRole;
 import org.collectionspace.services.authorization.PermissionsList;
 import org.collectionspace.services.authorization.PermissionsRolesList;
+import org.collectionspace.services.authorization.RoleValue;
+import org.collectionspace.services.authorization.URIResourceImpl;
 import org.springframework.transaction.TransactionStatus;
 import org.testng.annotations.BeforeClass;
 
@@ -84,9 +92,64 @@ public class AuthorizationSeedTest extends AbstractAuthorizationTestImpl {
             }
             for (PermissionRole pr : pcrList.getPermissionRoles()) {
                 if (pr.getPermissions().get(0).getPermissionId().equals(p.getCsid())) {
-//                    authZ.addPermissionsForUri(p, pr);
+                    addPermissionsForUri(p, pr);
                 }
             }
         }
     }
+
+        /**
+     * addPermissionsForUri add permissions from given permission configuration
+     * with assumption that resource is of type URI
+     * @param permission configuration
+     */
+    //FIXME this method should be in the restful web service resource of authz
+    private void addPermissionsForUri(Permission perm,
+            PermissionRole permRole) throws PermissionException {
+        List<String> principals = new ArrayList<String>();
+        if (!perm.getCsid().equals(permRole.getPermissions().get(0).getPermissionId())) {
+            throw new IllegalArgumentException("permission ids do not"
+                    + " match for role=" + permRole.getRoles().get(0).getRoleName()
+                    + " with permissionId=" + permRole.getPermissions().get(0).getPermissionId()
+                    + " for permission with csid=" + perm.getCsid());
+        }
+        for (RoleValue roleValue : permRole.getRoles()) {
+            principals.add(roleValue.getRoleName());
+        }
+        List<PermissionAction> permActions = perm.getActions();
+        for (PermissionAction permAction : permActions) {
+            CSpaceAction action = getAction(permAction.getName());
+            URIResourceImpl uriRes = new URIResourceImpl(perm.getTenantId(),
+                    perm.getResourceName(), action);
+            AuthZ.get().addPermissions(uriRes, principals.toArray(new String[0]));
+        }
+    }
+
+
+    /**
+     * getAction is a convenience method to get corresponding action for
+     * given ActionType
+     * @param action
+     * @return
+     */
+    private CSpaceAction getAction(ActionType action) {
+        if (ActionType.CREATE.equals(action)) {
+            return CSpaceAction.CREATE;
+        } else if (ActionType.READ.equals(action)) {
+            return CSpaceAction.READ;
+        } else if (ActionType.UPDATE.equals(action)) {
+            return CSpaceAction.UPDATE;
+        } else if (ActionType.DELETE.equals(action)) {
+            return CSpaceAction.DELETE;
+        } else if (ActionType.SEARCH.equals(action)) {
+            return CSpaceAction.SEARCH;
+        } else if (ActionType.ADMIN.equals(action)) {
+            return CSpaceAction.ADMIN;
+        } else if (ActionType.START.equals(action)) {
+            return CSpaceAction.START;
+        } else if (ActionType.STOP.equals(action)) {
+            return CSpaceAction.STOP;
+        }
+        throw new IllegalArgumentException("action = " + action.toString());
+    }
 }
similarity index 98%
rename from services/authorization/service/src/test/resources/applicationContext-authorization-test.xml
rename to services/authorization-mgt/client/src/test/resources/applicationContext-authorization-test.xml
index d9f03ee47224c60712da4e89085d93c5054d3498..856c38d94be3105f34844517be66a5718e714249 100644 (file)
@@ -88,5 +88,6 @@
     <bean id="cspaceAuthorizationProvider" class="org.collectionspace.services.authorization.spring.SpringAuthorizationProvider">
         <property name="providerAclService" ref="aclService"/>
         <property name="providerPermissionEvaluator" ref="permissionEvaluator"/>
+        <property name="txManager" ref="transactionManager"/>
     </bean>
 </beans>
similarity index 94%
rename from services/authorization/service/src/test/resources/test-data/test-permissions-roles.xml
rename to services/authorization-mgt/client/src/test/resources/test-data/test-permissions-roles.xml
index 5a0ff571541324650e71e8203bf7991b43d95db6..ea59f111552ef776a27b3fc3158b2019df927b9c 100644 (file)
@@ -19,7 +19,7 @@
         <subject>ROLE</subject>
         <permission>
             <permissionId>2</permissionId>
-            <resourceName>collectionobjects</resourceName>
+            <resourceName>dimensions</resourceName>
         </permission>
         <role>
             <roleId>1</roleId>
similarity index 94%
rename from services/authorization/service/src/test/resources/test-data/test-permissions.xml
rename to services/authorization-mgt/client/src/test/resources/test-data/test-permissions.xml
index 512f2127cb083bf24096286e2cd1874be8f8959e..3287d54ff5b280b96423e583ec0e596a0ad79060 100644 (file)
@@ -18,7 +18,7 @@
         <tenant_id>1</tenant_id>
     </permission>
     <permission csid="2">
-        <resourceName>collectionobjects</resourceName>
+        <resourceName>dimensions</resourceName>
         <action>
             <name>CREATE</name>
         </action>
index 79a22b7be645bb2ac7316cfc1f20830f30b6a776..a4d7deabb1dd93cfcd4180b4cd490ef90f947814 100644 (file)
@@ -125,32 +125,7 @@ public class AuthorizationDelegate {
         }
     }
 
-    /**
-     * addPermissionsForUri add permissions from given permission configuration
-     * with assumption that resource is of type URI
-     * @param permission configuration
-     */
-    //FIXME this method should be in the restful web service resource of authz
-    public void addPermissionsForUri(Permission perm,
-            PermissionRole permRole) throws PermissionException {
-        List<String> principals = new ArrayList<String>();
-        if (!perm.getCsid().equals(permRole.getPermissions().get(0).getPermissionId())) {
-            throw new IllegalArgumentException("permission ids do not"
-                    + " match for role=" + permRole.getRoles().get(0).getRoleName()
-                    + " with permissionId=" + permRole.getPermissions().get(0).getPermissionId()
-                    + " for permission with csid=" + perm.getCsid());
-        }
-        for (RoleValue roleValue : permRole.getRoles()) {
-            principals.add(roleValue.getRoleName());
-        }
-        List<PermissionAction> permActions = perm.getActions();
-        for (PermissionAction permAction : permActions) {
-            CSpaceAction action = getAction(permAction.getName());
-            URIResourceImpl uriRes = new URIResourceImpl(perm.getTenantId(),
-                    perm.getResourceName(), action);
-            AuthZ.get().addPermissions(uriRes, principals.toArray(new String[0]));
-        }
-    }
+
 
     /**
      * getRoles get roles (string) array from given RoleValue list
index fdb980beb97e0d84edf333f81e891da5dd0043df..de65dd6108a95fc5a630c365a92fb11f54f6eeae 100644 (file)
@@ -15,9 +15,9 @@ insert into `accounts_roles`(`account_id`, `user_id`, `role_id`, `role_name`, `c
 insert into `accounts_roles`(`account_id`, `user_id`, `role_id`, `role_name`, `created_at`) values ('eeca40d7-dc77-4cc5-b489-16a53c75525a', 'test', '3', 'ROLE_COLLECTIONS_MANAGER', '2010-02-17 16:31:48');\r
 \r
 -- Additional account introduced during integration on release 0.6, and currently relied upon by the Application Layer.\r
-insert into `accounts_roles`(`account_id`, `user_id`, `role_id`, `role_name`, `created_at`) values ('251f98f3-0292-4f3e-aa95-455314050e1b', 'test', '1', 'ROLE_ADMINISTRATOR', '2010-05-03 12:35:00');\r
-insert into `accounts_roles`(`account_id`, `user_id`, `role_id`, `role_name`, `created_at`) values ('251f98f3-0292-4f3e-aa95-455314050e1b', 'test', '2', 'ROLE_USERS', '2010-05-03 12:35:00');\r
-insert into `accounts_roles`(`account_id`, `user_id`, `role_id`, `role_name`, `created_at`) values ('251f98f3-0292-4f3e-aa95-455314050e1b', 'test', '3', 'ROLE_COLLECTIONS_MANAGER', '2010-05-03 12:35:00');\r
+insert into `accounts_roles`(`account_id`, `user_id`, `role_id`, `role_name`, `created_at`) values ('251f98f3-0292-4f3e-aa95-455314050e1b', 'test@collectionspace.org', '1', 'ROLE_ADMINISTRATOR', '2010-05-03 12:35:00');\r
+insert into `accounts_roles`(`account_id`, `user_id`, `role_id`, `role_name`, `created_at`) values ('251f98f3-0292-4f3e-aa95-455314050e1b', 'test@collectionspace.org', '2', 'ROLE_USERS', '2010-05-03 12:35:00');\r
+insert into `accounts_roles`(`account_id`, `user_id`, `role_id`, `role_name`, `created_at`) values ('251f98f3-0292-4f3e-aa95-455314050e1b', 'test@collectionspace.org', '3', 'ROLE_COLLECTIONS_MANAGER', '2010-05-03 12:35:00');\r
 \r
 -- todo: barney is created in security test but accountrole is not yet created there, so add fake account id\r
 insert into `accounts_roles`(`account_id`, `user_id`, `role_id`, `role_name`, `created_at`) values ('1', 'barney', '2', 'ROLE_USERS', '2010-02-17 16:31:48');\r
index e1d7e05709a39aa6c1fa2de4be68e5aa823c8b72..a04763f039d0b02784d59685b34e0c59f8b12bc2 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project xmlns="http://maven.apache.org/POM/4.0.0"
-    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <artifactId>org.collectionspace.services.authorization</artifactId>
             <groupId>org.collectionspace.services</groupId>
             <artifactId>org.collectionspace.services.authorization.jaxb</artifactId>
             <version>${project.version}</version>
+            <scope>provided</scope>
         </dependency>
 
     </dependencies>
     <build>
         <finalName>cspace-services-authz</finalName>
         <plugins>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-surefire-plugin</artifactId>
-                <configuration>
-                    <systemProperties>
-                        <property>
-                            <name>maven.basedir</name>
-                            <value>${basedir}</value>
-                        </property>           
-                        <property>
-                            <name>log4j.configuration</name>
-                            <value>file:${project.build.directory}/test-classes/log4j.properties</value>
-                        </property>
-                        <property>
-                            <name>spring-beans-config</name>
-                            <value>applicationContext-authorization-test.xml</value>
-                        </property>
-                    </systemProperties>
-                </configuration>
-            </plugin>
+
         </plugins>
     </build>
 </project>
index 1aa2f03807b41846b56d0ba6ec527323e993f32c..1b5b5c369924b68b9f13582246dd52ac7d43b8df 100644 (file)
@@ -46,280 +46,305 @@ import org.slf4j.LoggerFactory;
  * @param <ListType> \r
  */\r
 public abstract class AbstractServiceClientImpl implements\r
-       CollectionSpaceClient {\r
-\r
-       /** The logger. */\r
-       protected final Logger logger = LoggerFactory\r
-       .getLogger(AbstractServiceClientImpl.class);\r
-\r
-       /**\r
-        * The character used to separate the words in a part label\r
-        */\r
-       public static final String PART_LABEL_SEPERATOR = "_";\r
-\r
-       /** The Constant PART_COMMON_LABEL. */\r
-       public static final String PART_COMMON_LABEL = "common";\r
-\r
-       /** The properties. */\r
-       private Properties properties = new Properties();\r
-\r
-       /** The url. */\r
-       private URL url;\r
-\r
-       /** The http client. */\r
-       private HttpClient httpClient;\r
-\r
-       /**\r
-        * Gets the common part name.\r
-        * \r
-        * @return the common part name\r
-        */\r
-       public String getCommonPartName() {\r
-               return getCommonPartName(getServicePathComponent());\r
-       }\r
-\r
-       /**\r
-        * Gets the common part name.\r
-        * \r
-        * @param servicePathComponent\r
-        *            the service path component\r
-        * @return the common part name\r
-        */\r
-       public String getCommonPartName(String servicePathComponent) {\r
-               return servicePathComponent + PART_LABEL_SEPERATOR + PART_COMMON_LABEL;\r
-       }\r
-\r
-       /**\r
-        * Gets the service path component.\r
-        * \r
-        * @return the service path component\r
-        */\r
-       abstract public String getServicePathComponent();\r
-\r
-       /**\r
-        * Instantiates a new abstract service client impl.\r
-        */\r
-       protected AbstractServiceClientImpl() {\r
-               readProperties();\r
-               setupHttpClient();\r
-       }\r
-\r
-       /*\r
-        * (non-Javadoc)\r
-        * \r
-        * @see\r
-        * org.collectionspace.services.client.CollectionSpaceClient#getProperty\r
-        * (java.lang.String)\r
-        */\r
-       @Override\r
-       public String getProperty(String propName) {\r
-               return properties.getProperty(propName);\r
-       }\r
-\r
-       /*\r
-        * (non-Javadoc)\r
-        * \r
-        * @see\r
-        * org.collectionspace.services.client.CollectionSpaceClient#setProperty\r
-        * (java.lang.String, java.lang.String)\r
-        */\r
-       @Override\r
-       public void setProperty(String propName, String value) {\r
-               properties.setProperty(propName, value);\r
-       }\r
-\r
-       /*\r
-        * (non-Javadoc)\r
-        * \r
-        * @see\r
-        * org.collectionspace.services.client.CollectionSpaceClient#removeProperty\r
-        * (java.lang.String)\r
-        */\r
-       @Override\r
-       public Object removeProperty(String propName) {\r
-               return properties.remove(propName);\r
-       }\r
-\r
-       /**\r
-        * Prints the properties.\r
-        */\r
-       public void printProperties() {\r
-               for (Object kobj : properties.keySet()) {\r
-                       String key = (String) kobj;\r
-                       logger.trace("begin property name=" + key + " value="\r
-                                       + properties.get(key));\r
-               }\r
-       }\r
-\r
-       /*\r
-        * (non-Javadoc)\r
-        * \r
-        * @see\r
-        * org.collectionspace.services.client.CollectionSpaceClient#getBaseURL()\r
-        */\r
-       @Override\r
-       public String getBaseURL() {\r
-               return properties.getProperty(URL_PROPERTY);\r
-       }\r
-\r
-       /*\r
-        * (non-Javadoc)\r
-        * \r
-        * @see\r
-        * org.collectionspace.services.client.CollectionSpaceClient#getHttpClient()\r
-        */\r
-       @Override\r
-       public HttpClient getHttpClient() {\r
-               return httpClient;\r
-       }\r
-\r
-       /*\r
-        * (non-Javadoc)\r
-        * \r
-        * @see org.collectionspace.services.client.CollectionSpaceClient#useAuth()\r
-        */\r
-       @Override\r
-       public boolean useAuth() {\r
-               String auth = properties.getProperty(AUTH_PROPERTY);\r
-               return Boolean.valueOf(auth);\r
-       }\r
-\r
-       /*\r
-        * (non-Javadoc)\r
-        * \r
-        * @see org.collectionspace.services.client.CollectionSpaceClient#useSSL()\r
-        */\r
-       @Override\r
-       public boolean useSSL() {\r
-               String ssl = properties.getProperty(SSL_PROPERTY);\r
-               return Boolean.valueOf(ssl);\r
-       }\r
-\r
-       /**\r
-        * readProperties reads properties from system class path as well as it\r
-        * overrides properties made available using command line\r
-        * \r
-        * @exception RuntimeException\r
-        */\r
-       private void readProperties() {\r
-\r
-               ClassLoader cl = Thread.currentThread().getContextClassLoader();\r
-               InputStream is = null;\r
-               try {\r
-                       is = cl.getResourceAsStream("collectionspace-client.properties");\r
-                       properties.load(is);\r
-                       if (logger.isDebugEnabled()) {\r
-                               printProperties();\r
-                       }\r
-                       String spec = System.getProperty(URL_PROPERTY);\r
-                       if (spec != null && !"".equals(spec)) {\r
-                               properties.setProperty(URL_PROPERTY, spec);\r
-                       }\r
-\r
-                       spec = properties.getProperty(URL_PROPERTY);\r
-                       url = new URL(spec);\r
-                       if (logger.isInfoEnabled()) {\r
-                               logger.info("readProperties() using url=" + url);\r
-                       }\r
-\r
-                       String auth = System.getProperty(AUTH_PROPERTY);\r
-                       if (auth != null && !"".equals(auth)) {\r
-                               properties.setProperty(AUTH_PROPERTY, auth);\r
-                       }\r
-                       String ssl = System.getProperty(SSL_PROPERTY);\r
-                       if (ssl != null && !"".equals(ssl)) {\r
-                               properties.setProperty(AUTH_PROPERTY, ssl);\r
-                       }\r
-                       String user = System.getProperty(USER_PROPERTY);\r
-                       if (user != null && !"".equals(user)) {\r
-                               properties.setProperty(USER_PROPERTY, user);\r
-                       }\r
-                       String password = System.getProperty(PASSWORD_PROPERTY);\r
-                       if (password != null && !"".equals(password)) {\r
-                               properties.setProperty(PASSWORD_PROPERTY, password);\r
-                       }\r
-                       if (logger.isDebugEnabled()) {\r
-                               printProperties();\r
-                       }\r
-               } catch (Exception e) {\r
-                       logger.debug("Caught exception while reading properties", e);\r
-                       throw new RuntimeException(e);\r
-               } finally {\r
-                       if (is != null) {\r
-                               try {\r
-                                       is.close();\r
-                               } catch (Exception e) {\r
-                                       if (logger.isDebugEnabled() == true) {\r
-                                               e.printStackTrace();\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-\r
-       /**\r
-        * setupHttpClient sets up HTTP client for the service client the setup\r
-        * process relies on the following properties URL_PROPERTY USER_PROPERTY\r
-        * PASSWORD_PROPERTY AUTH_PROPERTY SSL_PROPERTY\r
-        */\r
-       @Override\r
-       public void setupHttpClient() {\r
-               this.httpClient = new HttpClient();\r
-               if (useAuth()) {\r
-                       String user = properties.getProperty(USER_PROPERTY);\r
-                       String password = properties.getProperty(PASSWORD_PROPERTY);\r
-                       if (logger.isInfoEnabled()) {\r
-                               logger.info("setupHttpClient() using url=" + url + " user="\r
-                                               + user + " password=" + password);\r
-                       }\r
-\r
-                       httpClient.getState().setCredentials(\r
-                                       new AuthScope(url.getHost(), url.getPort(),\r
-                                                       AuthScope.ANY_REALM),\r
-                                                       new UsernamePasswordCredentials(user, password));\r
-                       // JAXRS client library requires HTTP preemptive authentication\r
-                       httpClient.getParams().setAuthenticationPreemptive(true);\r
-                       if (logger.isInfoEnabled()) {\r
-                               logger.info("setupHttpClient: set preemptive authentication");\r
-                       }\r
-               } else {\r
-                       if (logger.isInfoEnabled()) {\r
-                               logger.info("setupHttpClient() : no auth mode!");\r
-                       }\r
-               }\r
-       }\r
-\r
-       /*\r
-        * (non-Javadoc)\r
-        * \r
-        * @see\r
-        * org.collectionspace.services.client.CollectionSpaceClient#isServerSecure\r
-        * ()\r
-        */\r
-       @Override\r
-       public boolean isServerSecure() {\r
-               return Boolean.getBoolean("cspace.server.secure");\r
-       }\r
-\r
-       /*\r
-        * (non-Javadoc)\r
-        * \r
-        * @see\r
-        * org.collectionspace.services.client.CollectionSpaceClient#readList(java\r
-        * .lang.String, java.lang.String)\r
-        */\r
-       @Override\r
-       public ClientResponse<AbstractCommonList> readList(String pageSize,\r
-                       String pageNumber) {\r
-               return getProxy().readList(pageSize, pageNumber);\r
-       }\r
-       \r
-       /* (non-Javadoc)\r
-        * @see org.collectionspace.services.client.CollectionSpaceClient#delete(java.lang.String)\r
-        */\r
+        CollectionSpaceClient {\r
+\r
+    /** The logger. */\r
+    protected final Logger logger = LoggerFactory.getLogger(AbstractServiceClientImpl.class);\r
+    /**\r
+     * The character used to separate the words in a part label\r
+     */\r
+    public static final String PART_LABEL_SEPERATOR = "_";\r
+    /** The Constant PART_COMMON_LABEL. */\r
+    public static final String PART_COMMON_LABEL = "common";\r
+    /** The properties. */\r
+    private Properties properties = new Properties();\r
+    /** The url. */\r
+    private URL url;\r
+    /** The http client. */\r
+    private HttpClient httpClient;\r
+\r
+    /**\r
+     * Gets the common part name.\r
+     *\r
+     * @return the common part name\r
+     */\r
+    public String getCommonPartName() {\r
+        return getCommonPartName(getServicePathComponent());\r
+    }\r
+\r
+    /**\r
+     * Gets the common part name.\r
+     *\r
+     * @param servicePathComponent\r
+     *            the service path component\r
+     * @return the common part name\r
+     */\r
+    public String getCommonPartName(String servicePathComponent) {\r
+        return servicePathComponent + PART_LABEL_SEPERATOR + PART_COMMON_LABEL;\r
+    }\r
+\r
+    /**\r
+     * Gets the service path component.\r
+     *\r
+     * @return the service path component\r
+     */\r
+    abstract public String getServicePathComponent();\r
+\r
+    /**\r
+     * Instantiates a new abstract service client impl.\r
+     */\r
+    protected AbstractServiceClientImpl() {\r
+        readProperties();\r
+        setupHttpClient();\r
+    }\r
+\r
+    /*\r
+     * (non-Javadoc)\r
+     *\r
+     * @see\r
+     * org.collectionspace.services.client.CollectionSpaceClient#getProperty\r
+     * (java.lang.String)\r
+     */\r
     @Override\r
-       public ClientResponse<Response> delete(String csid) {\r
-       // must override in children if you want behavior\r
-               throw new UnsupportedOperationException();\r
-       }       \r
+    public String getProperty(String propName) {\r
+        return properties.getProperty(propName);\r
+    }\r
+\r
+    /*\r
+     * (non-Javadoc)\r
+     *\r
+     * @see\r
+     * org.collectionspace.services.client.CollectionSpaceClient#setProperty\r
+     * (java.lang.String, java.lang.String)\r
+     */\r
+    @Override\r
+    public void setProperty(String propName, String value) {\r
+        properties.setProperty(propName, value);\r
+    }\r
+\r
+    /*\r
+     * (non-Javadoc)\r
+     *\r
+     * @see\r
+     * org.collectionspace.services.client.CollectionSpaceClient#removeProperty\r
+     * (java.lang.String)\r
+     */\r
+    @Override\r
+    public Object removeProperty(String propName) {\r
+        return properties.remove(propName);\r
+    }\r
+\r
+    /**\r
+     * Prints the properties.\r
+     */\r
+    public void printProperties() {\r
+        for (Object kobj : properties.keySet()) {\r
+            String key = (String) kobj;\r
+            logger.trace("begin property name=" + key + " value="\r
+                    + properties.get(key));\r
+        }\r
+    }\r
+\r
+    /*\r
+     * (non-Javadoc)\r
+     *\r
+     * @see\r
+     * org.collectionspace.services.client.CollectionSpaceClient#getBaseURL()\r
+     */\r
+    @Override\r
+    public String getBaseURL() {\r
+        return properties.getProperty(URL_PROPERTY);\r
+    }\r
+\r
+    /*\r
+     * (non-Javadoc)\r
+     *\r
+     * @see\r
+     * org.collectionspace.services.client.CollectionSpaceClient#getHttpClient()\r
+     */\r
+    @Override\r
+    public HttpClient getHttpClient() {\r
+        return httpClient;\r
+    }\r
+\r
+    /*\r
+     * (non-Javadoc)\r
+     *\r
+     * @see org.collectionspace.services.client.CollectionSpaceClient#useAuth()\r
+     */\r
+    @Override\r
+    public boolean useAuth() {\r
+        String auth = properties.getProperty(AUTH_PROPERTY);\r
+        return Boolean.valueOf(auth);\r
+    }\r
+\r
+    /*\r
+     * (non-Javadoc)\r
+     *\r
+     * @see org.collectionspace.services.client.CollectionSpaceClient#useSSL()\r
+     */\r
+    @Override\r
+    public boolean useSSL() {\r
+        String ssl = properties.getProperty(SSL_PROPERTY);\r
+        return Boolean.valueOf(ssl);\r
+    }\r
+\r
+    /**\r
+     * readProperties reads properties from system class path as well as it\r
+     * overrides properties made available using command line\r
+     *\r
+     * @exception RuntimeException\r
+     */\r
+    private void readProperties() {\r
+\r
+        ClassLoader cl = Thread.currentThread().getContextClassLoader();\r
+        InputStream is = null;\r
+        try {\r
+            is = cl.getResourceAsStream("collectionspace-client.properties");\r
+            properties.load(is);\r
+            if (logger.isDebugEnabled()) {\r
+                printProperties();\r
+            }\r
+            String spec = System.getProperty(URL_PROPERTY);\r
+            if (spec != null && !"".equals(spec)) {\r
+                properties.setProperty(URL_PROPERTY, spec);\r
+            }\r
+\r
+            spec = properties.getProperty(URL_PROPERTY);\r
+            url = new URL(spec);\r
+            if (logger.isInfoEnabled()) {\r
+                logger.info("readProperties() using url=" + url);\r
+            }\r
+\r
+            String auth = System.getProperty(AUTH_PROPERTY);\r
+            if (auth != null && !"".equals(auth)) {\r
+                properties.setProperty(AUTH_PROPERTY, auth);\r
+            }\r
+            String ssl = System.getProperty(SSL_PROPERTY);\r
+            if (ssl != null && !"".equals(ssl)) {\r
+                properties.setProperty(AUTH_PROPERTY, ssl);\r
+            }\r
+            String user = System.getProperty(USER_PROPERTY);\r
+            if (user != null && !"".equals(user)) {\r
+                properties.setProperty(USER_PROPERTY, user);\r
+            }\r
+            String password = System.getProperty(PASSWORD_PROPERTY);\r
+            if (password != null && !"".equals(password)) {\r
+                properties.setProperty(PASSWORD_PROPERTY, password);\r
+            }\r
+            if (logger.isDebugEnabled()) {\r
+                printProperties();\r
+            }\r
+        } catch (Exception e) {\r
+            logger.debug("Caught exception while reading properties", e);\r
+            throw new RuntimeException(e);\r
+        } finally {\r
+            if (is != null) {\r
+                try {\r
+                    is.close();\r
+                } catch (Exception e) {\r
+                    if (logger.isDebugEnabled() == true) {\r
+                        e.printStackTrace();\r
+                    }\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+    /**\r
+     * setupHttpClient sets up HTTP client for the service client the setup\r
+     * process relies on the following properties URL_PROPERTY USER_PROPERTY\r
+     * PASSWORD_PROPERTY AUTH_PROPERTY SSL_PROPERTY\r
+     */\r
+    @Override\r
+    public void setupHttpClient() {\r
+        this.httpClient = new HttpClient();\r
+        if (useAuth()) {\r
+            String user = properties.getProperty(USER_PROPERTY);\r
+            String password = properties.getProperty(PASSWORD_PROPERTY);\r
+            if (logger.isInfoEnabled()) {\r
+                logger.info("setupHttpClient() using url=" + url + " user="\r
+                        + user + " password=" + password);\r
+            }\r
+\r
+            httpClient.getState().setCredentials(\r
+                    new AuthScope(url.getHost(), url.getPort(),\r
+                    AuthScope.ANY_REALM),\r
+                    new UsernamePasswordCredentials(user, password));\r
+            // JAXRS client library requires HTTP preemptive authentication\r
+            httpClient.getParams().setAuthenticationPreemptive(true);\r
+            if (logger.isInfoEnabled()) {\r
+                logger.info("setupHttpClient: set preemptive authentication");\r
+            }\r
+        } else {\r
+            if (logger.isInfoEnabled()) {\r
+                logger.info("setupHttpClient() : no auth mode!");\r
+            }\r
+        }\r
+    }\r
+\r
+    /*\r
+     * (non-Javadoc)\r
+     *\r
+     * @see\r
+     * org.collectionspace.services.client.CollectionSpaceClient#isServerSecure\r
+     * ()\r
+     */\r
+    @Override\r
+    public boolean isServerSecure() {\r
+        return Boolean.getBoolean("cspace.server.secure");\r
+    }\r
+\r
+    /*\r
+     * (non-Javadoc)\r
+     *\r
+     * @see\r
+     * org.collectionspace.services.client.CollectionSpaceClient#readList(java\r
+     * .lang.String, java.lang.String)\r
+     */\r
+    @Override\r
+    public ClientResponse<AbstractCommonList> readList(String pageSize,\r
+            String pageNumber) {\r
+        return getProxy().readList(pageSize, pageNumber);\r
+    }\r
+\r
+    /* (non-Javadoc)\r
+     * @see org.collectionspace.services.client.CollectionSpaceClient#delete(java.lang.String)\r
+     */\r
+    @Override\r
+    public ClientResponse<Response> delete(String csid) {\r
+        // must override in children if you want behavior\r
+        throw new UnsupportedOperationException();\r
+    }\r
+\r
+    @Override\r
+    public abstract CollectionSpaceProxy getProxy();\r
+\r
+    @Override\r
+    public abstract void setProxy();\r
+\r
+    public void setAuth(boolean useAuth,\r
+            String user, boolean useUser,\r
+            String password, boolean usePassword) {\r
+        if (useAuth) {\r
+            setProperty(CollectionSpaceClient.AUTH_PROPERTY,\r
+                    "true");\r
+            if (useUser) {\r
+                setProperty(CollectionSpaceClient.USER_PROPERTY,\r
+                        user);\r
+            } else {\r
+                removeProperty(CollectionSpaceClient.USER_PROPERTY);\r
+            }\r
+            if (usePassword) {\r
+                setProperty(CollectionSpaceClient.PASSWORD_PROPERTY,\r
+                        password);\r
+            } else {\r
+                removeProperty(CollectionSpaceClient.PASSWORD_PROPERTY);\r
+            }\r
+        } else {\r
+            removeProperty(CollectionSpaceClient.AUTH_PROPERTY);\r
+        }\r
+        setupHttpClient();\r
+        setProxy();\r
+    }\r
 }\r
index 82adaede4f8dbbdd4e37d5c0d9e18371b606def8..d17653618bacc782915e175a3c1df7818f51f230 100644 (file)
@@ -22,8 +22,8 @@
  *  limitations under the License.
  */
 package org.collectionspace.services.client;
-import javax.ws.rs.core.Response;
 
+import javax.ws.rs.core.Response;
 import org.apache.commons.httpclient.HttpClient;
 import org.collectionspace.services.jaxb.AbstractCommonList;
 import org.jboss.resteasy.client.ClientResponse;
@@ -32,19 +32,15 @@ import org.jboss.resteasy.client.ClientResponse;
  *
  */
 public interface CollectionSpaceClient {
-    
+
     /** The AUT h_ property. */
     String AUTH_PROPERTY = "cspace.auth";
-    
     /** The PASSWOR d_ property. */
     String PASSWORD_PROPERTY = "cspace.password";
-    
     /** The SS l_ property. */
     String SSL_PROPERTY = "cspace.ssl";
-    
     /** The UR l_ property. */
     String URL_PROPERTY = "cspace.url";
-    
     /** The USE r_ property. */
     String USER_PROPERTY = "cspace.user";
 
@@ -54,7 +50,7 @@ public interface CollectionSpaceClient {
      * @return the proxy
      */
     CollectionSpaceProxy getProxy();
-    
+
     /**
      * Gets the base url.
      *
@@ -104,6 +100,25 @@ public interface CollectionSpaceClient {
      */
     void setupHttpClient();
 
+    /**
+     * setProxy for the client
+     * might be useful to reset proxy (based on auth requirements) that is usually created at the time of
+     * constructing a client
+     */
+    void setProxy();
+
+    /**
+     * setAuth sets up authentication properties based on given parameters
+     * @param useAuth
+     * @param user user name
+     * @param useUser indicates using user name
+     * @param password
+     * @param usePassword indicates using password
+     */
+    void setAuth(boolean useAuth,
+            String user, boolean useUser,
+            String password, boolean usePassword);
+
     /**
      * Use auth.
      *
@@ -123,7 +138,7 @@ public interface CollectionSpaceClient {
      * @return boolean
      */
     boolean isServerSecure();
-    
+
     /**
      * Read list.
      *
index 8374ff20865c70647e7dd8d6ab39e13609e3588b..faf5fdc16efd3266e5dcc5389afa5a1c71a186fb 100644 (file)
@@ -20,7 +20,6 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
 package org.collectionspace.services.client;
 
 import javax.ws.rs.core.Response;
@@ -33,23 +32,30 @@ import org.jboss.resteasy.client.ClientResponse;
  * @version $Revision:$
  */
 public class TestServiceClient extends AbstractServiceClientImpl {
+
     /**
-    *
-    * Returning NULL since this class is a base-level client, used (only) 
-    * to obtain the base service URL.
-    *
-    */
-       @Override
-       public String getServicePathComponent() {
-               throw new UnsupportedOperationException();
-       }
-
-       @Override
-       public CollectionSpaceProxy getProxy() {
-               throw new UnsupportedOperationException();
-       }
-       
-       public ClientResponse<Response> delete(String csid) {
-               throw new UnsupportedOperationException();
-       }
+     *
+     * Returning NULL since this class is a base-level client, used (only)
+     * to obtain the base service URL.
+     *
+     */
+    @Override
+    public String getServicePathComponent() {
+        throw new UnsupportedOperationException();
+    }
+
+
+    @Override
+    public CollectionSpaceProxy getProxy() {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void setProxy() {
+        throw new UnsupportedOperationException();
+    }
+
+    public ClientResponse<Response> delete(String csid) {
+       throw new UnsupportedOperationException();
+    } 
 }
index be29719c43a296de73199da9a822cce3e3ddfc5e..02747faa642369c6029a3dc9f90b4ae50498d986 100644 (file)
@@ -69,35 +69,26 @@ import org.collectionspace.services.jaxb.AbstractCommonList;
  */\r
 public abstract class BaseServiceTest {\r
 \r
-       //Maven's base directory -i.e., the one containing the current pom.xml\r
-       static protected final String MAVEN_BASEDIR_PROPERTY = "maven.basedir";\r
-       \r
+    //Maven's base directory -i.e., the one containing the current pom.xml\r
+    static protected final String MAVEN_BASEDIR_PROPERTY = "maven.basedir";\r
     /** The Constant logger. */\r
     static protected final Logger logger = LoggerFactory.getLogger(BaseServiceTest.class);\r
-    \r
     /** The Constant serviceClient. */\r
     protected static final TestServiceClient serviceClient = new TestServiceClient();\r
-    \r
     /** The NO n_ existen t_ id. */\r
     protected final String NON_EXISTENT_ID = createNonExistentIdentifier();\r
-    \r
     /** The EXPECTE d_ statu s_ code. */\r
     protected int EXPECTED_STATUS_CODE = 0;\r
-    \r
     /** The REQUES t_ type. */\r
     protected ServiceRequestType REQUEST_TYPE = ServiceRequestType.NON_EXISTENT;\r
-    \r
     /** The Constant XML_DECLARATION. */\r
     protected static final String XML_DECLARATION = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";\r
-    \r
     /** The Constant MALFORMED_XML_DATA. */\r
     protected static final String MALFORMED_XML_DATA = XML_DECLARATION\r
             + "<malformed_xml>wrong schema contents</malformed_xml";\r
-    \r
     /** The WRON g_ xm l_ schem a_ data. */\r
     protected final String WRONG_XML_SCHEMA_DATA = XML_DECLARATION\r
             + "<wrong_schema>wrong schema contents</wrong_schema>";\r
-    \r
     /** The NUL l_ charset. */\r
     final String NULL_CHARSET = null;\r
 \r
@@ -107,16 +98,16 @@ public abstract class BaseServiceTest {
      * @return the client\r
      */\r
     abstract protected CollectionSpaceClient getClientInstance();\r
-    \r
-       /**\r
-        * Gets the abstract common list.\r
-        *\r
-        * @param response the response\r
-        * @return the abstract common list\r
-        */\r
-       abstract protected AbstractCommonList getAbstractCommonList(\r
-                       ClientResponse<AbstractCommonList> response);    \r
-    \r
+\r
+    /**\r
+     * Gets the abstract common list.\r
+     *\r
+     * @param response the response\r
+     * @return the abstract common list\r
+     */\r
+    abstract protected AbstractCommonList getAbstractCommonList(\r
+            ClientResponse<AbstractCommonList> response);\r
+\r
     /**\r
      * Returns the name of the currently running test.\r
      *\r
index c0ac2682179c46003b0b874001546358a16d4751..2e56c89c55f317a6877670bb76ffd5ccd56fb7c9 100644 (file)
@@ -41,6 +41,8 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.ext.Provider;
 import org.collectionspace.authentication.AuthN;
 import org.collectionspace.services.authorization.AuthZ;
+import org.collectionspace.services.authorization.CSpaceResource;
+import org.collectionspace.services.authorization.URIResourceImpl;
 import org.collectionspace.services.common.document.JaxbUtils;
 import org.collectionspace.services.common.storage.jpa.JpaStorageUtils;
 import org.slf4j.Logger;
@@ -66,19 +68,21 @@ public class SecurityInterceptor implements PreProcessInterceptor {
             logger.debug("received " + httpMethod + " on " + uriPath);
         }
         checkActive();
-        AuthZ authZ = AuthZ.get();
-//        CSpaceResource res = new URIResourceImpl(uriPath, httpMethod);
-//        if (!authZ.isAccessAllowed(res)) {
-//            logger.error("Access to " + res.getId() + " is NOT allowed to " +
-//                    " user=" + AuthN.get().getUserId());
-//            Response response = Response.status(
-//                    Response.Status.FORBIDDEN).entity(uriPath + " " + httpMethod).type("text/plain").build();
-//            throw new WebApplicationException(response);
-//        }
-//        if(logger.isDebugEnabled()) {
-//            logger.debug("Access to " + res.getId() + " is allowed to " +
-//                    " user=" + AuthN.get().getUserId());
-//        }
+        if (uriPath.startsWith("dimensions")) {
+             AuthZ authZ = AuthZ.get();
+            CSpaceResource res = new URIResourceImpl(uriPath, httpMethod);
+            if (!authZ.isAccessAllowed(res)) {
+                logger.error("Access to " + res.getId() + " is NOT allowed to "
+                        + " user=" + AuthN.get().getUserId());
+                Response response = Response.status(
+                        Response.Status.FORBIDDEN).entity(uriPath + " " + httpMethod).type("text/plain").build();
+                throw new WebApplicationException(response);
+            }
+            if (logger.isDebugEnabled()) {
+                logger.debug("Access to " + res.getId() + " is allowed to "
+                        + " user=" + AuthN.get().getUserId());
+            }
+        }
         return null;
     }
 
@@ -106,7 +110,7 @@ public class SecurityInterceptor implements PreProcessInterceptor {
             }
             Object status = JaxbUtils.getValue(account, "getStatus");
             if (status != null) {
-                String value = (String)JaxbUtils.getValue(status, "value");
+                String value = (String) JaxbUtils.getValue(status, "value");
                 if ("INACTIVE".equalsIgnoreCase(value)) {
                     String msg = "User's account is inactive, userId=" + userId;
                     Response response = Response.status(
index 3bc8bcb7089f0b984a63fcf51fb76b5702cd635a..f719cbe066166f243df82d10190a9ad81efebbf9 100644 (file)
         <dependency>\r
             <groupId>org.slf4j</groupId>\r
             <artifactId>slf4j-api</artifactId>\r
-            <scope>test</scope>\r
         </dependency>\r
         <dependency>\r
             <groupId>org.slf4j</groupId>\r
             <artifactId>slf4j-log4j12</artifactId>\r
-            <scope>test</scope>\r
         </dependency>\r
         <!-- CollectionSpace dependencies -->\r
         <dependency>\r
diff --git a/services/dimension/client/src/main/java/org/collectionspace/services/client/DimensionFactory.java b/services/dimension/client/src/main/java/org/collectionspace/services/client/DimensionFactory.java
new file mode 100644 (file)
index 0000000..9afb629
--- /dev/null
@@ -0,0 +1,66 @@
+/**
+ *  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.services.client;
+
+
+
+
+import javax.ws.rs.core.MediaType;
+import org.collectionspace.services.dimension.DimensionsCommon;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
+import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * @author
+ */
+public class DimensionFactory {
+
+    static private final Logger logger =
+            LoggerFactory.getLogger(DimensionFactory.class);
+
+    /**
+     * Creates the dimension instance.
+     *
+     * @param commpnPartName
+     * @param dimension
+     * @return the multipart output
+     */
+    public static MultipartOutput createDimensionInstance(String commonPartName, 
+            DimensionsCommon dimension) {
+
+        MultipartOutput multipart = new MultipartOutput();
+        OutputPart commonPart =
+                multipart.addPart(dimension, MediaType.APPLICATION_XML_TYPE);
+        commonPart.getHeaders().add("label", commonPartName);
+
+        return multipart;
+    }
+}
index 32310fba83616ea62425ce799770526fbd9cb41c..39105d7f61d832e847856a4b9b7e8ad634da4b66 100644 (file)
@@ -29,6 +29,7 @@ import javax.ws.rs.core.Response;
 
 import org.collectionspace.services.client.CollectionSpaceClient;
 import org.collectionspace.services.client.DimensionClient;
+import org.collectionspace.services.client.DimensionFactory;
 import org.collectionspace.services.dimension.DimensionsCommon;
 import org.collectionspace.services.dimension.DimensionsCommonList;
 import org.collectionspace.services.jaxb.AbstractCommonList;
@@ -54,14 +55,12 @@ import org.slf4j.LoggerFactory;
  */
 public class DimensionServiceTest extends AbstractServiceTestImpl {
 
-   /** The logger. */
-   private final Logger logger =
-       LoggerFactory.getLogger(DimensionServiceTest.class);
-
+    /** The logger. */
+    private final Logger logger =
+            LoggerFactory.getLogger(DimensionServiceTest.class);
     // Instance variables specific to this test.
     /** The SERVIC e_ pat h_ component. */
     final String SERVICE_PATH_COMPONENT = "dimensions";
-    
     /** The known resource id. */
     private String knownResourceId = null;
 
@@ -70,15 +69,15 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
      */
     @Override
     protected CollectionSpaceClient getClientInstance() {
-       return new DimensionClient();
+        return new DimensionClient();
     }
-    
+
     /* (non-Javadoc)
      * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
      */
     @Override
-       protected AbstractCommonList getAbstractCommonList(
-                       ClientResponse<AbstractCommonList> response) {
+    protected AbstractCommonList getAbstractCommonList(
+            ClientResponse<AbstractCommonList> response) {
         return response.getEntity(DimensionsCommonList.class);
     }
 
@@ -90,7 +89,7 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
      * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
      */
     @Override
-    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
     public void create(String testName) throws Exception {
 
         // Perform setup, such as initializing the type of service request
@@ -101,7 +100,8 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
         // Submit the request to the service and store the response.
         DimensionClient client = new DimensionClient();
         String identifier = createIdentifier();
-        MultipartOutput multipart = createDimensionInstance(identifier);
+        MultipartOutput multipart = createDimensionInstance(client.getCommonPartName(),
+                identifier);
         ClientResponse<Response> res = client.create(multipart);
 
         int statusCode = res.getStatus();
@@ -112,7 +112,7 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
         // Specifically:
         // Does it fall within the set of valid status codes?
         // Does it exactly match the expected status code?
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug(testName + ": status = " + statusCode);
         }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
@@ -121,7 +121,7 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
 
         // Store the ID returned from the first resource created
         // for additional tests below.
-        if (knownResourceId == null){
+        if (knownResourceId == null) {
             knownResourceId = extractId(res);
             if (logger.isDebugEnabled()) {
                 logger.debug(testName + ": knownResourceId=" + knownResourceId);
@@ -137,10 +137,10 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
      */
     @Override
-    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
-        dependsOnMethods = {"create"})
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+    dependsOnMethods = {"create"})
     public void createList(String testName) throws Exception {
-        for(int i = 0; i < 3; i++){
+        for (int i = 0; i < 3; i++) {
             create(testName);
         }
     }
@@ -153,7 +153,7 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
      */
     @Override
     public void createWithEmptyEntityBody(String testName) throws Exception {
-       //Should this really be empty?
+        //Should this really be empty?
     }
 
     /* (non-Javadoc)
@@ -161,7 +161,7 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
      */
     @Override
     public void createWithMalformedXml(String testName) throws Exception {
-       //Should this really be empty?
+        //Should this really be empty?
     }
 
     /* (non-Javadoc)
@@ -169,13 +169,13 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
      */
     @Override
     public void createWithWrongXmlSchema(String testName) throws Exception {
-       //Should this really be empty?
+        //Should this really be empty?
     }
 
     /*
     @Override
     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
-        dependsOnMethods = {"create", "testSubmitRequest"})
+    dependsOnMethods = {"create", "testSubmitRequest"})
     public void createWithEmptyEntityBody(String testName) throws Exception {
 
     // Perform setup.
@@ -191,9 +191,9 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
     // Check the status code of the response: does it match
     // the expected response(s)?
     if(logger.isDebugEnabled()){
-        logger.debug("createWithEmptyEntityBody url=" + url +
-            " status=" + statusCode);
-     }
+    logger.debug("createWithEmptyEntityBody url=" + url +
+    " status=" + statusCode);
+    }
     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -201,7 +201,7 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
 
     @Override
     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
-        dependsOnMethods = {"create", "testSubmitRequest"})
+    dependsOnMethods = {"create", "testSubmitRequest"})
     public void createWithMalformedXml(String testName) throws Exception {
 
     // Perform setup.
@@ -217,9 +217,9 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
     // Check the status code of the response: does it match
     // the expected response(s)?
     if(logger.isDebugEnabled()){
-        logger.debug(testName + ": url=" + url +
-            " status=" + statusCode);
-     }
+    logger.debug(testName + ": url=" + url +
+    " status=" + statusCode);
+    }
     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -227,7 +227,7 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
 
     @Override
     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
-        dependsOnMethods = {"create", "testSubmitRequest"})
+    dependsOnMethods = {"create", "testSubmitRequest"})
     public void createWithWrongXmlSchema(String testName) throws Exception {
 
     // Perform setup.
@@ -243,15 +243,14 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
     // Check the status code of the response: does it match
     // the expected response(s)?
     if(logger.isDebugEnabled()){
-        logger.debug(testName + ": url=" + url +
-            " status=" + statusCode);
-     }
+    logger.debug(testName + ": url=" + url +
+    " status=" + statusCode);
+    }
     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
     }
      */
-
     // ---------------------------------------------------------------
     // CRUD tests : READ tests
     // ---------------------------------------------------------------
@@ -260,8 +259,8 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
      */
     @Override
-    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
-        dependsOnMethods = {"create"})
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+    dependsOnMethods = {"create"})
     public void read(String testName) throws Exception {
 
         // Perform setup.
@@ -274,7 +273,7 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug(testName + ": status = " + statusCode);
         }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
@@ -292,8 +291,8 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
      */
     @Override
-    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
-        dependsOnMethods = {"read"})
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+    dependsOnMethods = {"read"})
     public void readNonExistent(String testName) throws Exception {
 
         // Perform setup.
@@ -306,7 +305,7 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug(testName + ": status = " + statusCode);
         }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
@@ -322,8 +321,8 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
      */
     @Override
-    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
-        dependsOnMethods = {"read"})
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+    dependsOnMethods = {"read"})
     public void readList(String testName) throws Exception {
 
         // Perform setup.
@@ -337,7 +336,7 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug(testName + ": status = " + statusCode);
         }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
@@ -346,17 +345,17 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
 
         // Optionally output additional data about list members for debugging.
         boolean iterateThroughList = false;
-        if(iterateThroughList && logger.isDebugEnabled()){
+        if (iterateThroughList && logger.isDebugEnabled()) {
             List<DimensionsCommonList.DimensionListItem> items =
                     list.getDimensionListItem();
             int i = 0;
-            for(DimensionsCommonList.DimensionListItem item : items){
-                logger.debug(testName + ": list-item[" + i + "] csid=" +
-                        item.getCsid());
-                logger.debug(testName + ": list-item[" + i + "] objectNumber=" +
-                        item.getDimension());
-                logger.debug(testName + ": list-item[" + i + "] URI=" +
-                        item.getUri());
+            for (DimensionsCommonList.DimensionListItem item : items) {
+                logger.debug(testName + ": list-item[" + i + "] csid="
+                        item.getCsid());
+                logger.debug(testName + ": list-item[" + i + "] objectNumber="
+                        item.getDimension());
+                logger.debug(testName + ": list-item[" + i + "] URI="
+                        item.getUri());
                 i++;
             }
         }
@@ -373,8 +372,8 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
      */
     @Override
-    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
-        dependsOnMethods = {"read"})
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+    dependsOnMethods = {"read"})
     public void update(String testName) throws Exception {
 
         // Perform setup.
@@ -384,12 +383,12 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
         DimensionClient client = new DimensionClient();
         ClientResponse<MultipartInput> res =
                 client.read(knownResourceId);
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug(testName + ": read status = " + res.getStatus());
         }
         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
 
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug("got object to update with ID: " + knownResourceId);
         }
         MultipartInput input = (MultipartInput) res.getEntity();
@@ -400,7 +399,7 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
         // Update the content of this resource.
         dimension.setValue("updated-" + dimension.getValue());
         dimension.setValueDate("updated-" + dimension.getValueDate());
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug("to be updated object");
             logger.debug(objectAsXmlString(dimension, DimensionsCommon.class));
         }
@@ -412,7 +411,7 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
         res = client.update(knownResourceId, output);
         int statusCode = res.getStatus();
         // Check the status code of the response: does it match the expected response(s)?
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug(testName + ": status = " + statusCode);
         }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
@@ -423,7 +422,7 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
         input = (MultipartInput) res.getEntity();
         DimensionsCommon updatedDimension =
                 (DimensionsCommon) extractPart(input,
-                        client.getCommonPartName(), DimensionsCommon.class);
+                client.getCommonPartName(), DimensionsCommon.class);
         Assert.assertNotNull(updatedDimension);
 
         Assert.assertEquals(updatedDimension.getValueDate(),
@@ -439,30 +438,30 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
      */
     @Override
-    public void updateWithEmptyEntityBody(String testName) throws Exception{
-       //Should this really be empty?
+    public void updateWithEmptyEntityBody(String testName) throws Exception {
+        //Should this really be empty?
     }
-    
+
     /* (non-Javadoc)
      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
      */
     @Override
     public void updateWithMalformedXml(String testName) throws Exception {
-       //Should this really be empty?
+        //Should this really be empty?
     }
-    
+
     /* (non-Javadoc)
      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
      */
     @Override
     public void updateWithWrongXmlSchema(String testName) throws Exception {
-       //Should this really be empty?
+        //Should this really be empty?
     }
 
     /*
     @Override
     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
-        dependsOnMethods = {"create", "update", "testSubmitRequest"})
+    dependsOnMethods = {"create", "update", "testSubmitRequest"})
     public void updateWithEmptyEntityBody(String testName) throws Exception {
 
     // Perform setup.
@@ -478,9 +477,9 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
     // Check the status code of the response: does it match
     // the expected response(s)?
     if(logger.isDebugEnabled()){
-        logger.debug(testName + ": url=" + url +
-            " status=" + statusCode);
-     }
+    logger.debug(testName + ": url=" + url +
+    " status=" + statusCode);
+    }
     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -488,7 +487,7 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
 
     @Override
     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
-        dependsOnMethods = {"create", "update", "testSubmitRequest"})
+    dependsOnMethods = {"create", "update", "testSubmitRequest"})
     public void updateWithMalformedXml(String testName) throws Exception {
 
     // Perform setup.
@@ -504,9 +503,9 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
     // Check the status code of the response: does it match
     // the expected response(s)?
     if(logger.isDebugEnabled()){
-        logger.debug(testName + ": url=" + url +
-         " status=" + statusCode);
-     }
+    logger.debug(testName + ": url=" + url +
+    " status=" + statusCode);
+    }
     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -514,7 +513,7 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
 
     @Override
     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
-        dependsOnMethods = {"create", "update", "testSubmitRequest"})
+    dependsOnMethods = {"create", "update", "testSubmitRequest"})
     public void updateWithWrongXmlSchema(String testName) throws Exception {
 
     // Perform setup.
@@ -530,9 +529,9 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
     // Check the status code of the response: does it match
     // the expected response(s)?
     if(logger.isDebugEnabled()){
-        logger.debug(testName + ": url=" + url +
-        " status=" + statusCode);
-     }
+    logger.debug(testName + ": url=" + url +
+    " status=" + statusCode);
+    }
     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -543,8 +542,8 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
      */
     @Override
-    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
-        dependsOnMethods = {"update", "testSubmitRequest"})
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+    dependsOnMethods = {"update", "testSubmitRequest"})
     public void updateNonExistent(String testName) throws Exception {
 
         // Perform setup.
@@ -554,14 +553,15 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
         // Note: The ID used in this 'create' call may be arbitrary.
         // The only relevant ID may be the one used in update(), below.
         DimensionClient client = new DimensionClient();
-        MultipartOutput multipart = createDimensionInstance(NON_EXISTENT_ID);
+        MultipartOutput multipart = createDimensionInstance(client.getCommonPartName(),
+                NON_EXISTENT_ID);
         ClientResponse<MultipartInput> res =
                 client.update(NON_EXISTENT_ID, multipart);
         int statusCode = res.getStatus();
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug(testName + ": status = " + statusCode);
         }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
@@ -577,8 +577,8 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
      */
     @Override
-    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
-        dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+    dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
     public void delete(String testName) throws Exception {
 
         // Perform setup.
@@ -591,7 +591,7 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug(testName + ": status = " + statusCode);
         }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
@@ -604,8 +604,8 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
      */
     @Override
-    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
-        dependsOnMethods = {"delete"})
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+    dependsOnMethods = {"delete"})
     public void deleteNonExistent(String testName) throws Exception {
 
         // Perform setup.
@@ -618,7 +618,7 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug(testName + ": status = " + statusCode);
         }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
@@ -646,9 +646,9 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        if(logger.isDebugEnabled()){
-            logger.debug("testSubmitRequest: url=" + url +
-                " status=" + statusCode);
+        if (logger.isDebugEnabled()) {
+            logger.debug("testSubmitRequest: url=" + url
+                    + " status=" + statusCode);
         }
         Assert.assertEquals(statusCode, EXPECTED_STATUS);
 
@@ -671,9 +671,9 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
      * @param identifier the identifier
      * @return the multipart output
      */
-    private MultipartOutput createDimensionInstance(String identifier) {
-        return createDimensionInstance(
-                       "dimensionType-" + identifier,
+    private MultipartOutput createDimensionInstance(String commonPartName, String identifier) {
+        return createDimensionInstance(commonPartName, 
+                "dimensionType-" + identifier,
                 "entryNumber-" + identifier,
                 "entryDate-" + identifier);
     }
@@ -686,19 +686,18 @@ public class DimensionServiceTest extends AbstractServiceTestImpl {
      * @param entryDate the entry date
      * @return the multipart output
      */
-    private MultipartOutput createDimensionInstance(String dimensionType, String entryNumber, String entryDate) {
+    private MultipartOutput createDimensionInstance(String commonPartName, String dimensionType, String entryNumber, String entryDate) {
         DimensionsCommon dimension = new DimensionsCommon();
         dimension.setDimension(dimensionType);
         dimension.setValue(entryNumber);
         dimension.setValueDate(entryDate);
-        MultipartOutput multipart = new MultipartOutput();
-        OutputPart commonPart =
-            multipart.addPart(dimension, MediaType.APPLICATION_XML_TYPE);
-        commonPart.getHeaders().add("label", new DimensionClient().getCommonPartName());
+        MultipartOutput multipart = DimensionFactory.createDimensionInstance(
+                commonPartName, dimension);
 
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug("to be created, dimension common");
-            logger.debug(objectAsXmlString(dimension, DimensionsCommon.class));
+            logger.debug(objectAsXmlString(dimension,
+                    DimensionsCommon.class));
         }
 
         return multipart;
index 6dac20c73de450e1c985937d368ee33278f13203..eecd1ec784f8d20f21aee69dc765048e7cffa40b 100644 (file)
             <artifactId>org.collectionspace.services.collectionobject.client</artifactId>\r
             <version>${project.version}</version>\r
         </dependency>\r
+        <dependency>\r
+            <groupId>org.collectionspace.services</groupId>\r
+            <artifactId>org.collectionspace.services.dimension.client</artifactId>\r
+            <version>${project.version}</version>\r
+        </dependency>\r
         <!-- External dependencies -->\r
         <dependency>\r
             <groupId>org.testng</groupId>\r
index f47b5fe0e1cc87b0903aaac50b539e6f8afd1ac5..79fbbcd84657a307233e00a31e3f6b1843ae8ece 100644 (file)
@@ -105,12 +105,7 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl {
         // its associated HTTP method name (e.g. POST, DELETE).
         setupCreate(testName);
         AccountClient accountClient = new AccountClient();
-        accountClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
-                "true");
-        accountClient.setProperty(CollectionSpaceClient.USER_PROPERTY,
-                "test");
-        accountClient.setProperty(
-                CollectionSpaceClient.PASSWORD_PROPERTY, "test");
+        accountClient.setAuth(true, "test", true, "test", true);
 
         // Submit the request to the service and store the response.
         AccountsCommon account =
@@ -142,12 +137,7 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl {
         // its associated HTTP method name (e.g. POST, DELETE).
         setupCreate(testName);
         AccountClient accountClient = new AccountClient();
-        accountClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
-                "true");
-        accountClient.setProperty(CollectionSpaceClient.USER_PROPERTY,
-                "test");
-        accountClient.setProperty(
-                CollectionSpaceClient.PASSWORD_PROPERTY, "test");
+        accountClient.setAuth(true, "test", true, "test", true);
 
         // Submit the request to the service and store the response.
         AccountsCommon account =
@@ -201,23 +191,10 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl {
     public void create(String testName) {
         setupCreate(testName);
         CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+        collectionObjectClient.setAuth(true, "barney", true, "barney08", true);
         String identifier = BaseServiceTest.createIdentifier();
         MultipartOutput multipart = createCollectionObjectInstance(
                 collectionObjectClient.getCommonPartName(), identifier);
-
-        collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
-                "true");
-        collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY,
-                "barney");
-        collectionObjectClient.setProperty(
-                CollectionSpaceClient.PASSWORD_PROPERTY, "barney08");
-        try {
-            collectionObjectClient.setupHttpClient();
-            collectionObjectClient.setProxy();
-        } catch (Exception e) {
-            logger.error("create: caught " + e.getMessage());
-            return;
-        }
         ClientResponse<Response> res = collectionObjectClient.create(multipart);
         if (logger.isDebugEnabled()) {
             logger.debug("create: status = " + res.getStatus());
@@ -233,27 +210,35 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl {
 
     }
 
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+    dependsOnMethods = {"createActiveAccount"})
+    public void createWithoutAuthn(String testName) {
+        setupCreate(testName);
+        CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+        collectionObjectClient.setAuth(false, "test", true, "test", true);
+        String identifier = BaseServiceTest.createIdentifier();
+        MultipartOutput multipart = createCollectionObjectInstance(
+                collectionObjectClient.getCommonPartName(), identifier);
+        ClientResponse<Response> res = collectionObjectClient.create(multipart);
+        if (logger.isDebugEnabled()) {
+            logger.debug("create: status = " + res.getStatus());
+        }
+        Assert.assertEquals(res.getStatus(),
+                Response.Status.UNAUTHORIZED.getStatusCode(), "expected "
+                + Response.Status.UNAUTHORIZED.getStatusCode());
+        res.releaseConnection();
+
+    }
+
     @Test(dataProvider = "testName", dependsOnMethods = {"createInactiveAccount"})
     public void createWithInactiveAccount(String testName) {
         banner(testName);
         CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+        collectionObjectClient.setAuth(true, "george", true, "george08", true);
         String identifier = BaseServiceTest.createIdentifier();
         MultipartOutput multipart = createCollectionObjectInstance(
                 collectionObjectClient.getCommonPartName(), identifier);
 
-        collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
-                "true");
-        collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY,
-                "george");
-        collectionObjectClient.setProperty(CollectionSpaceClient.PASSWORD_PROPERTY,
-                "george08");
-        try {
-            collectionObjectClient.setupHttpClient();
-            collectionObjectClient.setProxy();
-        } catch (Exception e) {
-            logger.error(testName + ": caught " + e.getMessage());
-            return;
-        }
         ClientResponse<Response> res = collectionObjectClient.create(multipart);
         if (logger.isDebugEnabled()) {
             logger.debug(testName + ": status = " + res.getStatus());
@@ -271,22 +256,10 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl {
     public void createWithoutPassword(String testName) {
         banner(testName);
         CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+        collectionObjectClient.setAuth(true, "test", true, "", false);
         String identifier = BaseServiceTest.createIdentifier();
         MultipartOutput multipart = createCollectionObjectInstance(
                 collectionObjectClient.getCommonPartName(), identifier);
-
-        collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
-                "true");
-        collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY,
-                "test");
-        collectionObjectClient.removeProperty(CollectionSpaceClient.PASSWORD_PROPERTY);
-        try {
-            collectionObjectClient.setupHttpClient();
-            collectionObjectClient.setProxy();
-        } catch (Exception e) {
-            logger.error(testName + ": caught " + e.getMessage());
-            return;
-        }
         ClientResponse<Response> res = collectionObjectClient.create(multipart);
         if (logger.isDebugEnabled()) {
             logger.debug(testName + ": status = " + res.getStatus());
@@ -302,23 +275,10 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl {
     public void createWithUnknownUser(String testName) {
         banner(testName);
         CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+        collectionObjectClient.setAuth(true, "foo", true, "bar", true);
         String identifier = BaseServiceTest.createIdentifier();
         MultipartOutput multipart = createCollectionObjectInstance(
                 collectionObjectClient.getCommonPartName(), identifier);
-
-        collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
-                "true");
-        collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY,
-                "foo");
-        collectionObjectClient.setProperty(CollectionSpaceClient.PASSWORD_PROPERTY,
-                "bar");
-        try {
-            collectionObjectClient.setupHttpClient();
-            collectionObjectClient.setProxy();
-        } catch (Exception e) {
-            logger.error(testName + ": caught " + e.getMessage());
-            return;
-        }
         ClientResponse<Response> res = collectionObjectClient.create(multipart);
         if (logger.isDebugEnabled()) {
             logger.debug(testName + ": status = " + res.getStatus());
@@ -334,23 +294,10 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl {
     public void createWithIncorrectPassword(String testName) {
         banner(testName);
         CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+        collectionObjectClient.setAuth(true, "test", true, "bar", true);
         String identifier = BaseServiceTest.createIdentifier();
         MultipartOutput multipart = createCollectionObjectInstance(
                 collectionObjectClient.getCommonPartName(), identifier);
-
-        collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
-                "true");
-        collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY,
-                "test");
-        collectionObjectClient.setProperty(
-                CollectionSpaceClient.PASSWORD_PROPERTY, "bar");
-        try {
-            collectionObjectClient.setupHttpClient();
-            collectionObjectClient.setProxy();
-        } catch (Exception e) {
-            logger.error(testName + ": caught " + e.getMessage());
-            return;
-        }
         ClientResponse<Response> res = collectionObjectClient.create(multipart);
         if (logger.isDebugEnabled()) {
             logger.debug(testName + ": status = " + res.getStatus());
@@ -366,23 +313,10 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl {
     public void createWithIncorrectUserPassword(String testName) {
         banner(testName);
         CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+        collectionObjectClient.setAuth(true, "foo", true, "bar", true);
         String identifier = BaseServiceTest.createIdentifier();
         MultipartOutput multipart = createCollectionObjectInstance(
                 collectionObjectClient.getCommonPartName(), identifier);
-
-        collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
-                "true");
-        collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY,
-                "foo");
-        collectionObjectClient.setProperty(
-                CollectionSpaceClient.PASSWORD_PROPERTY, "bar");
-        try {
-            collectionObjectClient.setupHttpClient();
-            collectionObjectClient.setProxy();
-        } catch (Exception e) {
-            logger.error(testName + ": caught " + e.getMessage());
-            return;
-        }
         ClientResponse<Response> res = collectionObjectClient.create(multipart);
         if (logger.isDebugEnabled()) {
             logger.debug(testName + ": status = "
@@ -399,23 +333,10 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl {
     public void createWithoutTenant(String testName) {
         banner(testName);
         CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+        collectionObjectClient.setAuth(true, "babybop", true, "babybop09", true);
         String identifier = BaseServiceTest.createIdentifier();
         MultipartOutput multipart = createCollectionObjectInstance(
                 collectionObjectClient.getCommonPartName(), identifier);
-
-        collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
-                "true");
-        collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY,
-                "babybop");
-        collectionObjectClient.setProperty(
-                CollectionSpaceClient.PASSWORD_PROPERTY, "babybop09");
-        try {
-            collectionObjectClient.setupHttpClient();
-            collectionObjectClient.setProxy();
-        } catch (Exception e) {
-            logger.error(testName + ": caught " + e.getMessage());
-            return;
-        }
         ClientResponse<Response> res = collectionObjectClient.create(multipart);
         if (logger.isDebugEnabled()) {
             logger.debug(testName + ": status = "
@@ -435,20 +356,7 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl {
         setupDelete(testName);
         CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
         collectionObjectClient = new CollectionObjectClient();
-
-        collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
-                "true");
-        collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY,
-                "test");
-        collectionObjectClient.setProperty(
-                CollectionSpaceClient.PASSWORD_PROPERTY, "test");
-        try {
-            collectionObjectClient.setupHttpClient();
-            collectionObjectClient.setProxy();
-        } catch (Exception e) {
-            logger.error("deleteCollectionObject: caught " + e.getMessage());
-            return;
-        }
+        collectionObjectClient.setAuth(true, "test", true, "test", true);
         if (logger.isDebugEnabled()) {
             logger.debug("Calling deleteCollectionObject:" + knownResourceId);
         }
@@ -468,13 +376,7 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl {
         // Perform setup.
         setupDelete(testName);
         AccountClient accountClient = new AccountClient();
-
-        accountClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
-                "true");
-        accountClient.setProperty(CollectionSpaceClient.USER_PROPERTY,
-                "test");
-        accountClient.setProperty(
-                CollectionSpaceClient.PASSWORD_PROPERTY, "test");
+        accountClient.setAuth(true, "test", true, "test", true);
         // Submit the request to the service and store the response.
         ClientResponse<Response> res = accountClient.delete(barneyAccountId);
         int statusCode = res.getStatus();
@@ -507,7 +409,8 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl {
      */
     private MultipartOutput createCollectionObjectInstance(
             String commonPartName, String identifier) {
-        return createCollectionObjectInstance(commonPartName, "objectNumber-" + identifier, "objectName-" + identifier);
+        return createCollectionObjectInstance(commonPartName, "objectNumber-"
+                + identifier, "objectName-" + identifier);
     }
 
     /**
diff --git a/services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthorizationServiceTest.java b/services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthorizationServiceTest.java
new file mode 100644 (file)
index 0000000..48df128
--- /dev/null
@@ -0,0 +1,608 @@
+/**
+ *  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.services.security.client.test;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Hashtable;
+import java.util.List;
+import javax.ws.rs.core.Response;
+import org.collectionspace.services.account.AccountsCommon;
+import org.collectionspace.services.authorization.AccountRole;
+import org.collectionspace.services.authorization.AccountValue;
+import org.collectionspace.services.authorization.EffectType;
+
+import org.collectionspace.services.authorization.Permission;
+import org.collectionspace.services.authorization.PermissionAction;
+import org.collectionspace.services.authorization.PermissionRole;
+import org.collectionspace.services.authorization.PermissionValue;
+import org.collectionspace.services.authorization.Role;
+import org.collectionspace.services.authorization.RoleValue;
+import org.collectionspace.services.client.AccountClient;
+import org.collectionspace.services.client.AccountFactory;
+import org.collectionspace.services.client.AccountRoleClient;
+import org.collectionspace.services.client.AccountRoleFactory;
+import org.collectionspace.services.client.CollectionSpaceClient;
+import org.collectionspace.services.client.DimensionClient;
+import org.collectionspace.services.client.DimensionFactory;
+import org.collectionspace.services.client.PermissionClient;
+import org.collectionspace.services.client.PermissionFactory;
+import org.collectionspace.services.client.PermissionRoleClient;
+import org.collectionspace.services.client.PermissionRoleFactory;
+import org.collectionspace.services.client.RoleClient;
+import org.collectionspace.services.client.RoleFactory;
+import org.collectionspace.services.client.test.AbstractServiceTestImpl;
+import org.collectionspace.services.dimension.DimensionsCommon;
+import org.collectionspace.services.jaxb.AbstractCommonList;
+import org.jboss.resteasy.client.ClientResponse;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+
+/**
+ * AuthorizationServiceTest, carries out tests against a
+ * deployed and running Permission, Role, AccountRole, PermissionRole and
+ * CollectionObject Services.
+ *
+ * $LastChangedRevision: 917 $
+ * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
+ */
+public class AuthorizationServiceTest extends AbstractServiceTestImpl {
+
+    static private final Logger logger =
+            LoggerFactory.getLogger(AuthorizationServiceTest.class);
+    // Instance variables specific to this test.
+    private String knownResourceId = null;
+    private List<String> allResourceIdsCreated = new ArrayList();
+    //key for accValues is userId
+    private Hashtable<String, AccountValue> accValues = new Hashtable<String, AccountValue>();
+    //key for permValues is id as there could be several perms for the same resource
+    private Hashtable<String, PermissionValue> permValues = new Hashtable<String, PermissionValue>();
+    //key for roleValues is roleName
+    private Hashtable<String, RoleValue> roleValues = new Hashtable<String, RoleValue>();
+    private String bigbirdPermId;
+    private String elmoPermId;
+    /*
+     * This method is called only by the parent class, AbstractServiceTestImpl
+     */
+
+    @Override
+    protected String getServicePathComponent() {
+        return null;
+    }
+
+    @BeforeClass(alwaysRun = true)
+    public void seedData() {
+        seedPermissions();
+        seedRoles();
+        seedAccounts();
+        seedAccountRoles();
+        seedPermissionRoles();
+    }
+
+    private void seedPermissions() {
+        String rc1 = "collectionobjects";
+        bigbirdPermId = createPermission(rc1, EffectType.PERMIT);
+        PermissionValue bbpv = new PermissionValue();
+        bbpv.setResourceName(rc1);
+        bbpv.setPermissionId(bigbirdPermId);
+        permValues.put(bbpv.getPermissionId(), bbpv);
+
+        String rc2 = "collectionobjects";
+        elmoPermId = createPermission(rc2, EffectType.DENY);
+        PermissionValue epv = new PermissionValue();
+        epv.setResourceName(rc2);
+        epv.setPermissionId(elmoPermId);
+        permValues.put(epv.getPermissionId(), epv);
+    }
+
+    private void seedRoles() {
+        String rn1 = "ROLE_MMI_CM";
+        String r1RoleId = createRole(rn1);
+        RoleValue rv1 = new RoleValue();
+        rv1.setRoleId(r1RoleId);
+        rv1.setRoleName(rn1);
+        roleValues.put(rv1.getRoleName(), rv1);
+
+        String rn2 = "ROLE_MMI_INTERN";
+        String r2RoleId = createRole(rn2);
+        RoleValue rv2 = new RoleValue();
+        rv2.setRoleId(r2RoleId);
+        rv2.setRoleName(rn2);
+        roleValues.put(rv2.getRoleName(), rv2);
+    }
+
+    private void seedAccounts() {
+        String userId = "bigbird2010";
+        String accId = createAccount(userId, "bigbird@cspace.org");
+        AccountValue ava = new AccountValue();
+        ava.setScreenName(userId);
+        ava.setUserId(userId);
+        ava.setAccountId(accId);
+        accValues.put(ava.getUserId(), ava);
+
+        String userId2 = "elmo2010";
+        String coAccId = createAccount(userId2, "elmo@cspace.org");
+        AccountValue avc = new AccountValue();
+        avc.setScreenName(userId2);
+        avc.setUserId(userId2);
+        avc.setAccountId(coAccId);
+        accValues.put(avc.getUserId(), avc);
+    }
+
+    private void seedAccountRoles() {
+
+        List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
+        bigbirdRoleValues.add(roleValues.get("ROLE_MMI_CM"));
+        createAccountRole(accValues.get("bigbird2010"), bigbirdRoleValues);
+
+        List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
+        elmoRoleValues.add(roleValues.get("ROLE_MMI_INTERN"));
+        createAccountRole(accValues.get("elmo2010"), elmoRoleValues);
+    }
+
+    private void seedPermissionRoles() {
+
+        List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
+        bigbirdRoleValues.add(roleValues.get("ROLE_MMI_CM"));
+        createPermissionRole(permValues.get(bigbirdPermId), bigbirdRoleValues);
+
+        List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
+        elmoRoleValues.add(roleValues.get("ROLE_MMI_INTERN"));
+        createPermissionRole(permValues.get(elmoPermId), elmoRoleValues);
+
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
+     */
+    @Override
+    protected CollectionSpaceClient getClientInstance() {
+        return null;
+    }
+
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
+     */
+    @Override
+    protected AbstractCommonList getAbstractCommonList(
+            ClientResponse<AbstractCommonList> response) {
+        //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
+        throw new UnsupportedOperationException();
+    }
+
+    @Test(dataProvider = "testName")
+    @Override
+    public void readPaginatedList(String testName) throws Exception {
+        //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
+    }
+    // ---------------------------------------------------------------
+    // CRUD tests : CREATE tests
+    // ---------------------------------------------------------------
+    // Success outcomes
+
+    @Override
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
+    public void create(String testName) throws Exception {
+        setupCreate(testName);
+
+        // Submit the request to the service and store the response.
+        DimensionClient client = new DimensionClient();
+        client.setAuth(true, "bigbird2010", true, "bigbird2010", true);
+        String identifier = createIdentifier();
+        DimensionsCommon dimension = new DimensionsCommon();
+        dimension.setDimension("dimensionType");
+        dimension.setValue("value-" + identifier);
+        dimension.setValueDate(new Date().toString());
+        MultipartOutput multipart = DimensionFactory.createDimensionInstance(client.getCommonPartName(),
+                dimension);
+        ClientResponse<Response> res = client.create(multipart);
+
+        int statusCode = res.getStatus();
+
+        if (logger.isDebugEnabled()) {
+            logger.debug(testName + ": status = " + statusCode);
+        }
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
+    }
+
+    //to not cause uniqueness violation for permRole, createList is removed
+    @Override
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+    dependsOnMethods = {"create"})
+    public void createList(String testName) throws Exception {
+    }
+
+    // Failure outcomes
+    // Placeholders until the three tests below can be uncommented.
+    // See Issue CSPACE-401.
+    @Override
+    public void createWithEmptyEntityBody(String testName) throws Exception {
+    }
+
+    @Override
+    public void createWithMalformedXml(String testName) throws Exception {
+    }
+
+    @Override
+    public void createWithWrongXmlSchema(String testName) throws Exception {
+    }
+
+    // ---------------------------------------------------------------
+    // CRUD tests : READ tests
+    // ---------------------------------------------------------------
+    // Success outcomes
+    @Override
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+    dependsOnMethods = {"create"})
+    public void read(String testName) throws Exception {
+
+        // Perform setup.
+        setupRead(testName);
+
+    }
+
+    // Failure outcomes
+    @Override
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
+    public void readNonExistent(String testName) throws Exception {
+
+        // Perform setup.
+        setupReadNonExistent(testName);
+    }
+
+    // ---------------------------------------------------------------
+    // CRUD tests : READ_LIST tests
+    // ---------------------------------------------------------------
+    // Success outcomes
+    @Override
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+    dependsOnMethods = {"createList", "read"})
+    public void readList(String testName) throws Exception {
+        setupReadList(testName);
+    }
+
+    // Failure outcomes
+    // None at present.
+    // ---------------------------------------------------------------
+    // CRUD tests : UPDATE tests
+    // ---------------------------------------------------------------
+    // Success outcomes
+    @Override
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+    dependsOnMethods = {"read", "readList", "readNonExistent"})
+    public void update(String testName) throws Exception {
+        setupUpdate(testName);
+    }
+
+    // Failure outcomes
+    // Placeholders until the three tests below can be uncommented.
+    // See Issue CSPACE-401.
+    @Override
+    public void updateWithEmptyEntityBody(String testName) throws Exception {
+    }
+
+    @Override
+    public void updateWithMalformedXml(String testName) throws Exception {
+    }
+
+    @Override
+    public void updateWithWrongXmlSchema(String testName) throws Exception {
+    }
+
+    @Override
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+    dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
+    public void updateNonExistent(String testName) throws Exception {
+    }
+
+    // ---------------------------------------------------------------
+    // CRUD tests : DELETE tests
+    // ---------------------------------------------------------------
+    // Success outcomes
+    @Override
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+    dependsOnMethods = {"read"})
+    public void delete(String testName) throws Exception {
+        // Perform setup.
+        setupDelete(testName);
+
+    }
+
+    // Failure outcomes
+    @Override
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
+    public void deleteNonExistent(String testName) throws Exception {
+        //ignoring this test as the service side returns 200 now even if it does
+        //not find a record in the db
+    }
+
+    // ---------------------------------------------------------------
+    // Utility tests : tests of code used in tests above
+    // ---------------------------------------------------------------
+    /**
+     * Tests the code for manually submitting data that is used by several
+     * of the methods above.
+     */
+    @Test(dependsOnMethods = {"create"})
+    public void testSubmitRequest() throws Exception {
+    }
+
+    // ---------------------------------------------------------------
+    // Utility methods used by tests above
+    // ---------------------------------------------------------------
+    @AfterClass(alwaysRun = true)
+    public void cleanUp() {
+        setupDelete("cleanup");
+        String noTest = System.getProperty("noTestCleanup");
+        if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("Skipping Cleanup phase ...");
+            }
+            return;
+        }
+        if (logger.isDebugEnabled()) {
+            logger.debug("Cleaning up temporary resources created for testing ...");
+        }
+
+        deletePermissionRoles();
+        deleteAccountRoles();
+        deletePermissions();
+        deleteRoles();
+        deleteAccounts();
+    }
+
+    private String createPermission(String resName, EffectType effect) {
+        setupCreate("createPermission");
+        PermissionClient permClient = new PermissionClient();
+        List<PermissionAction> actions = PermissionFactory.createDefaultActions();
+        Permission permission = PermissionFactory.createPermissionInstance(resName,
+                "default permissions for " + resName,
+                actions, effect, true, true, true);
+        ClientResponse<Response> res = permClient.create(permission);
+        int statusCode = res.getStatus();
+        if (logger.isDebugEnabled()) {
+            logger.debug("createPermission: resName=" + resName
+                    + " status = " + statusCode);
+        }
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+        res.releaseConnection();
+        return extractId(res);
+    }
+
+    private void deletePermission(String permId) {
+        setupDelete("deletePermission");
+        PermissionClient permClient = new PermissionClient();
+        ClientResponse<Response> res = permClient.delete(permId);
+        int statusCode = res.getStatus();
+        if (logger.isDebugEnabled()) {
+            logger.debug("deletePermission: delete permission id="
+                    + permId + " status=" + statusCode);
+        }
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+        res.releaseConnection();
+    }
+
+    private String createRole(String roleName) {
+        setupCreate("createRole");
+        RoleClient roleClient = new RoleClient();
+
+        Role role = RoleFactory.createRoleInstance(roleName,
+                "role for " + roleName, true);
+        ClientResponse<Response> res = roleClient.create(role);
+        int statusCode = res.getStatus();
+        if (logger.isDebugEnabled()) {
+            logger.debug("createRole: name=" + roleName
+                    + " status = " + statusCode);
+        }
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+        res.releaseConnection();
+        return extractId(res);
+    }
+
+    private void deleteRole(String roleId) {
+        setupDelete("deleteRole");
+        RoleClient roleClient = new RoleClient();
+        ClientResponse<Response> res = roleClient.delete(roleId);
+        int statusCode = res.getStatus();
+        if (logger.isDebugEnabled()) {
+            logger.debug("deleteRole: delete role id=" + roleId
+                    + " status=" + statusCode);
+        }
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+        res.releaseConnection();
+    }
+
+    private String createAccount(String userName, String email) {
+        setupCreate("createAccount");
+        AccountClient accClient = new AccountClient();
+        AccountsCommon account = AccountFactory.createAccountInstance(
+                userName, userName, userName, email,
+                true, true, false, true, true);
+        ClientResponse<Response> res = accClient.create(account);
+        int statusCode = res.getStatus();
+        if (logger.isDebugEnabled()) {
+            logger.debug("createAccount: userName=" + userName
+                    + " status = " + statusCode);
+        }
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+        res.releaseConnection();
+        return extractId(res);
+    }
+
+    private void deleteAccount(String accId) {
+        setupDelete("deleteAccount");
+        AccountClient accClient = new AccountClient();
+        ClientResponse<Response> res = accClient.delete(accId);
+        int statusCode = res.getStatus();
+        if (logger.isDebugEnabled()) {
+            logger.debug("deleteAccount: delete account id="
+                    + accId + " status=" + statusCode);
+        }
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+        res.releaseConnection();
+    }
+
+    private String createAccountRole(AccountValue av,
+            Collection<RoleValue> rvs) {
+        setupCreate("createAccountRole");
+
+        // Submit the request to the service and store the response.
+        AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
+                av, rvs, true, true);
+        AccountRoleClient client = new AccountRoleClient();
+        ClientResponse<Response> res = client.create(av.getAccountId(), accRole);
+        int statusCode = res.getStatus();
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("createAccountRole: status = " + statusCode);
+        }
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+        res.releaseConnection();
+        return extractId(res);
+    }
+
+    private void deleteAccountRole(String screenName) {
+        // Perform setup.
+        setupDelete("deleteAccountRole");
+
+        // Submit the request to the service and store the response.
+        AccountRoleClient client = new AccountRoleClient();
+        ClientResponse<Response> res = client.delete(
+                accValues.get(screenName).getAccountId(), "123");
+        int statusCode = res.getStatus();
+
+        // Check the status code of the response: does it match
+        // the expected response(s)?
+        if (logger.isDebugEnabled()) {
+            logger.debug("deleteAccountRole: status = " + statusCode);
+        }
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+        res.releaseConnection();
+    }
+
+    private String createPermissionRole(PermissionValue pv,
+            Collection<RoleValue> rvs) {
+        setupCreate("createPermissionRole");
+        PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
+                pv, rvs, true, true);
+        PermissionRoleClient client = new PermissionRoleClient();
+        ClientResponse<Response> res = client.create(pv.getPermissionId(), permRole);
+        int statusCode = res.getStatus();
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("createPermissionRole: status = " + statusCode);
+        }
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+        res.releaseConnection();
+        return extractId(res);
+    }
+
+    private void deletePermissionRole(String permId) {
+
+        // Perform setup.
+        setupDelete("deletePermissionRole");
+
+        // Submit the request to the service and store the response.
+        PermissionRoleClient client = new PermissionRoleClient();
+        ClientResponse<Response> res = client.delete(permId, "123");
+        int statusCode = res.getStatus();
+
+        // Check the status code of the response: does it match
+        // the expected response(s)?
+        if (logger.isDebugEnabled()) {
+            logger.debug("deletePermissionRole : status = " + statusCode);
+        }
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+        res.releaseConnection();
+    }
+
+    private void deletePermissionRoles() {
+
+        //first delete relationships between the entities
+        for (PermissionValue pv : permValues.values()) {
+            deletePermissionRole(pv.getPermissionId());
+        }
+    }
+
+    private void deleteAccountRoles() {
+        for (AccountValue av : accValues.values()) {
+            deleteAccountRole(av.getUserId());
+        }
+    }
+
+    private void deletePermissions() {
+        //delete entities
+        for (PermissionValue pv : permValues.values()) {
+            deletePermission(pv.getPermissionId());
+        }
+    }
+
+    private void deleteRoles() {
+        for (RoleValue rv : roleValues.values()) {
+            deleteRole(rv.getRoleId());
+        }
+    }
+
+    private void deleteAccounts() {
+
+        for (AccountValue av1 : accValues.values()) {
+            deleteAccount(av1.getAccountId());
+        }
+    }
+}