]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-259 CSpaceDBLoginModule now can obtain datasource. Requires #971.
authorSanjay Dalal <sanjay.dalal@berkeley.edu>
Wed, 25 Nov 2009 22:55:43 +0000 (22:55 +0000)
committerSanjay Dalal <sanjay.dalal@berkeley.edu>
Wed, 25 Nov 2009 22:55:43 +0000 (22:55 +0000)
test: authentication service tested by enabling security on the service side

services/authentication/client/src/test/java/org/collectionspace/services/authentication/client/AuthenticationServiceTest.java
services/authentication/service/build.xml
services/authentication/service/src/main/java/org/collectionspace/authentication/CSpaceDBLoginModule.java
services/authentication/service/src/main/resources/config/jboss-login-config.xml
services/authentication/service/src/main/resources/db/mysql/test_authn.sql

index 460b6af6204fec32fff3b159be9044159257627e..2ca1edb11be47ba5eb96bba32b848495c9492092 100644 (file)
@@ -46,416 +46,390 @@ import org.slf4j.LoggerFactory;
  */
 public class AuthenticationServiceTest extends AbstractServiceTest {
 
-       /** The known resource id. */
-       private String knownResourceId = null;
-       
-       /** The logger. */
-       final Logger logger = LoggerFactory
-                       .getLogger(AuthenticationServiceTest.class);
+    /** The known resource id. */
+    private String knownResourceId = null;
+    /** The logger. */
+    final Logger logger = LoggerFactory.getLogger(AuthenticationServiceTest.class);
 
-       /* (non-Javadoc)
-        * @see org.collectionspace.services.client.test.AbstractServiceTest#getServicePathComponent()
-        */
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.client.test.AbstractServiceTest#getServicePathComponent()
+     */
     @Override
-       protected String getServicePathComponent() {
-               // no need to return anything but null since no auth resources are
-               // accessed
-               return null;
-       }
+    protected String getServicePathComponent() {
+        // no need to return anything but null since no auth resources are
+        // accessed
+        return null;
+    }
 
-       /* (non-Javadoc)
-        * @see org.collectionspace.services.client.test.AbstractServiceTest#create()
-        */
-       @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class)
-       @Override
-       public void create(String testName) {
-               CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
-               String identifier = this.createIdentifier();
-               MultipartOutput multipart = createCollectionObjectInstance(
-                               collectionObjectClient.getCommonPartName(), identifier);
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.client.test.AbstractServiceTest#create()
+     */
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class)
+    @Override
+    public void create(String testName) {
+        CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+        String identifier = this.createIdentifier();
+        MultipartOutput multipart = createCollectionObjectInstance(
+                collectionObjectClient.getCommonPartName(), identifier);
 
-               if (!collectionObjectClient.isServerSecure()) {
-                       logger.warn("set -Dcspace.server.secure=true to run security tests");
-                       return;
-               }
-               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("create: caught " + e.getMessage());
-                       return;
-               }
-               ClientResponse<Response> res = collectionObjectClient.create(multipart);
-               if(logger.isDebugEnabled()){
+        if (!collectionObjectClient.isServerSecure()) {
+            logger.warn("set -Dcspace.server.secure=true to run security tests");
+            return;
+        }
+        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("create: caught " + e.getMessage());
+            return;
+        }
+        ClientResponse<Response> res = collectionObjectClient.create(multipart);
+        if (logger.isDebugEnabled()) {
             logger.debug("create: status = " + res.getStatus());
         }
-               Assert.assertEquals(res.getStatus(), Response.Status.CREATED
-                               .getStatusCode(), "expected "
-                               + Response.Status.CREATED.getStatusCode());
+        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.
-               knownResourceId = extractId(res);
-       }
+        // Store the ID returned from this create operation for additional tests
+        // below.
+        knownResourceId = extractId(res);
+    }
 
-       /**
-        * Creates the collection object instance without user.
-        */
-       @Test(dependsOnMethods = { "create" })
-       public void createWithoutUser() {
-               CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
-               String identifier = this.createIdentifier();
-               MultipartOutput multipart = createCollectionObjectInstance(
-                               collectionObjectClient.getCommonPartName(), identifier);
-               if (!collectionObjectClient.isServerSecure()) {
-                       logger
-                                       .warn("set -Dcspace.server.secure=true to run security tests");
-                       return;
-               }
-               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("createWithoutUser: caught " + e.getMessage());
-                       return;
-               }
-               ClientResponse<Response> res = collectionObjectClient.create(multipart);
-               if(logger.isDebugEnabled()){
+    /**
+     * Creates the collection object instance without user.
+     */
+    @Test(dependsOnMethods = {"create"})
+    public void createWithoutUser() {
+        CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+        String identifier = this.createIdentifier();
+        MultipartOutput multipart = createCollectionObjectInstance(
+                collectionObjectClient.getCommonPartName(), identifier);
+        if (!collectionObjectClient.isServerSecure()) {
+            logger.warn("set -Dcspace.server.secure=true to run security tests");
+            return;
+        }
+        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("createWithoutUser: caught " + e.getMessage());
+            return;
+        }
+        ClientResponse<Response> res = collectionObjectClient.create(multipart);
+        if (logger.isDebugEnabled()) {
             logger.debug("createWithoutUser: status = " + res.getStatus());
         }
-               Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED
-                               .getStatusCode(), "expected "
-                               + Response.Status.UNAUTHORIZED.getStatusCode());
-       }
+        Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(), "expected " + Response.Status.UNAUTHORIZED.getStatusCode());
+    }
 
-       /**
-        * Creates the collection object instance without password.
-        */
-       @Test(dependsOnMethods = { "createWithoutUser" })
-       public void createWithoutPassword() {
-               CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
-               String identifier = this.createIdentifier();
-               MultipartOutput multipart = createCollectionObjectInstance(
-                               collectionObjectClient.getCommonPartName(), identifier);
-               if (!collectionObjectClient.isServerSecure()) {
-                       logger
-                                       .warn("set -Dcspace.server.secure=true to run security tests");
-                       return;
-               }
-               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("createWithoutPassword: caught " + e.getMessage());
-                       return;
-               }
-               ClientResponse<Response> res = collectionObjectClient.create(multipart);
-               if(logger.isDebugEnabled()){
+    /**
+     * Creates the collection object instance without password.
+     */
+    @Test(dependsOnMethods = {"createWithoutUser"})
+    public void createWithoutPassword() {
+        CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+        String identifier = this.createIdentifier();
+        MultipartOutput multipart = createCollectionObjectInstance(
+                collectionObjectClient.getCommonPartName(), identifier);
+        if (!collectionObjectClient.isServerSecure()) {
+            logger.warn("set -Dcspace.server.secure=true to run security tests");
+            return;
+        }
+        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("createWithoutPassword: caught " + e.getMessage());
+            return;
+        }
+        ClientResponse<Response> res = collectionObjectClient.create(multipart);
+        if (logger.isDebugEnabled()) {
             logger.debug("createWithoutPassword: status = " + res.getStatus());
         }
-               Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED
-                               .getStatusCode(), "expected "
-                               + Response.Status.UNAUTHORIZED.getStatusCode());
-       }
+        Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(), "expected " + Response.Status.UNAUTHORIZED.getStatusCode());
+    }
 
-       /**
-        * Creates the collection object instance with incorrect password.
-        */
-       @Test(dependsOnMethods = { "createWithoutPassword" })
-       public void createWithIncorrectPassword() {
-               CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
-               String identifier = this.createIdentifier();
-               MultipartOutput multipart = createCollectionObjectInstance(
-                               collectionObjectClient.getCommonPartName(), identifier);
-               if (!collectionObjectClient.isServerSecure()) {
-                       logger
-                                       .warn("set -Dcspace.server.secure=true to run security tests");
-                       return;
-               }
-               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("createWithIncorrectPassword: caught "
-                                       + e.getMessage());
-                       return;
-               }
-               ClientResponse<Response> res = collectionObjectClient.create(multipart);
-               if(logger.isDebugEnabled()){
+    /**
+     * Creates the collection object instance with incorrect password.
+     */
+    @Test(dependsOnMethods = {"createWithoutPassword"})
+    public void createWithIncorrectPassword() {
+        CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+        String identifier = this.createIdentifier();
+        MultipartOutput multipart = createCollectionObjectInstance(
+                collectionObjectClient.getCommonPartName(), identifier);
+        if (!collectionObjectClient.isServerSecure()) {
+            logger.warn("set -Dcspace.server.secure=true to run security tests");
+            return;
+        }
+        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("createWithIncorrectPassword: caught " + e.getMessage());
+            return;
+        }
+        ClientResponse<Response> res = collectionObjectClient.create(multipart);
+        if (logger.isDebugEnabled()) {
             logger.debug("createWithIncorrectPassword: status = " + res.getStatus());
         }
-               Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED
-                               .getStatusCode(), "expected "
-                               + Response.Status.UNAUTHORIZED.getStatusCode());
-       }
+        Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(), "expected " + Response.Status.UNAUTHORIZED.getStatusCode());
+    }
 
-       /**
-        * Creates the collection object instance without user password.
-        */
-       @Test(dependsOnMethods = { "createWithoutPassword" })
-       public void createWithoutUserPassword() {
-               CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
-               String identifier = this.createIdentifier();
-               MultipartOutput multipart = createCollectionObjectInstance(
-                               collectionObjectClient.getCommonPartName(), identifier);
-               if (!collectionObjectClient.isServerSecure()) {
-                       logger.warn("set -Dcspace.server.secure=true to run security tests");
-                       return;
-               }
-               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("createWithoutUserPassword: caught " + e.getMessage());
-                       return;
-               }
-               ClientResponse<Response> res = collectionObjectClient.create(multipart);
-               if(logger.isDebugEnabled()){
+    /**
+     * Creates the collection object instance without user password.
+     */
+    @Test(dependsOnMethods = {"createWithoutPassword"})
+    public void createWithoutUserPassword() {
+        CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+        String identifier = this.createIdentifier();
+        MultipartOutput multipart = createCollectionObjectInstance(
+                collectionObjectClient.getCommonPartName(), identifier);
+        if (!collectionObjectClient.isServerSecure()) {
+            logger.warn("set -Dcspace.server.secure=true to run security tests");
+            return;
+        }
+        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("createWithoutUserPassword: caught " + e.getMessage());
+            return;
+        }
+        ClientResponse<Response> res = collectionObjectClient.create(multipart);
+        if (logger.isDebugEnabled()) {
             logger.debug("createWithoutUserPassword: status = " + res.getStatus());
         }
-               Assert.assertEquals(res.getStatus(), Response.Status.FORBIDDEN
-                               .getStatusCode(), "expected "
-                               + Response.Status.FORBIDDEN.getStatusCode());
-       }
+        Assert.assertEquals(res.getStatus(), Response.Status.FORBIDDEN.getStatusCode(), "expected " + Response.Status.FORBIDDEN.getStatusCode());
+    }
 
-       /**
-        * Creates the collection object instance with incorrect user password.
-        */
-       @Test(dependsOnMethods = { "createWithoutPassword" })
-       public void createWithIncorrectUserPassword() {
-               CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
-               String identifier = this.createIdentifier();
-               MultipartOutput multipart = createCollectionObjectInstance(
-                               collectionObjectClient.getCommonPartName(), identifier);
-               if (!collectionObjectClient.isServerSecure()) {
-                       logger.warn("set -Dcspace.server.secure=true to run security tests");
-                       return;
-               }
-               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("createWithIncorrectUserPassword: caught "
-                                       + e.getMessage());
-                       return;
-               }
-               ClientResponse<Response> res = collectionObjectClient.create(multipart);
-               if(logger.isDebugEnabled()){
+    /**
+     * Creates the collection object instance with incorrect user password.
+     */
+    @Test(dependsOnMethods = {"createWithoutPassword"})
+    public void createWithIncorrectUserPassword() {
+        CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+        String identifier = this.createIdentifier();
+        MultipartOutput multipart = createCollectionObjectInstance(
+                collectionObjectClient.getCommonPartName(), identifier);
+        if (!collectionObjectClient.isServerSecure()) {
+            logger.warn("set -Dcspace.server.secure=true to run security tests");
+            return;
+        }
+        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("createWithIncorrectUserPassword: caught " + e.getMessage());
+            return;
+        }
+        ClientResponse<Response> res = collectionObjectClient.create(multipart);
+        if (logger.isDebugEnabled()) {
             logger.debug("createWithIncorrectUserPassword: status = " +
-                res.getStatus());
+                    res.getStatus());
         }
-               Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED
-                               .getStatusCode(), "expected "
-                               + Response.Status.UNAUTHORIZED.getStatusCode());
-       }
+        Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(), "expected " + Response.Status.UNAUTHORIZED.getStatusCode());
+    }
 
-       /* (non-Javadoc)
-        * @see org.collectionspace.services.client.test.AbstractServiceTest#delete()
-        */
-       @Override
-       @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
-        dependsOnMethods = { "createWithIncorrectUserPassword" })
-       public void delete(String testName) {
-               CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
-               collectionObjectClient = new CollectionObjectClient();
-               if (!collectionObjectClient.isServerSecure()) {
-                       logger.warn("set -Dcspace.server.secure=true to run security tests");
-                       return;
-               }
-               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;
-               }
-               if(logger.isDebugEnabled()){
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.client.test.AbstractServiceTest#delete()
+     */
+    @Override
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
+    dependsOnMethods = {"createWithIncorrectUserPassword"})
+    public void delete(String testName) {
+        CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+        collectionObjectClient = new CollectionObjectClient();
+        if (!collectionObjectClient.isServerSecure()) {
+            logger.warn("set -Dcspace.server.secure=true to run security tests");
+            return;
+        }
+        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;
+        }
+        if (logger.isDebugEnabled()) {
             logger.debug("Calling deleteCollectionObject:" + knownResourceId);
         }
-               ClientResponse<Response> res = collectionObjectClient
-                               .delete(knownResourceId);
-               if(logger.isDebugEnabled()){
+        ClientResponse<Response> res = collectionObjectClient.delete(knownResourceId);
+        if (logger.isDebugEnabled()) {
             logger.debug("deleteCollectionObject: status = " + res.getStatus());
         }
-               Assert.assertEquals(res.getStatus(),
-                               Response.Status.OK.getStatusCode(), "expected "
-                                               + Response.Status.OK.getStatusCode());
-       }
+        Assert.assertEquals(res.getStatus(),
+                Response.Status.OK.getStatusCode(), "expected " + Response.Status.OK.getStatusCode());
+    }
 
-       // ---------------------------------------------------------------
-       // Utility methods used by tests above
-       // ---------------------------------------------------------------
-       /**
-        * Creates the collection object instance.
-        * 
-        * @param commonPartName the common part name
-        * @param identifier the identifier
-        * 
-        * @return the multipart output
-        */
-       private MultipartOutput createCollectionObjectInstance(
-                       String commonPartName, String identifier) {
-               return createCollectionObjectInstance(commonPartName, "objectNumber-"
-                               + identifier, "objectName-" + identifier);
-       }
+    // ---------------------------------------------------------------
+    // Utility methods used by tests above
+    // ---------------------------------------------------------------
+    /**
+     * Creates the collection object instance.
+     *
+     * @param commonPartName the common part name
+     * @param identifier the identifier
+     *
+     * @return the multipart output
+     */
+    private MultipartOutput createCollectionObjectInstance(
+            String commonPartName, String identifier) {
+        return createCollectionObjectInstance(commonPartName, "objectNumber-" + identifier, "objectName-" + identifier);
+    }
 
-       /**
-        * Creates the collection object instance.
-        * 
-        * @param commonPartName the common part name
-        * @param objectNumber the object number
-        * @param objectName the object name
-        * 
-        * @return the multipart output
-        */
-       private MultipartOutput createCollectionObjectInstance(
-                       String commonPartName, String objectNumber, String objectName) {
-               CollectionobjectsCommon collectionObject = new CollectionobjectsCommon();
+    /**
+     * Creates the collection object instance.
+     *
+     * @param commonPartName the common part name
+     * @param objectNumber the object number
+     * @param objectName the object name
+     *
+     * @return the multipart output
+     */
+    private MultipartOutput createCollectionObjectInstance(
+            String commonPartName, String objectNumber, String objectName) {
+        CollectionobjectsCommon collectionObject = new CollectionobjectsCommon();
 
-               collectionObject.setObjectNumber(objectNumber);
-               collectionObject.setObjectName(objectName);
-               MultipartOutput multipart = new MultipartOutput();
-               OutputPart commonPart = multipart.addPart(collectionObject,
-                               MediaType.APPLICATION_XML_TYPE);
-               commonPart.getHeaders().add("label", commonPartName);
+        collectionObject.setObjectNumber(objectNumber);
+        collectionObject.setObjectName(objectName);
+        MultipartOutput multipart = new MultipartOutput();
+        OutputPart commonPart = multipart.addPart(collectionObject,
+                MediaType.APPLICATION_XML_TYPE);
+        commonPart.getHeaders().add("label", commonPartName);
 
-               if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug("to be created, collectionobject common ",
-                collectionObject, CollectionobjectsCommon.class);
+                    collectionObject, CollectionobjectsCommon.class);
         }
-               return multipart;
-       }
+        return multipart;
+    }
 
-       /* (non-Javadoc)
-        * @see org.collectionspace.services.client.test.AbstractServiceTest#createList()
-        */
-       @Override
-       public void createList(String testName) throws Exception {
-       }
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.client.test.AbstractServiceTest#createList()
+     */
+    @Override
+    public void createList(String testName) throws Exception {
+    }
 
-       /* (non-Javadoc)
-        * @see org.collectionspace.services.client.test.AbstractServiceTest#createWithEmptyEntityBody()
-        */
-       @Override
-       public void createWithEmptyEntityBody(String testName) throws Exception {
-       }
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.client.test.AbstractServiceTest#createWithEmptyEntityBody()
+     */
+    @Override
+    public void createWithEmptyEntityBody(String testName) throws Exception {
+    }
 
-       /* (non-Javadoc)
-        * @see org.collectionspace.services.client.test.AbstractServiceTest#createWithMalformedXml()
-        */
-       @Override
-       public void createWithMalformedXml(String testName) throws Exception {
-       }
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.client.test.AbstractServiceTest#createWithMalformedXml()
+     */
+    @Override
+    public void createWithMalformedXml(String testName) throws Exception {
+    }
 
-       /* (non-Javadoc)
-        * @see org.collectionspace.services.client.test.AbstractServiceTest#createWithWrongXmlSchema()
-        */
-       @Override
-       public void createWithWrongXmlSchema(String testName) throws Exception {
-       }
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.client.test.AbstractServiceTest#createWithWrongXmlSchema()
+     */
+    @Override
+    public void createWithWrongXmlSchema(String testName) throws Exception {
+    }
 
-       /* (non-Javadoc)
-        * @see org.collectionspace.services.client.test.AbstractServiceTest#read()
-        */
-       @Override
-       public void read(String testName) throws Exception {
-       }
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.client.test.AbstractServiceTest#read()
+     */
+    @Override
+    public void read(String testName) throws Exception {
+    }
 
-       /* (non-Javadoc)
-        * @see org.collectionspace.services.client.test.AbstractServiceTest#readNonExistent()
-        */
-       @Override
-       public void readNonExistent(String testName) throws Exception {
-       }
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.client.test.AbstractServiceTest#readNonExistent()
+     */
+    @Override
+    public void readNonExistent(String testName) throws Exception {
+    }
 
-       /* (non-Javadoc)
-        * @see org.collectionspace.services.client.test.AbstractServiceTest#readList()
-        */
-       @Override
-       public void readList(String testName) throws Exception {
-       }
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.client.test.AbstractServiceTest#readList()
+     */
+    @Override
+    public void readList(String testName) throws Exception {
+    }
 
-       /* (non-Javadoc)
-        * @see org.collectionspace.services.client.test.AbstractServiceTest#update()
-        */
-       @Override
-       public void update(String testName) throws Exception {
-       }
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.client.test.AbstractServiceTest#update()
+     */
+    @Override
+    public void update(String testName) throws Exception {
+    }
 
-       /* (non-Javadoc)
-        * @see org.collectionspace.services.client.test.AbstractServiceTest#updateWithEmptyEntityBody()
-        */
-       @Override
-       public void updateWithEmptyEntityBody(String testName) throws Exception {
-       }
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.client.test.AbstractServiceTest#updateWithEmptyEntityBody()
+     */
+    @Override
+    public void updateWithEmptyEntityBody(String testName) throws Exception {
+    }
 
-       /* (non-Javadoc)
-        * @see org.collectionspace.services.client.test.AbstractServiceTest#updateWithMalformedXml()
-        */
-       @Override
-       public void updateWithMalformedXml(String testName) throws Exception {
-       }
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.client.test.AbstractServiceTest#updateWithMalformedXml()
+     */
+    @Override
+    public void updateWithMalformedXml(String testName) throws Exception {
+    }
 
-       /* (non-Javadoc)
-        * @see org.collectionspace.services.client.test.AbstractServiceTest#updateWithWrongXmlSchema()
-        */
-       @Override
-       public void updateWithWrongXmlSchema(String testName) throws Exception {
-       }
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.client.test.AbstractServiceTest#updateWithWrongXmlSchema()
+     */
+    @Override
+    public void updateWithWrongXmlSchema(String testName) throws Exception {
+    }
 
-       /* (non-Javadoc)
-        * @see org.collectionspace.services.client.test.AbstractServiceTest#updateNonExistent()
-        */
-       @Override
-       public void updateNonExistent(String testName) throws Exception {
-       }
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.client.test.AbstractServiceTest#updateNonExistent()
+     */
+    @Override
+    public void updateNonExistent(String testName) throws Exception {
+    }
 
-       /* (non-Javadoc)
-        * @see org.collectionspace.services.client.test.AbstractServiceTest#deleteNonExistent()
-        */
-       @Override
-       public void deleteNonExistent(String testName) throws Exception {
-       }
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.client.test.AbstractServiceTest#deleteNonExistent()
+     */
+    @Override
+    public void deleteNonExistent(String testName) throws Exception {
+    }
 }
index 374b8c71fea5ab0a5c372382739e5828121c79c3..5bbd99dd8cf29c7d3c5246c81cd994f75f89210b 100644 (file)
             <fileset dir="${src}/main/resources/"/>\r
         </copy>\r
         <echo message="Add authentication-policy to ${jboss.server.cspace}/conf/login-config.xml"/>\r
-        <echo message="Make sure cspace-ds.xml exists in ${jboss.server.cspace}/deploy"/>\r
     </target>\r
 \r
     <target name="undeploy"\r
index 4042360302ff33f6ea2e239c8257518f579c7e18..1d2a7d3dd9155595ea14200f7d4d6f84cf1b040c 100644 (file)
@@ -1,5 +1,25 @@
 /**\r
- * Copyright 2009 University of California at Berkeley\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.authentication;\r
 \r
@@ -7,63 +27,57 @@ import java.lang.reflect.Constructor;
 import java.security.Principal;\r
 import java.security.acl.Group;\r
 import java.sql.Connection;\r
-import java.sql.DriverManager;\r
 import java.sql.PreparedStatement;\r
 import java.sql.ResultSet;\r
 import java.sql.SQLException;\r
 \r
 import java.util.HashMap;\r
 import javax.naming.InitialContext;\r
+import javax.naming.NamingException;\r
 import javax.security.auth.login.FailedLoginException;\r
 import javax.security.auth.login.LoginException;\r
+import javax.sql.DataSource;\r
 import org.jboss.security.SimpleGroup;\r
 import org.jboss.security.SimplePrincipal;\r
 import org.jboss.security.auth.spi.DatabaseServerLoginModule;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
+//import org.slf4j.Logger;\r
+//import org.slf4j.LoggerFactory;\r
 \r
 public class CSpaceDBLoginModule extends DatabaseServerLoginModule {\r
 \r
     //disabled due to classloading problem\r
-    //private Logger logger = LoggerFactory.getLogger(CSpaceDBLoginModule.class);\r
-    private boolean log = true;\r
+//    private Logger logger = LoggerFactory.getLogger(CSpaceDBLoginModule.class);\r
+    private boolean log = true; //logger.isDebugEnabled();\r
 \r
     private void log(String str) {\r
         System.out.println(str);\r
     }\r
 \r
     protected String getUsersPassword() throws LoginException {\r
-        \r
+\r
         String username = getUsername();\r
         String password = null;\r
         Connection conn = null;\r
         PreparedStatement ps = null;\r
         ResultSet rs = null;\r
         InitialContext ctx = null;\r
-        try{\r
-//            Properties env = new Properties();\r
-//            env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");\r
-//            env.setProperty(Context.PROVIDER_URL, "jnp://localhost:1199/");\r
-//            env.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");\r
-//            ctx = new InitialContext(env);\r
-////            ctx = new InitialContext();\r
-//            DataSource ds = (DataSource) ctx.lookup(dsJndiName);\r
-//            if(ds == null){\r
-//                throw new IllegalArgumentException("datasource not found: " + dsJndiName);\r
-//            }\r
-//            conn = ds.getConnection();\r
-            Class.forName("com.mysql.jdbc.Driver");\r
-            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/cspace", "test", "test");\r
+        try {\r
 \r
+            ctx = new InitialContext();\r
+            DataSource ds = (DataSource) ctx.lookup(dsJndiName);\r
+            if (ds == null) {\r
+                throw new IllegalArgumentException("datasource not found: " + dsJndiName);\r
+            }\r
+            conn = ds.getConnection();\r
             // Get the password\r
-            if(log){\r
-                log("Excuting query: " + principalsQuery + ", with username: " + username);\r
+            if (log) {\r
+                log("Executing query: " + principalsQuery + ", with username: " + username);\r
             }\r
             ps = conn.prepareStatement(principalsQuery);\r
             ps.setString(1, username);\r
             rs = ps.executeQuery();\r
-            if(rs.next() == false){\r
-                if(log){\r
+            if (rs.next() == false) {\r
+                if (log) {\r
                     log("Query returned no matches from db");\r
                 }\r
                 throw new FailedLoginException("No matching username found");\r
@@ -71,44 +85,44 @@ public class CSpaceDBLoginModule extends DatabaseServerLoginModule {
 \r
             password = rs.getString(1);\r
             password = convertRawPassword(password);\r
-            if(log){\r
+            if (log) {\r
                 log("Obtained user password");\r
             }\r
-//        }catch(NamingException ex){\r
-//            LoginException le = new LoginException("Error looking up DataSource from: " + dsJndiName);\r
-//            le.initCause(ex);\r
-//            throw le;\r
-        }catch(SQLException ex){\r
+        } catch (NamingException ex) {\r
+            LoginException le = new LoginException("Error looking up DataSource from: " + dsJndiName);\r
+            le.initCause(ex);\r
+            throw le;\r
+        } catch (SQLException ex) {\r
             LoginException le = new LoginException("Query failed");\r
             le.initCause(ex);\r
             throw le;\r
-        }catch(Exception ex){\r
+        } catch (Exception ex) {\r
             LoginException le = new LoginException("Unknown Exception");\r
             le.initCause(ex);\r
             throw le;\r
-        }finally{\r
-            if(rs != null){\r
-                try{\r
+        } finally {\r
+            if (rs != null) {\r
+                try {\r
                     rs.close();\r
-                }catch(SQLException e){\r
+                } catch (SQLException e) {\r
                 }\r
             }\r
-            if(ps != null){\r
-                try{\r
+            if (ps != null) {\r
+                try {\r
                     ps.close();\r
-                }catch(SQLException e){\r
+                } catch (SQLException e) {\r
                 }\r
             }\r
-            if(conn != null){\r
-                try{\r
+            if (conn != null) {\r
+                try {\r
                     conn.close();\r
-                }catch(SQLException ex){\r
+                } catch (SQLException ex) {\r
                 }\r
             }\r
-            if(ctx != null){\r
-                try{\r
+            if (ctx != null) {\r
+                try {\r
                     ctx.close();\r
-                }catch(Exception e){\r
+                } catch (Exception e) {\r
                 }\r
             }\r
         }\r
@@ -122,7 +136,7 @@ public class CSpaceDBLoginModule extends DatabaseServerLoginModule {
      */\r
     protected Group[] getRoleSets() throws LoginException {\r
         String username = getUsername();\r
-        if(log){\r
+        if (log) {\r
             log("getRoleSets using rolesQuery: " + rolesQuery + ", username: " + username);\r
         }\r
 \r
@@ -131,26 +145,24 @@ public class CSpaceDBLoginModule extends DatabaseServerLoginModule {
         PreparedStatement ps = null;\r
         ResultSet rs = null;\r
 \r
-        try{\r
-//         InitialContext ctx = new InitialContext();\r
-//         DataSource ds = (DataSource) ctx.lookup(dsJndiName);\r
-//         conn = ds.getConnection();\r
-            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/cspace", "test", "test");\r
+        try {\r
+            InitialContext ctx = new InitialContext();\r
+            DataSource ds = (DataSource) ctx.lookup(dsJndiName);\r
+            conn = ds.getConnection();\r
             // Get the user role names\r
-            if(log){\r
-                log("Excuting query: " + rolesQuery + ", with username: " + username);\r
+            if (log) {\r
+                log("Executing query: " + rolesQuery + ", with username: " + username);\r
             }\r
 \r
-            ps =\r
-                    conn.prepareStatement(rolesQuery);\r
-            try{\r
+            ps = conn.prepareStatement(rolesQuery);\r
+            try {\r
                 ps.setString(1, username);\r
-            }catch(ArrayIndexOutOfBoundsException ignore){\r
+            } catch (ArrayIndexOutOfBoundsException ignore) {\r
                 // The query may not have any parameters so just try it\r
             }\r
             rs = ps.executeQuery();\r
-            if(rs.next() == false){\r
-                if(log){\r
+            if (rs.next() == false) {\r
+                if (log) {\r
                     log("No roles found");\r
                 }\r
 //                if(aslm.getUnauthenticatedIdentity() == null){\r
@@ -164,59 +176,57 @@ public class CSpaceDBLoginModule extends DatabaseServerLoginModule {
                 return roleSets;\r
             }\r
 \r
-            do{\r
+            do {\r
                 String name = rs.getString(1);\r
                 String groupName = rs.getString(2);\r
-                if(groupName == null || groupName.length() == 0){\r
+                if (groupName == null || groupName.length() == 0) {\r
                     groupName = "Roles";\r
                 }\r
 \r
                 Group group = (Group) setsMap.get(groupName);\r
-                if(group == null){\r
+                if (group == null) {\r
                     group = new SimpleGroup(groupName);\r
                     setsMap.put(groupName, group);\r
                 }\r
 \r
-                try{\r
+                try {\r
 //                    Principal p = aslm.createIdentity(name);\r
                     Principal p = createIdentity(name);\r
-                    if(log){\r
+                    if (log) {\r
                         log("Assign user to role " + name);\r
                     }\r
 \r
                     group.addMember(p);\r
-                }catch(Exception e){\r
+                } catch (Exception e) {\r
                     log("Failed to create principal: " + name + " " + e.toString());\r
                 }\r
 \r
-            }while(rs.next());\r
-        } //      catch(NamingException ex)\r
-        //      {\r
-        //         LoginException le = new LoginException("Error looking up DataSource from: "+dsJndiName);\r
-        //         le.initCause(ex);\r
-        //         throw le;\r
-        //      }\r
-        catch(SQLException ex){\r
+            } while (rs.next());\r
+        } catch (NamingException ex) {\r
+            LoginException le = new LoginException("Error looking up DataSource from: " + dsJndiName);\r
+            le.initCause(ex);\r
+            throw le;\r
+        } catch (SQLException ex) {\r
             LoginException le = new LoginException("Query failed");\r
             le.initCause(ex);\r
             throw le;\r
-        }finally{\r
-            if(rs != null){\r
-                try{\r
+        } finally {\r
+            if (rs != null) {\r
+                try {\r
                     rs.close();\r
-                }catch(SQLException e){\r
+                } catch (SQLException e) {\r
                 }\r
             }\r
-            if(ps != null){\r
-                try{\r
+            if (ps != null) {\r
+                try {\r
                     ps.close();\r
-                }catch(SQLException e){\r
+                } catch (SQLException e) {\r
                 }\r
             }\r
-            if(conn != null){\r
-                try{\r
+            if (conn != null) {\r
+                try {\r
                     conn.close();\r
-                }catch(Exception ex){\r
+                } catch (Exception ex) {\r
                 }\r
             }\r
 \r
@@ -239,18 +249,17 @@ public class CSpaceDBLoginModule extends DatabaseServerLoginModule {
     protected Principal createIdentity(String username)\r
             throws Exception {\r
         Principal p = null;\r
-        if(principalClassName == null){\r
+        if (principalClassName == null) {\r
             p = new SimplePrincipal(username);\r
-        }else{\r
+        } else {\r
             ClassLoader loader = Thread.currentThread().getContextClassLoader();\r
             Class clazz = loader.loadClass(principalClassName);\r
             Class[] ctorSig = {String.class};\r
             Constructor ctor = clazz.getConstructor(ctorSig);\r
             Object[] ctorArgs = {username};\r
-            p =\r
-                    (Principal) ctor.newInstance(ctorArgs);\r
+            p = (Principal) ctor.newInstance(ctorArgs);\r
         }\r
 \r
         return p;\r
     }\r
-}
\ No newline at end of file
+}\r
index 945f643d6e244abdb4ee98eda49c67de78054153..4efd480783f046bfcb8352f0419187ad040b03a4 100644 (file)
@@ -20,7 +20,7 @@ copy before the "other" application-policy
         <authentication>
             <login-module code="org.collectionspace.authentication.CSpaceDBLoginModule"
                              flag="required">
-                <module-option name="dsJndiName">java:/CspaceDS</module-option>
+                <module-option name="dsJndiName">CspaceDS</module-option>
                 <module-option name="hashAlgorithm">SHA-256</module-option>
                 <module-option name="ignorePasswordCase">false</module-option>
                 <module-option name="principalsQuery">
index 9ee6e3fd6f84a513c5274d745d15ccc4a464e7fd..ccdf609829c0bf16e0a7219b8d438c111ee148e1 100644 (file)
@@ -5,8 +5,7 @@
 --\r
 use cspace;\r
 \r
-insert into users (username, passwd) values ('test', 'test');\r
-insert into users (username, passwd) values ('admin', 'admin');\r
+INSERT INTO `users` (`username`,`passwd`) VALUES ('test','n4bQgYhMfWWaL+qgxVrQFaO/TxsrC4Is0V1sFbDwCgg=');\r
 \r
 insert into roles (rolename, rolegroup) values ('collections_manager', 'collections');\r
 insert into roles (rolename, rolegroup) values ('collections_registrar', 'collections');\r