]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-227, CSPACE-228, CSPACE-229 configured service layer for authentication, teste...
authorSanjay Dalal <sanjay.dalal@berkeley.edu>
Mon, 29 Jun 2009 19:04:53 +0000 (19:04 +0000)
committerSanjay Dalal <sanjay.dalal@berkeley.edu>
Mon, 29 Jun 2009 19:04:53 +0000 (19:04 +0000)
services/JaxRsServiceProvider/pom.xml
services/JaxRsServiceProvider/src/main/resources/jndi.properties [deleted file]
services/JaxRsServiceProvider/src/main/webapp/WEB-INF/jboss-web.xml [new file with mode: 0644]
services/JaxRsServiceProvider/src/main/webapp/WEB-INF/web.xml
services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClient.java
services/collectionobject/client/pom.xml
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/collectionobject/client/src/test/resources/log4j.xml
services/pom.xml

index 3e7546313cc928dfe1d602cd7fe1feb20719b661..058a5095470923183587c6347329e158341b8a6b 100644 (file)
     </dependencies>\r
     \r
     <build>\r
-        <finalName>CollectionSpace</finalName>\r
+        <finalName>cspace-services</finalName>\r
         <plugins>\r
             <plugin>\r
                 <groupId>org.codehaus.mojo</groupId>\r
                 <artifactId>jboss-maven-plugin</artifactId>\r
                 <configuration>\r
+                    <serverName>cspace</serverName>\r
                     <jbossHome>${jboss.dir}</jbossHome>\r
                     <port>8180</port>\r
                 </configuration>\r
                             <goal>undeploy</goal>\r
                         </goals>\r
                         <configuration>\r
-                            <fileName>${basedir}/target/CollectionSpace.war</fileName>\r
+                            <fileNames>\r
+                                <param>${project.build.directory}/${project.build.finalName}.war</param>\r
+                            </fileNames>\r
                         </configuration>\r
                     </execution>\r
                     <execution>\r
                             <goal>deploy</goal>\r
                         </goals>\r
                         <configuration>\r
-                            <fileName>${basedir}/target/CollectionSpace.war</fileName>\r
+                            <fileNames>\r
+                                <param>${project.build.directory}/${project.build.finalName}.war</param>\r
+                            </fileNames>\r
                         </configuration>\r
                     </execution>\r
                 </executions>\r
diff --git a/services/JaxRsServiceProvider/src/main/resources/jndi.properties b/services/JaxRsServiceProvider/src/main/resources/jndi.properties
deleted file mode 100644 (file)
index a3aa407..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
-java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
-java.naming.provider.url=jnp://localhost:1099
\ No newline at end of file
diff --git a/services/JaxRsServiceProvider/src/main/webapp/WEB-INF/jboss-web.xml b/services/JaxRsServiceProvider/src/main/webapp/WEB-INF/jboss-web.xml
new file mode 100644 (file)
index 0000000..c91efe0
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<jboss-web>\r
+     <!-- All secure web resources will use this security domain -->\r
+    <security-domain>java:/jaas/cspace</security-domain>\r
+</jboss-web>
\ No newline at end of file
index 29379ffcbb05581dc10968d6841b341533af8213..812508a236fd17535bdeb4d34707801147baec49 100644 (file)
@@ -9,7 +9,7 @@
 -->
 <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
 <web-app>
-    <display-name>CollectionSpace</display-name>
+    <display-name>CollectionSpace Services</display-name>
 
     <context-param>
         <param-name>javax.ws.rs.Application</param-name>
@@ -18,7 +18,7 @@
 
     <context-param>
         <param-name>resteasy.servlet.mapping.prefix</param-name>
-        <param-value>/nuxeo-rest</param-value>
+        <param-value>/</param-value>
     </context-param>
 
     <!-- Listeners -->
 
     <servlet-mapping>
         <servlet-name>Resteasy</servlet-name>
-        <url-pattern>/nuxeo-rest/*</url-pattern>
+        <url-pattern>/*</url-pattern>
     </servlet-mapping>
 
+<!-- BEGIN-AUTH uncomment the following
+    <security-constraint>
+        <web-resource-collection>
+            <web-resource-name>CollectionSpace Services</web-resource-name>
+            <url-pattern>/*</url-pattern>
+        </web-resource-collection>
+        <auth-constraint>
+            <role-name>*</role-name>
+        </auth-constraint>
+
+        <user-data-constraint>
+            <transport-guarantee>NONE</transport-guarantee>
+        </user-data-constraint>
+    </security-constraint>
+
+    <login-config>
+        <auth-method>BASIC</auth-method>
+        <realm-name>CollectionSpace realm</realm-name>
+    </login-config>
+ END AUTH -->
 </web-app>
index 43d3635042112e91c1f543146468875699827397..f50212f9648af9e46fa147f21560b2e40b96764f 100644 (file)
@@ -1,32 +1,76 @@
 package org.collectionspace.services.client;\r
 \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
 public abstract class CollectionSpaceClient {\r
-       static final String URL_PROPERTY = "org.collectionspace.url";\r
-       /*\r
-       static final String URL_PROPERTY_SCHEME = "org.collectionspace.url.schme";\r
-       static final String URL_PROPERTY_HOST = "org.collectionspace.url.host";\r
-       static final String URL_PROPERTY_PORT = "org.collectionspace.url.port";\r
-       static final String URL_PROPERTY_CONTEXT = "org.collectionspace.url.context";\r
-        */\r
-       \r
-       private static final String SCHEME = "http";\r
-       private static final String HOST = "localhost";\r
-       private static final String PORT = "8180";\r
-       private static final String URI = "/CollectionSpace/nuxeo-rest";\r
-       private static final String URL = SCHEME + "://" +\r
-               HOST + ":" +\r
-               PORT +\r
-               URI;\r
-       private String collectionSpaceURL = null;\r
-       \r
-       \r
-       String getURL() {\r
-               String result = collectionSpaceURL;\r
-               \r
-               if (collectionSpaceURL == null) {\r
-                       result = collectionSpaceURL = System.getProperty(URL_PROPERTY, URL);\r
-               }\r
-               \r
-               return result;\r
-       }\r
+\r
+    static final String AUTH_PROPERTY = "org.collectionspace.auth";\r
+    static final String SSL_PROPERTY = "org.collectionspace.ssl";\r
+    static final String URL_PROPERTY = "org.collectionspace.url";\r
+    /*\r
+    static final String URL_PROPERTY_SCHEME = "org.collectionspace.url.schme";\r
+    static final String URL_PROPERTY_HOST = "org.collectionspace.url.host";\r
+    static final String URL_PROPERTY_PORT = "org.collectionspace.url.port";\r
+    static final String URL_PROPERTY_CONTEXT = "org.collectionspace.url.context";\r
+     */\r
+    private static final String HOST = "localhost";\r
+    private static final int PORT = 8180;\r
+    private static final int SSL_PORT = 8543;\r
+    private static final String PATH = "/cspace-services/";\r
+    private static final String DEFAULT_URL = "http://" +\r
+            HOST + ":" + PORT + PATH;\r
+    private static final String DEFAULT_SSL_URL = "https://" +\r
+            HOST + ":" + SSL_PORT + PATH;\r
+    private String baseURL = null;\r
+    private HttpClient httpClient;\r
+    private boolean useAuth;\r
+    private boolean useSSL;\r
+    final Logger logger = LoggerFactory.getLogger(CollectionSpaceClient.class);\r
+\r
+    protected CollectionSpaceClient() {\r
+\r
+        String url = System.getProperty(URL_PROPERTY, DEFAULT_URL);\r
+        if(url != null){\r
+            baseURL = url;\r
+        }\r
+        useAuth = Boolean.getBoolean(AUTH_PROPERTY);\r
+        if(useAuth){\r
+            httpClient = new HttpClient();\r
+            httpClient.getState().setCredentials(\r
+                    new AuthScope(HOST, PORT, AuthScope.ANY_REALM),\r
+                    new UsernamePasswordCredentials("test", "test"));\r
+            httpClient.getParams().setAuthenticationPreemptive(true);\r
+            if(logger.isDebugEnabled()){\r
+                logger.debug("set up httpClient for authentication");\r
+            }\r
+        }\r
+        useSSL = Boolean.getBoolean(SSL_PROPERTY);\r
+        if(logger.isDebugEnabled()){\r
+            logger.debug("useSSL=" + useSSL);\r
+        }\r
+        baseURL = useSSL ? DEFAULT_SSL_URL : DEFAULT_URL;\r
+        if(logger.isDebugEnabled()){\r
+            logger.debug("using baseURL=" + baseURL);\r
+        }\r
+    }\r
+\r
+    protected String getBaseURL() {\r
+        return baseURL;\r
+    }\r
+\r
+    protected HttpClient getHttpClient() {\r
+        return httpClient;\r
+    }\r
+\r
+    protected boolean useAuth() {\r
+        return useAuth;\r
+    }\r
+\r
+    protected boolean useSSL() {\r
+        return useSSL;\r
+    }\r
 }\r
index b2a6f12322088a453f62cf6bfdd06145799f4d5d..29bb3c079e069f51cbbb45e1b98d51f973d1f5e9 100644 (file)
     </dependencies>\r
     \r
     <build>\r
-        <finalName>collectionspace-services-collectionobject-client</finalName>\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>log4j.xml</value>\r
+                        </property>\r
+                    </systemProperties>\r
+                </configuration>\r
+            </plugin>\r
             <plugin>\r
                 <artifactId>maven-compiler-plugin</artifactId>\r
                 <version>2.0.2</version>\r
index 9bd95c175d9ac8df7bdac78478a5efebca18070e..0331788d2526ed50526fc0e9dba317cae5ca6f00 100644 (file)
@@ -17,7 +17,6 @@ import org.jboss.resteasy.spi.ResteasyProviderFactory;
  */
 public class CollectionObjectClient extends CollectionSpaceClient {
 
-
     /**
      *
      */
@@ -35,7 +34,13 @@ public class CollectionObjectClient extends CollectionSpaceClient {
     private CollectionObjectClient() {
         ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
         RegisterBuiltin.register(factory);
-        collectionObjectProxy = ProxyFactory.create(CollectionObjectProxy.class, getURL());
+        if(useAuth()){
+            collectionObjectProxy = ProxyFactory.create(CollectionObjectProxy.class,
+                    getBaseURL(), getHttpClient());
+        }else{
+            collectionObjectProxy = ProxyFactory.create(CollectionObjectProxy.class,
+                    getBaseURL());
+        }
     }
 
     /**
index 97aee047ac9d475ad2d3e85514dd783549c2e9dc..093400cc83442f4561877a65246c5db472e480e4 100644 (file)
@@ -13,6 +13,8 @@ import org.testng.annotations.Test;
 import org.collectionspace.services.collectionobject.CollectionObject;
 import org.collectionspace.services.collectionobject.CollectionObjectList;
 import org.collectionspace.services.client.CollectionObjectClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * A CollectionObjectNuxeoServiceTest.
@@ -24,60 +26,61 @@ public class CollectionObjectServiceTest {
     private CollectionObjectClient collectionObjectClient = CollectionObjectClient.getInstance();
     private String updateId = null;
     private String deleteId = null;
+    final Logger logger = LoggerFactory.getLogger(CollectionObjectServiceTest.class);
 
     @Test
     public void createCollectionObject() {
-       long identifier = this.createIdentifier();
-       
-       CollectionObject collectionObject = createCollectionObject(identifier);
+        long identifier = this.createIdentifier();
+
+        CollectionObject collectionObject = createCollectionObject(identifier);
         ClientResponse<Response> res = collectionObjectClient.createCollectionObject(collectionObject);
         Assert.assertEquals(res.getStatus(), Response.Status.CREATED.getStatusCode());
-        
+
         //store updateId locally for "update" test
-        if (updateId == null) {
-               updateId = extractId(res);
-        } else {
-               deleteId = extractId(res);
-               System.out.println("Set deleteId: " + deleteId);
+        if(updateId == null){
+            updateId = extractId(res);
+        }else{
+            deleteId = extractId(res);
+            verbose("Set deleteId: " + deleteId);
         }
     }
 
     @Test(dependsOnMethods = {"createCollectionObject"})
     public void updateCollectionObject() {
-       ClientResponse<CollectionObject> res = collectionObjectClient.getCollectionObject(updateId);
+        ClientResponse<CollectionObject> res = collectionObjectClient.getCollectionObject(updateId);
         CollectionObject collectionObject = res.getEntity();
         verbose("Got CollectionObject to update with ID: " + updateId,
-                       collectionObject, CollectionObject.class);
-        
+                collectionObject, CollectionObject.class);
+
         //collectionObject.setCsid("updated-" + updateId);
         collectionObject.setObjectNumber("updated-" + collectionObject.getObjectNumber());
         collectionObject.setObjectName("updated-" + collectionObject.getObjectName());
-        
+
         // make call to update service
         res = collectionObjectClient.updateCollectionObject(updateId, collectionObject);
-        
+
         // check the response
-        CollectionObject updatedCollectionObject = res.getEntity();        
+        CollectionObject updatedCollectionObject = res.getEntity();
         Assert.assertEquals(updatedCollectionObject.getObjectName(), collectionObject.getObjectName());
         verbose("updateCollectionObject: ", updatedCollectionObject, CollectionObject.class);
-        
+
         return;
     }
 
     @Test(dependsOnMethods = {"createCollectionObject"})
     public void createCollection() {
-       for (int i = 0; i < 3; i++) {
-               this.createCollectionObject();
-       }
+        for(int i = 0; i < 3; i++){
+            this.createCollectionObject();
+        }
     }
-    
+
     @Test(dependsOnMethods = {"createCollection"})
     public void getCollectionObjectList() {
         //the resource method is expected to return at least an empty list
         CollectionObjectList coList = collectionObjectClient.getCollectionObjectList().getEntity();
         List<CollectionObjectList.CollectionObjectListItem> coItemList = coList.getCollectionObjectListItem();
         int i = 0;
-        for(CollectionObjectList.CollectionObjectListItem pli : coItemList) {
+        for(CollectionObjectList.CollectionObjectListItem pli : coItemList){
             verbose("getCollectionObjectList: list-item[" + i + "] csid=" + pli.getCsid());
             verbose("getCollectionObjectList: list-item[" + i + "] objectNumber=" + pli.getObjectNumber());
             verbose("getCollectionObjectList: list-item[" + i + "] URI=" + pli.getUri());
@@ -87,7 +90,7 @@ public class CollectionObjectServiceTest {
 
     @Test(dependsOnMethods = {"createCollection"})
     public void deleteCollectionObject() {
-       System.out.println("Calling deleteCollectionObject:" + deleteId);
+        verbose("Calling deleteCollectionObject:" + deleteId);
         ClientResponse<Response> res = collectionObjectClient.deleteCollectionObject(deleteId);
         verbose("deleteCollectionObject: csid=" + deleteId);
         verbose("deleteCollectionObject: status = " + res.getStatus());
@@ -95,17 +98,17 @@ public class CollectionObjectServiceTest {
     }
 
     private CollectionObject createCollectionObject(long identifier) {
-       CollectionObject collectionObject = createCollectionObject("objectNumber-" + identifier,
-                       "objectName-" + 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);
+        CollectionObject collectionObject = new CollectionObject();
+
+        collectionObject.setObjectNumber(objectNumber);
+        collectionObject.setObjectName(objectName);
 
         return collectionObject;
     }
@@ -120,7 +123,10 @@ public class CollectionObjectServiceTest {
     }
 
     private void verbose(String msg) {
-        System.out.println("CollectionObject Test: " + msg);
+//        if(logger.isInfoEnabled()){
+//            logger.debug(msg);
+//        }
+        System.out.println(msg);
     }
 
     private void verbose(String msg, Object o, Class clazz) {
@@ -142,9 +148,9 @@ public class CollectionObjectServiceTest {
             verbose("    name=" + mentry.getKey() + " value=" + mentry.getValue());
         }
     }
-    
+
     private long createIdentifier() {
-       long identifier = System.currentTimeMillis();
-       return identifier;
+        long identifier = System.currentTimeMillis();
+        return identifier;
     }
 }
index 52121cb83cedeb64cfa7485e530e05508d28a259..b26abaa9b6d06d013b0bef929099d677dc91d222 100644 (file)
@@ -2,26 +2,25 @@
 <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
 <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
 
-       <appender name="console" class="org.apache.log4j.ConsoleAppender">
-               <param name="Target" value="System.out" />
-               <layout class="org.apache.log4j.TTCCLayout">
-                       <param name="DateFormat" value="ISO8601" />
-               </layout>
-       </appender>
-
-
-       <appender name="unit-tests"
+    <appender name="console" class="org.apache.log4j.ConsoleAppender">
+        <param name="Target" value="System.out" />
+        <layout class="org.apache.log4j.TTCCLayout">
+            <param name="DateFormat" value="ISO8601" />
+        </layout>
+    </appender>
+
+    <appender name="unit-tests"
                class="org.apache.log4j.RollingFileAppender">
-               <param name="File" value="./target/unit-tests.log" />
-               <param name="MaxFileSize" value="10240KB" />
-               <param name="MaxBackupIndex" value="6" />
-               <layout class="org.apache.log4j.TTCCLayout">
-                       <param name="DateFormat" value="ISO8601" />
-               </layout>
-       </appender>
-
-       <logger name="org.apache.commons.httpclient" additivity="false">
-               <level value="warn" />
+        <param name="File" value="./target/unit-tests.log" />
+        <param name="MaxFileSize" value="10240KB" />
+        <param name="MaxBackupIndex" value="6" />
+        <layout class="org.apache.log4j.TTCCLayout">
+            <param name="DateFormat" value="ISO8601" />
+        </layout>
+    </appender>
+
+       <!--logger name="org.apache.commons.httpclient" additivity="false">
+               <level value="info" />
                <appender-ref ref="console" />
                <appender-ref ref="unit-tests" />
        </logger>
                <appender-ref ref="unit-tests" />
        </logger>
 
-       <root>
-               <priority value="debug" />
+       <logger name="org.collectionspace" additivity="false">
+               <level value="info" />
                <appender-ref ref="console" />
                <appender-ref ref="unit-tests" />
-       </root>
+       </logger-->
+    <category name="org.apache.commons.httpclient">
+        <priority value="INFO"/>
+    </category>
+    <category name="httpclient.wire">
+        <priority value="INFO"/>
+    </category>
+    <category name="org.collectionspace.services.client">
+        <priority value="DEBUG"/>
+    </category>
+    <root>
+        <priority value="debug" />
+        <appender-ref ref="console" />
+        <appender-ref ref="unit-tests" />
+    </root>
 
 </log4j:configuration>
 
index 96344dd9a744fb26ed3ebd92bff86429590d4ee2..b847730b82d46153d24bcbfe5005d3692fb354c3 100644 (file)
@@ -22,6 +22,7 @@
 
     <modules>
         <module>common</module>
+        <module>authentication</module>
         <module>client</module>
         <module>collectionobject</module>
         <module>JaxRsServiceProvider</module>