]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-323 changed directory structure of authentication service, refactored Coolecti...
authorSanjay Dalal <sanjay.dalal@berkeley.edu>
Thu, 30 Jul 2009 22:58:16 +0000 (22:58 +0000)
committerSanjay Dalal <sanjay.dalal@berkeley.edu>
Thu, 30 Jul 2009 22:58:16 +0000 (22:58 +0000)
A    services/authentication/service
A  + services/authentication/service/src
A    services/authentication/service/src/test/resources
A    services/authentication/service/src/test/resources/log4j.properties
A    services/authentication/service/src/main/resources/log4j.properties
A  + services/authentication/service/pom.xml
A  + services/authentication/service/build.xml
D    services/authentication/src
D    services/authentication/pom.xml
D    services/authentication/build.xml
A    services/authentication/client
A    services/authentication/client/src
A    services/authentication/client/src/test
A    services/authentication/client/src/test/java
A    services/authentication/client/src/test/java/org
A    services/authentication/client/src/test/java/org/collectionspace
A    services/authentication/client/src/test/java/org/collectionspace/services
A    services/authentication/client/src/test/java/org/collectionspace/services/authentication
A    services/authentication/client/src/test/java/org/collectionspace/services/authentication/client
A    services/authentication/client/src/test/java/org/collectionspace/services/authentication/client/AuthenticationServiceTest.java
A    services/authentication/client/src/test/resources
A    services/authentication/client/src/test/resources/log4j.properties
A    services/authentication/client/src/main
A    services/authentication/client/src/main/java
A    services/authentication/client/src/main/java/org
A    services/authentication/client/src/main/java/org/collectionspace
A    services/authentication/client/src/main/java/org/collectionspace/services
A    services/authentication/client/src/main/java/org/collectionspace/services/authentication
A    services/authentication/client/src/main/java/org/collectionspace/services/authentication/client
A    services/authentication/client/src/main/resources
A    services/authentication/client/pom.xml
M    services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java
M    services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java
M    services/intake/client/src/main/java/org/collectionspace/services/client/IntakeClient.java
M    services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClient.java
A  + services/client/src/main/java/org/collectionspace/services/client/BaseServiceClient.java

19 files changed:
services/authentication/client/pom.xml [new file with mode: 0644]
services/authentication/client/src/test/java/org/collectionspace/services/authentication/client/AuthenticationServiceTest.java [new file with mode: 0644]
services/authentication/client/src/test/resources/log4j.properties [new file with mode: 0644]
services/authentication/service/build.xml [moved from services/authentication/build.xml with 96% similarity]
services/authentication/service/pom.xml [moved from services/authentication/pom.xml with 76% similarity]
services/authentication/service/src/main/java/org/collectionspace/authentication/CSpaceDBLoginModule.java [moved from services/authentication/src/main/java/org/collectionspace/authentication/CSpaceDBLoginModule.java with 100% similarity]
services/authentication/service/src/main/resources/config/jboss-login-config.xml [moved from services/authentication/src/main/resources/config/jboss-login-config.xml with 100% similarity]
services/authentication/service/src/main/resources/config/jboss-web-security-config.xml [moved from services/authentication/src/main/resources/config/jboss-web-security-config.xml with 100% similarity]
services/authentication/service/src/main/resources/config/web-security-config.xml [moved from services/authentication/src/main/resources/config/web-security-config.xml with 100% similarity]
services/authentication/service/src/main/resources/db/mysql/authentication.sql [moved from services/authentication/src/main/resources/db/mysql/authentication.sql with 100% similarity]
services/authentication/service/src/main/resources/db/mysql/test_authn.sql [moved from services/authentication/src/main/resources/db/mysql/test_authn.sql with 100% similarity]
services/authentication/service/src/main/resources/log4j.properties [new file with mode: 0644]
services/authentication/service/src/test/java/org/collectionspace/authentication/AppTest.java [moved from services/authentication/src/test/java/org/collectionspace/authentication/AppTest.java with 100% similarity]
services/authentication/service/src/test/resources/log4j.properties [new file with mode: 0644]
services/client/src/main/java/org/collectionspace/services/client/BaseServiceClient.java [new file with mode: 0644]
services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClient.java
services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java
services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java
services/intake/client/src/main/java/org/collectionspace/services/client/IntakeClient.java

diff --git a/services/authentication/client/pom.xml b/services/authentication/client/pom.xml
new file mode 100644 (file)
index 0000000..8dbbefd
--- /dev/null
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<project xmlns="http://maven.apache.org/POM/4.0.0"\r
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">\r
+\r
+    <parent>\r
+        <artifactId>org.collectionspace.services.authentication</artifactId>\r
+        <groupId>org.collectionspace.services</groupId>\r
+        <version>1.0</version>\r
+    </parent>\r
+\r
+    <modelVersion>4.0.0</modelVersion>\r
+    <groupId>org.collectionspace.services</groupId>\r
+    <artifactId>org.collectionspace.services.authentication.client</artifactId>\r
+    <version>1.0</version>\r
+    <name>services.authentication.client</name>\r
+    \r
+    <dependencies>\r
+        <!-- keep slf4j dependencies on the top -->\r
+        <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
+        <dependency>\r
+            <groupId>org.collectionspace.services</groupId>\r
+            <artifactId>org.collectionspace.services.client</artifactId>\r
+            <version>1.0</version>\r
+        </dependency>\r
+        <dependency>\r
+            <groupId>org.collectionspace.services</groupId>\r
+            <artifactId>org.collectionspace.services.collectionobject.client</artifactId>\r
+            <version>1.0</version>\r
+        </dependency>\r
+        <dependency>\r
+            <groupId>org.testng</groupId>\r
+            <artifactId>testng</artifactId>\r
+            <version>5.6</version>\r
+        </dependency>\r
+        <dependency>\r
+            <groupId>org.jboss.resteasy</groupId>\r
+            <artifactId>resteasy-jaxrs</artifactId>\r
+            <version>1.0.2.GA</version>\r
+            <!-- filter out unwanted jars -->\r
+            <exclusions>\r
+                <exclusion>\r
+                    <groupId>tjws</groupId>\r
+                    <artifactId>webserver</artifactId>\r
+                </exclusion>\r
+            </exclusions>\r
+        </dependency>\r
+        <dependency>\r
+            <groupId>org.jboss.resteasy</groupId>\r
+            <artifactId>resteasy-jaxb-provider</artifactId>\r
+            <version>1.0.2.GA</version>\r
+        </dependency>\r
+        <dependency>\r
+            <groupId>org.jboss.resteasy</groupId>\r
+            <artifactId>resteasy-multipart-provider</artifactId>\r
+            <version>1.0.2.GA</version>\r
+        </dependency>\r
+        <dependency>\r
+            <groupId>commons-httpclient</groupId>\r
+            <artifactId>commons-httpclient</artifactId>\r
+            <version>3.1</version>\r
+        </dependency>\r
+    </dependencies>\r
+    \r
+    <build>\r
+        <finalName>cspace-services-collectionobject-client</finalName>\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>log4j.configuration</name>\r
+                            <value>file:target/test-classes/log4j.properties</value>\r
+                        </property>\r
+                    </systemProperties>\r
+                </configuration>\r
+            </plugin>\r
+            <plugin>\r
+                <artifactId>maven-compiler-plugin</artifactId>\r
+                <version>2.0.2</version>\r
+                <configuration>\r
+                    <source>1.6</source>\r
+                    <target>1.6</target>\r
+                </configuration>\r
+            </plugin>\r
+        </plugins>\r
+    </build>\r
+</project>\r
+\r
diff --git a/services/authentication/client/src/test/java/org/collectionspace/services/authentication/client/AuthenticationServiceTest.java b/services/authentication/client/src/test/java/org/collectionspace/services/authentication/client/AuthenticationServiceTest.java
new file mode 100644 (file)
index 0000000..bd49c3d
--- /dev/null
@@ -0,0 +1,284 @@
+/**
+ * This document is a part of the source code and related artifacts
+ * for CollectionSpace, an open source collections management system
+ * for museums and related institutions:
+ *
+ * http://www.collectionspace.org
+ * http://wiki.collectionspace.org
+ *
+ * Copyright © 2009 Regents of the University of California
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.collectionspace.services.authentication.client;
+
+import java.util.ArrayList;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+import org.jboss.resteasy.client.ClientResponse;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import org.collectionspace.services.collectionobject.CollectionObject;
+import org.collectionspace.services.client.CollectionObjectClient;
+import org.collectionspace.services.client.CollectionSpaceClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * AuthenticationServiceTest uses CollectionObject service to test authentication
+ * 
+ * $LastChangedRevision: 434 $
+ * $LastChangedDate: 2009-07-28 14:34:15 -0700 (Tue, 28 Jul 2009) $
+ */
+public class AuthenticationServiceTest {
+
+    private String knownCollectionObjectId = null;
+    final Logger logger = LoggerFactory.getLogger(AuthenticationServiceTest.class);
+
+    @Test
+    public void auth_createCollectionObject() {
+        if(!isServerSecure()){
+            return;
+        }
+        String identifier = this.createIdentifier();
+        CollectionObject collectionObject = createCollectionObject(identifier);
+        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("auth_createCollectionObject: caught " + e.getMessage());
+            return;
+        }
+        ClientResponse<Response> res = collectionObjectClient.createCollectionObject(collectionObject);
+        verbose("auth_createCollectionObject: status = " + res.getStatus());
+        Assert.assertEquals(res.getStatus(), Response.Status.CREATED.getStatusCode(),
+                "expected " + Response.Status.CREATED.getStatusCode());
+
+        // Store the ID returned from this create operation for additional tests below.
+        knownCollectionObjectId = extractId(res);
+    }
+
+    @Test(dependsOnMethods = {"auth_createCollectionObject"})
+    public void auth_createCollectionObjectWithoutUser() {
+        if(!isServerSecure()){
+            return;
+        }
+        String identifier = this.createIdentifier();
+        CollectionObject collectionObject = createCollectionObject(identifier);
+        CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+        collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY, "true");
+        collectionObjectClient.removeProperty(CollectionSpaceClient.USER_PROPERTY);
+        collectionObjectClient.setProperty(CollectionSpaceClient.PASSWORD_PROPERTY, "test");
+        try{
+            collectionObjectClient.setupHttpClient();
+            collectionObjectClient.setProxy();
+        }catch(Exception e){
+            logger.error("auth_createCollectionObjectWithoutUser: caught " + e.getMessage());
+            return;
+        }
+        ClientResponse<Response> res = collectionObjectClient.createCollectionObject(collectionObject);
+        verbose("auth_createCollectionObjectWithoutUser: status = " + res.getStatus());
+        Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(),
+                "expected " + Response.Status.UNAUTHORIZED.getStatusCode());
+    }
+
+    @Test(dependsOnMethods = {"auth_createCollectionObjectWithoutUser"})
+    public void auth_createCollectionObjectWithoutPassword() {
+        if(!isServerSecure()){
+            logger.warn("set -Dcspace.server.secure=true to run security tests");
+            return;
+        }
+        String identifier = this.createIdentifier();
+        CollectionObject collectionObject = createCollectionObject(identifier);
+        CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+        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("auth_createCollectionObjectWithoutPassword: caught " + e.getMessage());
+            return;
+        }
+        ClientResponse<Response> res = collectionObjectClient.createCollectionObject(collectionObject);
+        verbose("auth_createCollectionObjectWithoutPassword: status = " + res.getStatus());
+        Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(),
+                "expected " + Response.Status.UNAUTHORIZED.getStatusCode());
+    }
+
+    @Test(dependsOnMethods = {"auth_createCollectionObjectWithoutPassword"})
+    public void auth_createCollectionObjectWithIncorrectPassword() {
+        if(!isServerSecure()){
+            logger.warn("set -Dcspace.server.secure=true to run security tests");
+            return;
+        }
+        String identifier = this.createIdentifier();
+        CollectionObject collectionObject = createCollectionObject(identifier);
+        CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+        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("auth_createCollectionObjectWithIncorrectPassword: caught " + e.getMessage());
+            return;
+        }
+        ClientResponse<Response> res = collectionObjectClient.createCollectionObject(collectionObject);
+        verbose("auth_createCollectionObjectWithIncorrectPassword: status = " + res.getStatus());
+        Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(),
+                "expected " + Response.Status.UNAUTHORIZED.getStatusCode());
+    }
+
+    @Test(dependsOnMethods = {"auth_createCollectionObjectWithoutPassword"})
+    public void auth_createCollectionObjectWithoutUserPassword() {
+        if(!isServerSecure()){
+            logger.warn("set -Dcspace.server.secure=true to run security tests");
+            return;
+        }
+        String identifier = this.createIdentifier();
+        CollectionObject collectionObject = createCollectionObject(identifier);
+        CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+        collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY, "true");
+        collectionObjectClient.removeProperty(CollectionSpaceClient.USER_PROPERTY);
+        collectionObjectClient.removeProperty(CollectionSpaceClient.PASSWORD_PROPERTY);
+        try{
+            collectionObjectClient.setupHttpClient();
+            collectionObjectClient.setProxy();
+        }catch(Exception e){
+            logger.error("auth_createCollectionObjectWithoutUserPassword: caught " + e.getMessage());
+            return;
+        }
+        ClientResponse<Response> res = collectionObjectClient.createCollectionObject(collectionObject);
+        verbose("auth_createCollectionObjectWithoutUserPassword: status = " + res.getStatus());
+        Assert.assertEquals(res.getStatus(), Response.Status.FORBIDDEN.getStatusCode(),
+                "expected " + Response.Status.FORBIDDEN.getStatusCode());
+    }
+
+    @Test(dependsOnMethods = {"auth_createCollectionObjectWithoutPassword"})
+    public void auth_createCollectionObjectWithIncorrectUserPassword() {
+        if(!isServerSecure()){
+            logger.warn("set -Dcspace.server.secure=true to run security tests");
+            return;
+        }
+        String identifier = this.createIdentifier();
+        CollectionObject collectionObject = createCollectionObject(identifier);
+        CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+        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("auth_createCollectionObjectWithIncorrectUserPassword: caught " + e.getMessage());
+            return;
+        }
+        ClientResponse<Response> res = collectionObjectClient.createCollectionObject(collectionObject);
+        verbose("auth_createCollectionObjectWithIncorrectUserPassword: status = " + res.getStatus());
+        Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(),
+                "expected " + Response.Status.UNAUTHORIZED.getStatusCode());
+    }
+
+
+    @Test(dependsOnMethods = {"auth_createCollectionObjectWithIncorrectUserPassword"})
+    public void auth_deleteCollectionObject() {
+        if(!isServerSecure()){
+            logger.warn("set -Dcspace.server.secure=true to run security tests");
+            return;
+        }
+        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("auth_deleteCollectionObject: caught " + e.getMessage());
+            return;
+        }
+        verbose("Calling deleteCollectionObject:" + knownCollectionObjectId);
+        ClientResponse<Response> res = collectionObjectClient.deleteCollectionObject(knownCollectionObjectId);
+        verbose("auth_deleteCollectionObject: status = " + res.getStatus());
+        Assert.assertEquals(res.getStatus(), Response.Status.OK.getStatusCode(),
+                "expected " + Response.Status.OK.getStatusCode());
+    }
+
+    // ---------------------------------------------------------------
+    // Utility methods used by tests above
+    // ---------------------------------------------------------------
+    private CollectionObject createCollectionObject(String identifier) {
+        CollectionObject collectionObject = createCollectionObject("objectNumber-" + identifier,
+                "objectName-" + identifier);
+
+        return collectionObject;
+    }
+
+    private CollectionObject createCollectionObject(String objectNumber, String objectName) {
+        CollectionObject collectionObject = new CollectionObject();
+
+        collectionObject.setObjectNumber(objectNumber);
+        collectionObject.setObjectName(objectName);
+
+        return collectionObject;
+    }
+
+    private String extractId(ClientResponse<Response> res) {
+        MultivaluedMap mvm = res.getMetadata();
+        String uri = (String) ((ArrayList) mvm.get("Location")).get(0);
+        verbose("extractId:uri=" + uri);
+        String[] segments = uri.split("/");
+        String id = segments[segments.length - 1];
+        verbose("id=" + id);
+        return id;
+    }
+
+    private void verbose(String msg) {
+        if(logger.isInfoEnabled()){
+            logger.debug(msg);
+        }
+    }
+
+    private void verbose(String msg, Object o, Class clazz) {
+        try{
+            verbose(msg);
+            JAXBContext jc = JAXBContext.newInstance(clazz);
+            Marshaller m = jc.createMarshaller();
+            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
+                    Boolean.TRUE);
+            m.marshal(o, System.out);
+        }catch(Exception e){
+            e.printStackTrace();
+        }
+    }
+
+    private String createIdentifier() {
+        long identifier = System.currentTimeMillis();
+        return Long.toString(identifier);
+    }
+
+    private boolean isServerSecure() {
+        return Boolean.getBoolean("cspace.server.secure");
+    }
+}
diff --git a/services/authentication/client/src/test/resources/log4j.properties b/services/authentication/client/src/test/resources/log4j.properties
new file mode 100644 (file)
index 0000000..5d288d8
--- /dev/null
@@ -0,0 +1,23 @@
+log4j.rootLogger=debug, stdout, R\r
+\r
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender\r
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout\r
+\r
+# Pattern to output the caller's file name and line number.\r
+log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n\r
+\r
+log4j.appender.R=org.apache.log4j.RollingFileAppender\r
+log4j.appender.R.File=target/test-client.log\r
+\r
+log4j.appender.R.MaxFileSize=100KB\r
+# Keep one backup file\r
+log4j.appender.R.MaxBackupIndex=1\r
+\r
+log4j.appender.R.layout=org.apache.log4j.PatternLayout\r
+log4j.appender.R.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n\r
+\r
+#packages\r
+log4j.logger.org.collectionspace=DEBUG\r
+log4j.logger.org.apache=INFO\r
+log4j.logger.httpclient=INFO\r
+log4j.logger.org.jboss.resteasy=WARN\r
similarity index 96%
rename from services/authentication/build.xml
rename to services/authentication/service/build.xml
index 2972776a6c02bf2f06f30d04303eedea10d0586b..86bf45265ef53f16bfb6d141b038b0b9909c46fb 100644 (file)
@@ -4,7 +4,7 @@
         collectionspace authentication service\r
     </description>\r
   <!-- set global properties for this build -->\r
-    <property name="services.trunk" value="../.."/>\r
+    <property name="services.trunk" value="../../.."/>\r
     <property file="${services.trunk}/build.properties" />\r
     <property name="mvn.opts" value="" />\r
     <property name="src" location="src"/>\r
similarity index 76%
rename from services/authentication/pom.xml
rename to services/authentication/service/pom.xml
index 4c0f9a475c820ad7760f34f6be60e68d4fe38088..79b335f65fdd28b59665c91b651bc4223a967a87 100644 (file)
@@ -7,10 +7,10 @@
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <groupId>org.collectionspace.services</groupId>
-    <artifactId>org.collectionspace.services.authentication</artifactId>
+    <artifactId>org.collectionspace.services.authentication.service</artifactId>
     <packaging>jar</packaging>
     <version>1.0</version>
-    <name>services.authentication</name>
+    <name>services.authentication.service</name>
 
     <properties>
         <jboss.version>4.2.3.GA</jboss.version>
     </properties>
 
     <dependencies>
-
-        <!-- utilities -->
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <version>4.1</version>
-            <scope>test</scope>
-        </dependency>
         <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-log4j12</artifactId>
         </dependency>
+        <!-- utilities -->
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.1</version>
+            <scope>test</scope>
+        </dependency>
 
       <!-- javax -->
         <dependency>
     <build>
         <finalName>cspace-services-authn</finalName>
         <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <systemProperties>
+                        <property>
+                            <name>log4j.configuration</name>
+                            <value>file:target/test-classes/log4j.properties</value>
+                        </property>
+                    </systemProperties>
+                </configuration>
+            </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
diff --git a/services/authentication/service/src/main/resources/log4j.properties b/services/authentication/service/src/main/resources/log4j.properties
new file mode 100644 (file)
index 0000000..01d5b6f
--- /dev/null
@@ -0,0 +1,21 @@
+log4j.rootLogger=debug, stdout, R\r
+\r
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender\r
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout\r
+\r
+# Pattern to output the caller's file name and line number.\r
+log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n\r
+\r
+log4j.appender.R=org.apache.log4j.RollingFileAppender\r
+log4j.appender.R.File=${jboss.server.log.dir}/server.log\r
+\r
+log4j.appender.R.MaxFileSize=100KB\r
+# Keep one backup file\r
+log4j.appender.R.MaxBackupIndex=1\r
+\r
+log4j.appender.R.layout=org.apache.log4j.PatternLayout\r
+log4j.appender.R.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n\r
+\r
+#packages\r
+log4j.logger.org.nuxeo=WARN\r
+log4j.logger.org.collectionspace=DEBUG
\ No newline at end of file
diff --git a/services/authentication/service/src/test/resources/log4j.properties b/services/authentication/service/src/test/resources/log4j.properties
new file mode 100644 (file)
index 0000000..18c5103
--- /dev/null
@@ -0,0 +1,23 @@
+log4j.rootLogger=debug, stdout, R\r
+\r
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender\r
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout\r
+\r
+# Pattern to output the caller's file name and line number.\r
+log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n\r
+\r
+log4j.appender.R=org.apache.log4j.RollingFileAppender\r
+log4j.appender.R.File=target/test-client.log\r
+\r
+log4j.appender.R.MaxFileSize=100KB\r
+# Keep one backup file\r
+log4j.appender.R.MaxBackupIndex=1\r
+\r
+log4j.appender.R.layout=org.apache.log4j.PatternLayout\r
+log4j.appender.R.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n\r
+\r
+#packages\r
+log4j.logger.org.collectionspace=DEBUG\r
+log4j.logger.org.apache=INFO\r
+log4j.logger.httpclient=INFO\r
+log4j.logger.org.jboss.resteasy=INFO\r
diff --git a/services/client/src/main/java/org/collectionspace/services/client/BaseServiceClient.java b/services/client/src/main/java/org/collectionspace/services/client/BaseServiceClient.java
new file mode 100644 (file)
index 0000000..91aaee8
--- /dev/null
@@ -0,0 +1,178 @@
+/**\r
+ *  This document is a part of the source code and related artifacts\r
+ *  for CollectionSpace, an open source collections management system\r
+ *  for museums and related institutions:\r
+\r
+ *  http://www.collectionspace.org\r
+ *  http://wiki.collectionspace.org\r
+\r
+ *  Copyright 2009 University of California at Berkeley\r
+\r
+ *  Licensed under the Educational Community License (ECL), Version 2.0.\r
+ *  You may not use this file except in compliance with this License.\r
+\r
+ *  You may obtain a copy of the ECL 2.0 License at\r
+\r
+ *  https://source.collectionspace.org/collection-space/LICENSE.txt\r
+\r
+ *  Unless required by applicable law or agreed to in writing, software\r
+ *  distributed under the License is distributed on an "AS IS" BASIS,\r
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *  See the License for the specific language governing permissions and\r
+ *  limitations under the License.\r
+ */\r
+package org.collectionspace.services.client;\r
+\r
+import java.io.InputStream;\r
+import java.net.URL;\r
+import java.util.Properties;\r
+import org.apache.commons.httpclient.HttpClient;\r
+import org.apache.commons.httpclient.UsernamePasswordCredentials;\r
+import org.apache.commons.httpclient.auth.AuthScope;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+/**\r
+ * BaseServiceClient is an abstract base client of all service clients\r
+ */\r
+public abstract class BaseServiceClient implements CollectionSpaceClient {\r
+\r
+    protected final Logger logger = LoggerFactory.getLogger(BaseServiceClient.class);\r
+    private Properties properties = new Properties();\r
+    private URL url;\r
+    private HttpClient httpClient;\r
+\r
+    protected BaseServiceClient() {\r
+        readProperties();\r
+        setupHttpClient();\r
+    }\r
+\r
+    @Override\r
+    public String getProperty(String propName) {\r
+        return properties.getProperty(propName);\r
+    }\r
+\r
+    @Override\r
+    public void setProperty(String propName, String value) {\r
+        properties.setProperty(propName, value);\r
+    }\r
+\r
+    @Override\r
+    public Object removeProperty(String propName) {\r
+        return properties.remove(propName);\r
+    }\r
+\r
+    public void printProperties() {\r
+        for(Object kobj : properties.keySet()){\r
+            String key = (String) kobj;\r
+            logger.trace("begin property name=" + key + " value=" + properties.get(key));\r
+        }\r
+    }\r
+\r
+    @Override\r
+    public String getBaseURL() {\r
+        return properties.getProperty(URL_PROPERTY);\r
+    }\r
+\r
+    @Override\r
+    public HttpClient getHttpClient() {\r
+        return httpClient;\r
+    }\r
+\r
+    @Override\r
+    public boolean useAuth() {\r
+        String auth = properties.getProperty(AUTH_PROPERTY);\r
+        return Boolean.valueOf(auth);\r
+    }\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\r
+     * as it overrides properties made available using command line\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
+            spec = properties.getProperty(URL_PROPERTY);\r
+            url = new URL(spec);\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
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+    /**\r
+     * setupHttpClient sets up HTTP client for the service client\r
+     * the setup process relies on the following properties\r
+     * URL_PROPERTY\r
+     * USER_PROPERTY\r
+     * PASSWORD_PROPERTY\r
+     * AUTH_PROPERTY\r
+     * SSL_PROPERTY\r
+     */\r
+    @Override\r
+    public void setupHttpClient() {\r
+        if(useAuth()){\r
+            this.httpClient = new HttpClient();\r
+            String user = properties.getProperty(USER_PROPERTY);\r
+            String password = properties.getProperty(PASSWORD_PROPERTY);\r
+            if(logger.isDebugEnabled()){\r
+                logger.debug("setupHttpClient() using url=" + url +\r
+                        " user=" + user + " password=" + password);\r
+            }\r
+\r
+            httpClient.getState().setCredentials(\r
+                    new AuthScope(url.getHost(), url.getPort(), AuthScope.ANY_REALM),\r
+                    new UsernamePasswordCredentials(user, password));\r
+            //JAXRS client library requires HTTP preemptive authentication\r
+            httpClient.getParams().setAuthenticationPreemptive(true);\r
+            if(logger.isDebugEnabled()){\r
+                logger.debug("setupHttpClient: set preemptive authentication");\r
+            }\r
+        }\r
+    }\r
+}\r
index 36597660313b2f61ff357260c76a7c7a61185037..371803ff6637d11888cd3e57649be47a58504937 100644 (file)
-/**\r
- *  This document is a part of the source code and related artifacts\r
- *  for CollectionSpace, an open source collections management system\r
- *  for museums and related institutions:\r
-\r
- *  http://www.collectionspace.org\r
- *  http://wiki.collectionspace.org\r
-\r
- *  Copyright 2009 University of California at Berkeley\r
-\r
- *  Licensed under the Educational Community License (ECL), Version 2.0.\r
- *  You may not use this file except in compliance with this License.\r
-\r
- *  You may obtain a copy of the ECL 2.0 License at\r
-\r
- *  https://source.collectionspace.org/collection-space/LICENSE.txt\r
-\r
- *  Unless required by applicable law or agreed to in writing, software\r
- *  distributed under the License is distributed on an "AS IS" BASIS,\r
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- *  See the License for the specific language governing permissions and\r
- *  limitations under the License.\r
- */\r
-package org.collectionspace.services.client;\r
-\r
-import java.io.InputStream;\r
-import java.net.URL;\r
-import java.util.Properties;\r
-import org.apache.commons.httpclient.HttpClient;\r
-import org.apache.commons.httpclient.UsernamePasswordCredentials;\r
-import org.apache.commons.httpclient.auth.AuthScope;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-/**\r
- * CollectionSpaceClient is an abstract base client of all service clients\r
- */\r
-public abstract class CollectionSpaceClient {\r
-\r
-    public static final String USER_PROPERTY = "cspace.user";\r
-    public static final String PASSWORD_PROPERTY = "cspace.password";\r
-    public static final String AUTH_PROPERTY = "cspace.auth";\r
-    public static final String SSL_PROPERTY = "cspace.ssl";\r
-    public static final String URL_PROPERTY = "cspace.url";\r
-\r
-    \r
-    private static final String PATH = "/cspace-services/";\r
-\r
-    protected final Logger logger = LoggerFactory.getLogger(CollectionSpaceClient.class);\r
-    private Properties properties = new Properties();\r
-    private URL url;\r
-    private HttpClient httpClient;\r
-\r
-    protected CollectionSpaceClient() {\r
-\r
-        readProperties();\r
-\r
-        if(useAuth()){\r
-            httpClient = new HttpClient();\r
-            String user = properties.getProperty(USER_PROPERTY);\r
-            String password = properties.getProperty(PASSWORD_PROPERTY);\r
-            if(logger.isDebugEnabled()){\r
-                logger.debug("using user=" + user + " password=" + password);\r
-            }\r
-            httpClient.getState().setCredentials(\r
-                    new AuthScope(url.getHost(), url.getPort(), AuthScope.ANY_REALM),\r
-                    new UsernamePasswordCredentials(user, password));\r
-            httpClient.getParams().setAuthenticationPreemptive(true);\r
-            if(logger.isDebugEnabled()){\r
-                logger.debug("set up httpClient for authentication");\r
-            }\r
-        }\r
-    }\r
-\r
-    protected String getBaseURL() {\r
-        return (String) properties.getProperty(URL_PROPERTY);\r
-    }\r
-\r
-    protected HttpClient getHttpClient() {\r
-        return httpClient;\r
-    }\r
-\r
-    protected boolean useAuth() {\r
-        String auth = properties.getProperty(AUTH_PROPERTY);\r
-        return Boolean.valueOf(auth);\r
-    }\r
-\r
-    protected 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\r
-     * as it overrides properties made available using command line\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
-                for(Object kobj : properties.keySet()){\r
-                    String key = (String) kobj;\r
-                    logger.debug("begin property name=" + key + " value=" + properties.get(key));\r
-                }\r
-            }\r
-            String spec = System.getProperty(URL_PROPERTY);\r
-            if(spec != null && !"".equals(spec)){\r
-                properties.setProperty(URL_PROPERTY, spec);\r
-            }\r
-            spec = properties.getProperty(URL_PROPERTY);\r
-            url = new URL(spec);\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
-                for(Object kobj : properties.keySet()){\r
-                    String key = (String) kobj;\r
-                    logger.debug("end property name=" + key + " value=" + properties.get(key));\r
-                }\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
-                }\r
-            }\r
-        }\r
-    }\r
-}\r
+/**
+ *  This document is a part of the source code and related artifacts
+ *  for CollectionSpace, an open source collections management system
+ *  for museums and related institutions:
+
+ *  http://www.collectionspace.org
+ *  http://wiki.collectionspace.org
+
+ *  Copyright 2009 University of California at Berkeley
+
+ *  Licensed under the Educational Community License (ECL), Version 2.0.
+ *  You may not use this file except in compliance with this License.
+
+ *  You may obtain a copy of the ECL 2.0 License at
+
+ *  https://source.collectionspace.org/collection-space/LICENSE.txt
+
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.collectionspace.services.client;
+import org.apache.commons.httpclient.HttpClient;
+
+/**
+ *
+ */
+public interface CollectionSpaceClient {
+    String AUTH_PROPERTY = "cspace.auth";
+    String PASSWORD_PROPERTY = "cspace.password";
+    String SSL_PROPERTY = "cspace.ssl";
+    String URL_PROPERTY = "cspace.url";
+    String USER_PROPERTY = "cspace.user";
+
+    String getBaseURL();
+
+    HttpClient getHttpClient();
+
+    String getProperty(String propName);
+
+    Object removeProperty(String propName);
+
+    void setProperty(String propName, String value);
+
+    /**
+     * setupHttpClient sets up HTTP client for the service client
+     * the setup process relies on the following properties
+     * URL_PROPERTY
+     * USER_PROPERTY
+     * PASSWORD_PROPERTY
+     * AUTH_PROPERTY
+     * SSL_PROPERTY
+     */
+    void setupHttpClient();
+
+    boolean useAuth();
+
+    boolean useSSL();
+
+}
index 0331788d2526ed50526fc0e9dba317cae5ca6f00..b9070c37fd54f43adb6bbaf44b38fec50f61ffe6 100644 (file)
@@ -15,12 +15,8 @@ import org.jboss.resteasy.spi.ResteasyProviderFactory;
 
  * @version $Revision:$
  */
-public class CollectionObjectClient extends CollectionSpaceClient {
+public class CollectionObjectClient extends BaseServiceClient {
 
-    /**
-     *
-     */
-    private static final CollectionObjectClient instance = new CollectionObjectClient();
     /**
      *
      */
@@ -31,9 +27,16 @@ public class CollectionObjectClient extends CollectionSpaceClient {
      * Default constructor for CollectionObjectClient class.
      *
      */
-    private CollectionObjectClient() {
+    public CollectionObjectClient() {
         ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
         RegisterBuiltin.register(factory);
+        setProxy();
+    }
+
+    /**
+     * allow to reset proxy as per security needs
+     */
+    public void setProxy() {
         if(useAuth()){
             collectionObjectProxy = ProxyFactory.create(CollectionObjectProxy.class,
                     getBaseURL(), getHttpClient());
@@ -43,15 +46,6 @@ public class CollectionObjectClient extends CollectionSpaceClient {
         }
     }
 
-    /**
-     * FIXME Comment this
-     *
-     * @return
-     */
-    public static CollectionObjectClient getInstance() {
-        return instance;
-    }
-
     /**
      * @return
      * @see org.collectionspace.hello.client.CollectionObjectProxy#getCollectionObject()
index 7de255f64a59f2096061b75213680a6e4f2f297a..619ba790fe5de13b527ac24d2c02d0178f919d00 100644 (file)
@@ -48,7 +48,7 @@ import org.slf4j.LoggerFactory;
  */
 public class CollectionObjectServiceTest {
 
-  private CollectionObjectClient collectionObjectClient = CollectionObjectClient.getInstance();
+  private CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
   private String knownCollectionObjectId = null;
   private final String NON_EXISTENT_ID = createNonExistentIdentifier();
   final Logger logger = LoggerFactory.getLogger(CollectionObjectServiceTest.class);
index cdc28e90310702f6097e142762ccd45649393d56..167c44d1fad036d151faa711fb1861eae4bcf16c 100644 (file)
@@ -15,7 +15,7 @@ import org.jboss.resteasy.spi.ResteasyProviderFactory;
 
  * @version $Revision:$
  */
-public class IntakeClient extends CollectionSpaceClient {
+public class IntakeClient extends BaseServiceClient {
 
 
     /**