You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by la...@apache.org on 2012/09/24 22:25:56 UTC

svn commit: r1389558 [1/2] - in /airavata/sandbox/airavata-rest-security: ./ modules/commons/airavata-registry-rest/ modules/commons/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/security/basic/ modules/commons/airavat...

Author: lahiru
Date: Mon Sep 24 20:25:54 2012
New Revision: 1389558

URL: http://svn.apache.org/viewvc?rev=1389558&view=rev
Log:
Adding user store changes made by Amila

Added:
    airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/UserStore.java
    airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/UserStoreException.java
    airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/configurations/AbstractConfigurationReader.java
    airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/userstore/
    airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/userstore/AbstractJDBCUserStore.java
    airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/userstore/JDBCUserStore.java
    airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/userstore/LDAPUserStore.java
    airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/userstore/SessionDBUserStore.java
    airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/util/
    airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/util/DBLookup.java
    airavata/sandbox/airavata-rest-security/modules/security/src/test/java/org/apache/airavata/security/configurations/TestUserStore.java
    airavata/sandbox/airavata-rest-security/modules/security/src/test/java/org/apache/airavata/security/userstore/
    airavata/sandbox/airavata-rest-security/modules/security/src/test/java/org/apache/airavata/security/userstore/JDBCUserStoreTest.java
    airavata/sandbox/airavata-rest-security/modules/security/src/test/java/org/apache/airavata/security/userstore/LDAPUserStoreTest.java
    airavata/sandbox/airavata-rest-security/modules/security/src/test/java/org/apache/airavata/security/userstore/SessionDBUserStoreTest.java
    airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/jdbc-authenticator.xml
    airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/ldap-authenticator.xml
    airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/session-authenticator.xml
    airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/testdb/
    airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/testdb/test/
    airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/testdb/test.h2.db   (with props)
    airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/testdb/test.trace.db
    airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/testdb/test/test.trace.db
Modified:
    airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/airavata-registry-rest-services.iml
    airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/pom.xml
    airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/security/basic/BasicAccessAuthenticator.java
    airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/security/session/DBLookup.java
    airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/security/session/SessionAuthenticator.java
    airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/main/resources/authenticators.xml
    airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/test/java/org/apache/airavata/services/registry/rest/security/basic/BasicAccessAuthenticatorTest.java
    airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/test/java/org/apache/airavata/services/registry/rest/security/session/DBLookupTest.java
    airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/test/java/org/apache/airavata/services/registry/rest/security/session/SessionAuthenticatorTest.java
    airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/test/resources/authenticators.xml
    airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/test/resources/testdb/test.h2.db
    airavata/sandbox/airavata-rest-security/modules/security/airavata-security.iml
    airavata/sandbox/airavata-rest-security/modules/security/pom.xml
    airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/AbstractAuthenticator.java
    airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/Authenticator.java
    airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/AuthenticatorConfiguration.java
    airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/configurations/AbstractAuthenticatorConfigurations.java
    airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/configurations/AuthenticatorConfigurationReader.java
    airavata/sandbox/airavata-rest-security/modules/security/src/test/java/org/apache/airavata/security/configurations/AuthenticatorConfigurationReaderTest.java
    airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/authenticators.xml
    airavata/sandbox/airavata-rest-security/pom.xml

Modified: airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/airavata-registry-rest-services.iml
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/airavata-registry-rest-services.iml?rev=1389558&r1=1389557&r2=1389558&view=diff
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/airavata-registry-rest-services.iml (original)
+++ airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/airavata-registry-rest-services.iml Mon Sep 24 20:25:54 2012
@@ -99,6 +99,62 @@
         </sourceRoots>
       </configuration>
     </facet>
+    <facet type="web" name="airavata-registry-rest-services">
+      <configuration>
+        <descriptors>
+          <deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/src/main/webapp/WEB-INF/web.xml" />
+        </descriptors>
+        <webroots>
+          <root url="file://$MODULE_DIR$/src/main/webapp" relative="/" />
+        </webroots>
+        <sourceRoots>
+          <root url="file://$MODULE_DIR$/src/main/java" />
+          <root url="file://$MODULE_DIR$/src/main/resources" />
+        </sourceRoots>
+      </configuration>
+    </facet>
+    <facet type="web" name="airavata-registry-rest-services">
+      <configuration>
+        <descriptors>
+          <deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/src/main/webapp/WEB-INF/web.xml" />
+        </descriptors>
+        <webroots>
+          <root url="file://$MODULE_DIR$/src/main/webapp" relative="/" />
+        </webroots>
+        <sourceRoots>
+          <root url="file://$MODULE_DIR$/src/main/java" />
+          <root url="file://$MODULE_DIR$/src/main/resources" />
+        </sourceRoots>
+      </configuration>
+    </facet>
+    <facet type="web" name="airavata-registry-rest-services">
+      <configuration>
+        <descriptors>
+          <deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/src/main/webapp/WEB-INF/web.xml" />
+        </descriptors>
+        <webroots>
+          <root url="file://$MODULE_DIR$/src/main/webapp" relative="/" />
+        </webroots>
+        <sourceRoots>
+          <root url="file://$MODULE_DIR$/src/main/java" />
+          <root url="file://$MODULE_DIR$/src/main/resources" />
+        </sourceRoots>
+      </configuration>
+    </facet>
+    <facet type="web" name="airavata-registry-rest-services">
+      <configuration>
+        <descriptors>
+          <deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/src/main/webapp/WEB-INF/web.xml" />
+        </descriptors>
+        <webroots>
+          <root url="file://$MODULE_DIR$/src/main/webapp" relative="/" />
+        </webroots>
+        <sourceRoots>
+          <root url="file://$MODULE_DIR$/src/main/java" />
+          <root url="file://$MODULE_DIR$/src/main/resources" />
+        </sourceRoots>
+      </configuration>
+    </facet>
   </component>
   <component name="NewModuleRootManager" inherit-compiler-output="false">
     <output url="file://$MODULE_DIR$/target/classes" />
@@ -113,10 +169,6 @@
     </content>
     <orderEntry type="inheritedJdk" />
     <orderEntry type="sourceFolder" forTests="false" />
-    <orderEntry type="module" module-name="airavata-registry-api" />
-    <orderEntry type="module" module-name="airavata-gfac-schema-utils" />
-    <orderEntry type="module" module-name="airavata-common-utils" />
-    <orderEntry type="module" module-name="airavata-common-registry-api" />
     <orderEntry type="module" module-name="airavata-security" />
     <orderEntry type="module-library">
       <library>
@@ -319,6 +371,76 @@
     <orderEntry type="module-library">
       <library>
         <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/apache/shiro/shiro-core/1.2.1/shiro-core-1.2.1.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="file://$MODULE_DIR$/../../../../../shiro/shiro-root-1.2.1/core/src/main/java" />
+          <root url="file://$MODULE_DIR$/../../../../../shiro/shiro-root-1.2.1/core/src/test/java" />
+          <root url="file://$MODULE_DIR$/../../../../../shiro/shiro-root-1.2.1/samples/aspectj/src/main/java" />
+          <root url="file://$MODULE_DIR$/../../../../../shiro/shiro-root-1.2.1/samples/aspectj/src/test/java" />
+          <root url="file://$MODULE_DIR$/../../../../../shiro/shiro-root-1.2.1/samples/quickstart/src/main/java" />
+          <root url="file://$MODULE_DIR$/../../../../../shiro/shiro-root-1.2.1/samples/spring/src/main/java" />
+          <root url="file://$MODULE_DIR$/../../../../../shiro/shiro-root-1.2.1/samples/spring-client/src/main/java" />
+          <root url="file://$MODULE_DIR$/../../../../../shiro/shiro-root-1.2.1/samples/spring-hibernate/src/main/java" />
+          <root url="file://$MODULE_DIR$/../../../../../shiro/shiro-root-1.2.1/samples/standalone/src/main/java" />
+          <root url="file://$MODULE_DIR$/../../../../../shiro/shiro-root-1.2.1/samples/web/src/test/java" />
+          <root url="file://$MODULE_DIR$/../../../../../shiro/shiro-root-1.2.1/support/aspectj/src/main/aspect" />
+          <root url="file://$MODULE_DIR$/../../../../../shiro/shiro-root-1.2.1/support/aspectj/src/main/java" />
+          <root url="file://$MODULE_DIR$/../../../../../shiro/shiro-root-1.2.1/support/aspectj/src/test/java" />
+          <root url="file://$MODULE_DIR$/../../../../../shiro/shiro-root-1.2.1/support/cas/src/main/java" />
+          <root url="file://$MODULE_DIR$/../../../../../shiro/shiro-root-1.2.1/support/ehcache/src/main/java" />
+          <root url="file://$MODULE_DIR$/../../../../../shiro/shiro-root-1.2.1/support/ehcache/src/test/java" />
+          <root url="file://$MODULE_DIR$/../../../../../shiro/shiro-root-1.2.1/support/guice/src/main/java" />
+          <root url="file://$MODULE_DIR$/../../../../../shiro/shiro-root-1.2.1/support/guice/src/test/java" />
+          <root url="file://$MODULE_DIR$/../../../../../shiro/shiro-root-1.2.1/support/quartz/src/main/java" />
+          <root url="file://$MODULE_DIR$/../../../../../shiro/shiro-root-1.2.1/support/spring/src/main/java" />
+          <root url="file://$MODULE_DIR$/../../../../../shiro/shiro-root-1.2.1/support/spring/src/test/java" />
+          <root url="file://$MODULE_DIR$/../../../../../shiro/shiro-root-1.2.1/tools/hasher/src/main/java" />
+          <root url="file://$MODULE_DIR$/../../../../../shiro/shiro-root-1.2.1/web/src/main/java" />
+          <root url="file://$MODULE_DIR$/../../../../../shiro/shiro-root-1.2.1/web/src/test/java" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/commons-beanutils/commons-beanutils/1.8.3/commons-beanutils-1.8.3.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/commons-dbcp/commons-dbcp/1.4/commons-dbcp-1.4.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/commons-pool/commons-pool/1.5.4/commons-pool-1.5.4.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/com/h2database/h2/1.3.168/h2-1.3.168.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
           <root url="jar://$MAVEN_REPOSITORY$/org/easymock/easymock/3.0/easymock-3.0.jar!/" />
         </CLASSES>
         <JAVADOC />
@@ -490,24 +612,6 @@
     <orderEntry type="module-library">
       <library>
         <CLASSES>
-          <root url="jar://$MAVEN_REPOSITORY$/commons-dbcp/commons-dbcp/1.2.2/commons-dbcp-1.2.2.jar!/" />
-        </CLASSES>
-        <JAVADOC />
-        <SOURCES />
-      </library>
-    </orderEntry>
-    <orderEntry type="module-library">
-      <library>
-        <CLASSES>
-          <root url="jar://$MAVEN_REPOSITORY$/commons-pool/commons-pool/1.3/commons-pool-1.3.jar!/" />
-        </CLASSES>
-        <JAVADOC />
-        <SOURCES />
-      </library>
-    </orderEntry>
-    <orderEntry type="module-library">
-      <library>
-        <CLASSES>
           <root url="jar://$MAVEN_REPOSITORY$/org/apache/jackrabbit/jackrabbit-api/2.2.7/jackrabbit-api-2.2.7.jar!/" />
         </CLASSES>
         <JAVADOC />
@@ -778,7 +882,7 @@
     <orderEntry type="module-library">
       <library>
         <CLASSES>
-          <root url="jar://$MAVEN_REPOSITORY$/com/h2database/h2/1.3.168/h2-1.3.168.jar!/" />
+          <root url="jar://$MAVEN_REPOSITORY$/org/apache/jackrabbit/jackrabbit-jcr-rmi/2.2.7/jackrabbit-jcr-rmi-2.2.7.jar!/" />
         </CLASSES>
         <JAVADOC />
         <SOURCES />
@@ -787,7 +891,7 @@
     <orderEntry type="module-library">
       <library>
         <CLASSES>
-          <root url="jar://$MAVEN_REPOSITORY$/org/apache/jackrabbit/jackrabbit-jcr-rmi/2.2.7/jackrabbit-jcr-rmi-2.2.7.jar!/" />
+          <root url="jar://$MAVEN_REPOSITORY$/com/sun/jersey/contribs/jersey-multipart/1.13/jersey-multipart-1.13.jar!/" />
         </CLASSES>
         <JAVADOC />
         <SOURCES />
@@ -796,7 +900,7 @@
     <orderEntry type="module-library">
       <library>
         <CLASSES>
-          <root url="jar://$MAVEN_REPOSITORY$/com/sun/jersey/contribs/jersey-multipart/1.13/jersey-multipart-1.13.jar!/" />
+          <root url="jar://$MAVEN_REPOSITORY$/org/jvnet/mimepull/1.6/mimepull-1.6.jar!/" />
         </CLASSES>
         <JAVADOC />
         <SOURCES />
@@ -805,7 +909,7 @@
     <orderEntry type="module-library">
       <library>
         <CLASSES>
-          <root url="jar://$MAVEN_REPOSITORY$/org/jvnet/mimepull/1.6/mimepull-1.6.jar!/" />
+          <root url="jar://$MAVEN_REPOSITORY$/org/apache/airavata/airavata-registry-api/0.4-incubating/airavata-registry-api-0.4-incubating.jar!/" />
         </CLASSES>
         <JAVADOC />
         <SOURCES />
@@ -823,6 +927,15 @@
     <orderEntry type="module-library">
       <library>
         <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/apache/airavata/airavata-gfac-schema-utils/0.4-incubating/airavata-gfac-schema-utils-0.4-incubating.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
           <root url="jar://$MAVEN_REPOSITORY$/xmlbeans/xbean/2.5.0/xbean-2.5.0.jar!/" />
         </CLASSES>
         <JAVADOC />
@@ -850,6 +963,15 @@
     <orderEntry type="module-library">
       <library>
         <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/apache/airavata/airavata-common-utils/0.4-incubating/airavata-common-utils-0.4-incubating.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
           <root url="jar://$MAVEN_REPOSITORY$/xerces/xercesImpl/2.9.1/xercesImpl-2.9.1.jar!/" />
         </CLASSES>
         <JAVADOC />
@@ -1090,6 +1212,15 @@
         <SOURCES />
       </library>
     </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/org/apache/airavata/airavata-common-registry-api/0.4-incubating/airavata-common-registry-api-0.4-incubating.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
   </component>
 </module>
 

Modified: airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/pom.xml
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/pom.xml?rev=1389558&r1=1389557&r2=1389558&view=diff
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/pom.xml (original)
+++ airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/pom.xml Mon Sep 24 20:25:54 2012
@@ -104,7 +104,11 @@
             <artifactId>h2</artifactId>
             <version>1.3.168</version>
         </dependency>
-
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <version>5.1.21</version>
+        </dependency>
 
 		<dependency>
 			<groupId>junit</groupId>

Modified: airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/security/basic/BasicAccessAuthenticator.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/security/basic/BasicAccessAuthenticator.java?rev=1389558&r1=1389557&r2=1389558&view=diff
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/security/basic/BasicAccessAuthenticator.java (original)
+++ airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/security/basic/BasicAccessAuthenticator.java Mon Sep 24 20:25:54 2012
@@ -1,29 +1,21 @@
 package org.apache.airavata.services.registry.rest.security.basic;
 
-import org.apache.airavata.security.AbstractDatabaseAuthenticator;
+import org.apache.airavata.security.AbstractAuthenticator;
 import org.apache.airavata.security.AuthenticationException;
-import org.apache.airavata.services.registry.rest.security.session.DBLookup;
+import org.apache.airavata.security.UserStoreException;
 import org.apache.commons.codec.binary.Base64;
-import org.w3c.dom.Element;
 import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
-import java.sql.SQLException;
 
 /**
  * This authenticator handles basic access authentication requests. In basic access authentication
  * we get user name and password as HTTP headers. The password is encoded with base64.
  * More information @link{http://en.wikipedia.org/wiki/Basic_access_authentication}
  */
-public class BasicAccessAuthenticator extends AbstractDatabaseAuthenticator {
+public class BasicAccessAuthenticator extends AbstractAuthenticator {
 
-    private DBLookup dbLookup;
-
-    private String userTable;
-    private String userNameColumn;
-    private String passwordColumn;
 
     private static final String AUTHENTICATOR_NAME = "BasicAccessAuthenticator";
 
@@ -76,7 +68,7 @@ public class BasicAccessAuthenticator ex
 
     @Override
     protected boolean doAuthentication(Object credentials) throws AuthenticationException {
-        if (this.dbLookup == null) {
+        if (this.getUserStore() == null) {
             throw new AuthenticationException("Authenticator is not initialized. Error processing request.");
         }
 
@@ -91,12 +83,9 @@ public class BasicAccessAuthenticator ex
         String password = array[1];
 
         try {
-            String retrievedPassword = dbLookup.getMatchingColumnValue(userTable, passwordColumn, userNameColumn,
-                    userName);
-
-            return retrievedPassword != null && (retrievedPassword.equals(password));
+            return this.getUserStore().authenticate(userName, password);
 
-        } catch (SQLException e) {
+        } catch (UserStoreException e) {
             throw new AuthenticationException("Error querying database for session information.", e);
         }
     }
@@ -180,8 +169,6 @@ public class BasicAccessAuthenticator ex
     @Override
     public void configure(Node node) throws RuntimeException {
 
-        super.configure(node);
-
         /**
          <specificConfigurations>
          <database>
@@ -196,74 +183,12 @@ public class BasicAccessAuthenticator ex
          </specificConfigurations>
          */
 
-        NodeList databaseNodeList = node.getChildNodes();
-
-        Node databaseNode = null;
-
-        for (int k = 0; k < databaseNodeList.getLength(); ++k) {
-
-            Node n = databaseNodeList.item(k);
-
-            if (n != null && n.getNodeType() == Node.ELEMENT_NODE) {
-                databaseNode = n;
-            }
-        }
-
-        if (databaseNode != null) {
-            NodeList nodeList = databaseNode.getChildNodes();
-
-            for (int i = 0; i < nodeList.getLength(); ++i) {
-                Node n = nodeList.item(i);
-
-                if (n.getNodeType() == Node.ELEMENT_NODE) {
-
-                    Element element = (Element) n;
-
-                    if (element.getNodeName().equals("userTableName")) {
-                        userTable = element.getFirstChild().getNodeValue();
-                    } else if (element.getNodeName().equals("userNameColumnName")) {
-                        userNameColumn = element.getFirstChild().getNodeValue();
-                    } else if (element.getNodeName().equals("passwordColumnName")) {
-                        passwordColumn = element.getFirstChild().getNodeValue();
-                    }
-                }
-            }
-        }
-
-        initializeDatabaseLookup();
-
-        StringBuilder stringBuilder = new StringBuilder("Configuring DB parameters for authenticator with User name Table - ");
-        stringBuilder.append(userTable).append(" User name column - ").append(userNameColumn).append(" Password column - ").
-                append(passwordColumn);
-
-        log.info(stringBuilder.toString());
-
-    }
-
-    private void initializeDatabaseLookup() throws RuntimeException {
-
-        this.dbLookup = new DBLookup(getDatabaseURL(), getDatabaseUserName(), getDatabasePassword(), getDatabaseDriver());
-
         try {
-            this.dbLookup.init();
-        } catch (ClassNotFoundException e) {
-            throw new RuntimeException("Error loading database driver. Driver class not found.", e);
-        } catch (InstantiationException e) {
-            throw new RuntimeException("Error loading database driver. Error instantiating driver object.", e);
-        } catch (IllegalAccessException e) {
-            throw new RuntimeException("Error loading database driver. Illegal access to driver object.", e);
+            this.getUserStore().configure(node);
+        } catch (UserStoreException e) {
+            throw new RuntimeException("Error while configuring authenticator user store", e);
         }
-    }
 
-    public String getUserTable() {
-        return userTable;
     }
 
-    public String getUserNameColumn() {
-        return userNameColumn;
-    }
-
-    public String getPasswordColumn() {
-        return passwordColumn;
-    }
 }

Modified: airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/security/session/DBLookup.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/security/session/DBLookup.java?rev=1389558&r1=1389557&r2=1389558&view=diff
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/security/session/DBLookup.java (original)
+++ airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/security/session/DBLookup.java Mon Sep 24 20:25:54 2012
@@ -1,97 +0,0 @@
-package org.apache.airavata.services.registry.rest.security.session;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.sql.*;
-import java.util.Properties;
-
-/**
- * Database lookup.
- */
-public class DBLookup {
-
-    private String jdbcUrl;
-    private String databaseUserName;
-    private String databasePassword;
-    private String driverName;
-
-    protected static Logger log = LoggerFactory.getLogger(DBLookup.class);
-
-    private Properties properties;
-
-
-    public DBLookup(String jdbcUrl, String userName, String password, String driver) {
-
-        this.jdbcUrl = jdbcUrl;
-        this.databaseUserName = userName;
-        this.databasePassword = password;
-        this.driverName = driver;
-    }
-
-    public void init() throws ClassNotFoundException, InstantiationException, IllegalAccessException {
-        properties = new Properties();
-
-        properties.put("user", databaseUserName);
-        properties.put("password", databasePassword);
-        properties.put("characterEncoding", "ISO-8859-1");
-        properties.put("useUnicode", "true");
-
-        loadDriver();
-    }
-
-    public String getMatchingColumnValue(String tableName, String selectColumn, String whereValue)
-            throws SQLException {
-        return getMatchingColumnValue(tableName, selectColumn, selectColumn, whereValue);
-    }
-
-    public String getMatchingColumnValue(String tableName, String selectColumn, String whereColumn, String whereValue)
-            throws SQLException {
-
-        StringBuilder stringBuilder = new StringBuilder();
-
-        stringBuilder.append("SELECT ").append(selectColumn).append(" FROM ").append(tableName)
-                .append(" WHERE ").append(whereColumn).append(" = ?");
-
-        String sql = stringBuilder.toString();
-
-        Connection connection = getConnection();
-
-        PreparedStatement ps = connection.prepareStatement(sql);
-        ResultSet rs = null;
-
-        try {
-            ps.setString(1, whereValue);
-            rs = ps.executeQuery();
-
-            if (rs.next()) {
-                return rs.getString(1);
-            }
-
-        } finally {
-            try {
-                if (rs != null) {
-                    rs.close();
-                }
-
-                ps.close();
-                connection.close();
-
-            } catch (Exception ignore) {
-                log.error("An error occurred while closing database connections ", ignore);
-            }
-        }
-
-        return null;
-    }
-
-    private void loadDriver() throws ClassNotFoundException, IllegalAccessException, InstantiationException {
-        Class.forName(driverName).newInstance();
-    }
-
-    private Connection getConnection() throws SQLException {
-        return DriverManager.getConnection(jdbcUrl, properties);
-    }
-
-}

Modified: airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/security/session/SessionAuthenticator.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/security/session/SessionAuthenticator.java?rev=1389558&r1=1389557&r2=1389558&view=diff
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/security/session/SessionAuthenticator.java (original)
+++ airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/main/java/org/apache/airavata/services/registry/rest/security/session/SessionAuthenticator.java Mon Sep 24 20:25:54 2012
@@ -1,26 +1,18 @@
 package org.apache.airavata.services.registry.rest.security.session;
 
-import org.apache.airavata.security.AbstractDatabaseAuthenticator;
+import org.apache.airavata.security.AbstractAuthenticator;
 import org.apache.airavata.security.AuthenticationException;
-import org.w3c.dom.Element;
+import org.apache.airavata.security.UserStoreException;
 import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
-import java.sql.SQLException;
 
 /**
  * This authenticator will authenticate requests based on a session (NOT HTTP Session) id stored
  * in the database.
  */
-public class SessionAuthenticator extends AbstractDatabaseAuthenticator {
-
-    private DBLookup dbLookup;
-
-    private String sessionTable;
-    private String sessionColumn;
-    private String comparingColumn;
+public class SessionAuthenticator extends AbstractAuthenticator {
 
     private static final String AUTHENTICATOR_NAME = "SessionAuthenticator";
 
@@ -33,19 +25,14 @@ public class SessionAuthenticator extend
     @Override
     public boolean doAuthentication(Object credentials) throws AuthenticationException {
 
-        if (this.dbLookup == null) {
-            throw new AuthenticationException("Authenticator is not initialized. Error processing request.");
-        }
-
-        if (credentials == null)
+       if (credentials == null)
             return false;
 
         HttpServletRequest httpServletRequest = (HttpServletRequest)credentials;
         String sessionTicket = httpServletRequest.getHeader(SESSION_TICKET);
         try {
-            String sessionString = dbLookup.getMatchingColumnValue(sessionTable, sessionColumn, sessionTicket);
-            return (sessionString != null);
-        } catch (SQLException e) {
+            return this.getUserStore().authenticate(sessionTicket);
+        } catch (UserStoreException e) {
             throw new AuthenticationException("Error querying database for session information.", e);
         }
     }
@@ -90,102 +77,13 @@ public class SessionAuthenticator extend
     @Override
     public void configure(Node node) throws RuntimeException {
 
-        super.configure(node);
-
-        /**
-         <specificConfigurations>
-         <database>
-         <jdbcUrl></jdbcUrl>
-         <databaseDriver></databaseDriver>
-         <userName></userName>
-         <password></password>
-         </database>
-         </specificConfigurations>
-         */
-
-        NodeList databaseNodeList = node.getChildNodes();
-
-        Node databaseNode = null;
-
-        for (int k = 0; k < databaseNodeList.getLength(); ++k) {
-
-            Node n = databaseNodeList.item(k);
-
-            if (n != null && n.getNodeType() == Node.ELEMENT_NODE) {
-                databaseNode = n;
-            }
-        }
-
-        if (databaseNode != null) {
-            NodeList nodeList = databaseNode.getChildNodes();
-
-            for (int i = 0; i < nodeList.getLength(); ++i) {
-                Node n = nodeList.item(i);
-
-                if (n.getNodeType() == Node.ELEMENT_NODE) {
-
-                    Element element = (Element) n;
-
-                    if (element.getNodeName().equals("sessionTable")) {
-                        sessionTable = element.getFirstChild().getNodeValue();
-                    } else if (element.getNodeName().equals("sessionColumn")) {
-                        sessionColumn = element.getFirstChild().getNodeValue();
-                    } else if (element.getNodeName().equals("comparingColumn")) {
-                        comparingColumn = element.getFirstChild().getNodeValue();
-                    }
-                }
-            }
-        }
-
-        initializeDatabaseLookup();
-
-        StringBuilder stringBuilder = new StringBuilder("Configuring DB parameters for authenticator with Session Table - ");
-        stringBuilder.append(sessionTable).append(" Session column - ").append(sessionColumn).append(" Comparing column - ").
-                append(comparingColumn);
-
-        log.info(stringBuilder.toString());
-
-    }
-
-    private void initializeDatabaseLookup() throws RuntimeException {
-
-        this.dbLookup = new DBLookup(getDatabaseURL(), getDatabaseUserName(), getDatabasePassword(), getDatabaseDriver());
-
         try {
-            this.dbLookup.init();
-        } catch (ClassNotFoundException e) {
-            throw new RuntimeException("Error loading database driver. Driver class not found.", e);
-        } catch (InstantiationException e) {
-            throw new RuntimeException("Error loading database driver. Error instantiating driver object.", e);
-        } catch (IllegalAccessException e) {
-            throw new RuntimeException("Error loading database driver. Illegal access to driver object.", e);
+            this.getUserStore().configure(node);
+        } catch (UserStoreException e) {
+            throw new RuntimeException("Error while configuring authenticator user store", e);
         }
     }
 
-    public String getSessionTable() {
-        return sessionTable;
-    }
-
-    public void setSessionTable(String sessionTable) {
-        this.sessionTable = sessionTable;
-    }
-
-    public String getSessionColumn() {
-        return sessionColumn;
-    }
-
-    public void setSessionColumn(String sessionColumn) {
-        this.sessionColumn = sessionColumn;
-    }
-
-    public String getComparingColumn() {
-        return comparingColumn;
-    }
-
-    public void setComparingColumn(String comparingColumn) {
-        this.comparingColumn = comparingColumn;
-    }
-
 
     @Override
     public boolean isAuthenticated(Object credentials) {

Modified: airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/main/resources/authenticators.xml
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/main/resources/authenticators.xml?rev=1389558&r1=1389557&r2=1389558&view=diff
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/main/resources/authenticators.xml (original)
+++ airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/main/resources/authenticators.xml Mon Sep 24 20:25:54 2012
@@ -8,7 +8,8 @@ Those configurations are reside inside &
 -->
 
 <authenticators>
-    <authenticator name="sessionAuthenticator" class="org.apache.airavata.services.registry.rest.security.session.SessionAuthenticator" enabled="true" priority="6">
+    <authenticator name="sessionAuthenticator" class="org.apache.airavata.services.registry.rest.security.session.SessionAuthenticator"
+                   enabled="true" priority="6" userstore="org.apache.airavata.security.userstore.SessionDBUserStore">
         <specificConfigurations>
             <database>
                 <!--jdbcUrl>jdbc:h2:modules/commons/airavata-registry-rest/src/test/resources/testdb/test</jdbcUrl-->
@@ -24,14 +25,15 @@ Those configurations are reside inside &
         </specificConfigurations>
     </authenticator>
 
-    <authenticator name="basicAccessAuthenticator" class="org.apache.airavata.services.registry.rest.security.basic.BasicAccessAuthenticator" enabled="true" priority="7">
+    <authenticator name="basicAccessAuthenticator" class="org.apache.airavata.services.registry.rest.security.basic.BasicAccessAuthenticator"
+                   enabled="true" priority="7" userstore="org.apache.airavata.security.userstore.JDBCUserStore">
         <specificConfigurations>
             <database>
                 <!--jdbcUrl>jdbc:h2:modules/commons/airavata-registry-rest/src/test/resources/testdb/test</jdbcUrl-->
-                <jdbcUrl>jdbc:h2:../../src/test/resources/testdb/test</jdbcUrl>
-                <userName>sa</userName>
-                <password>sa</password>
-                <databaseDriver>org.h2.Driver</databaseDriver>
+                <jdbcUrl>jdbc:mysql://localhost/airavata</jdbcUrl>
+                <userName>root</userName>
+                <password>root123</password>
+                <databaseDriver>com.mysql.jdbc.Driver</databaseDriver>
                 <userTableName>AIRAVATA_USER</userTableName>
                 <userNameColumnName>USERID</userNameColumnName>
                 <passwordColumnName>PASSWORD</passwordColumnName>
@@ -39,4 +41,22 @@ Those configurations are reside inside &
         </specificConfigurations>
     </authenticator>
 
+    <authenticator name="basicAccessAuthenticatorLdap" class="org.apache.airavata.services.registry.rest.security.basic.BasicAccessAuthenticator"
+                   enabled="true" priority="6" userstore="org.apache.airavata.security.userstore.LDAPUserStore">
+        <specificConfigurations>
+            <ldap>
+                <!--
+                url - The URL which LDAP server is listening for requests
+                systemUser - The DN of the LDAP server connection user
+                systemUserPassword - The password of the LDAP server connection user
+                userDNTemplate - The DN structure of the users in LDAP
+            -->
+                <url>ldap://localhost:10389</url>
+                <systemUser>admin</systemUser>
+                <systemUserPassword>secret</systemUserPassword>
+                <userDNTemplate>uid={0},ou=users,ou=system</userDNTemplate>
+            </ldap>
+        </specificConfigurations>
+    </authenticator>
+
 </authenticators>
\ No newline at end of file

Modified: airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/test/java/org/apache/airavata/services/registry/rest/security/basic/BasicAccessAuthenticatorTest.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/test/java/org/apache/airavata/services/registry/rest/security/basic/BasicAccessAuthenticatorTest.java?rev=1389558&r1=1389557&r2=1389558&view=diff
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/test/java/org/apache/airavata/services/registry/rest/security/basic/BasicAccessAuthenticatorTest.java (original)
+++ airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/test/java/org/apache/airavata/services/registry/rest/security/basic/BasicAccessAuthenticatorTest.java Mon Sep 24 20:25:54 2012
@@ -56,13 +56,13 @@ public class BasicAccessAuthenticatorTes
 
     }
 
-    public void testConfigure() throws Exception {
+    /*public void testConfigure() throws Exception {
 
         BasicAccessAuthenticator basicAccessAuthenticator = (BasicAccessAuthenticator)authenticator;
 
         assertEquals("AIRAVATA_USER", basicAccessAuthenticator.getUserTable());
         assertEquals("USERID", basicAccessAuthenticator.getUserNameColumn());
         assertEquals("PASSWORD", basicAccessAuthenticator.getPasswordColumn());
-    }
+    }*/
 
 }

Modified: airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/test/java/org/apache/airavata/services/registry/rest/security/session/DBLookupTest.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/test/java/org/apache/airavata/services/registry/rest/security/session/DBLookupTest.java?rev=1389558&r1=1389557&r2=1389558&view=diff
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/test/java/org/apache/airavata/services/registry/rest/security/session/DBLookupTest.java (original)
+++ airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/test/java/org/apache/airavata/services/registry/rest/security/session/DBLookupTest.java Mon Sep 24 20:25:54 2012
@@ -1,6 +1,7 @@
 package org.apache.airavata.services.registry.rest.security.session;
 
 import junit.framework.TestCase;
+import org.apache.airavata.security.util.DBLookup;
 
 import java.io.File;
 

Modified: airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/test/java/org/apache/airavata/services/registry/rest/security/session/SessionAuthenticatorTest.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/test/java/org/apache/airavata/services/registry/rest/security/session/SessionAuthenticatorTest.java?rev=1389558&r1=1389557&r2=1389558&view=diff
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/test/java/org/apache/airavata/services/registry/rest/security/session/SessionAuthenticatorTest.java (original)
+++ airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/test/java/org/apache/airavata/services/registry/rest/security/session/SessionAuthenticatorTest.java Mon Sep 24 20:25:54 2012
@@ -38,13 +38,4 @@ public class SessionAuthenticatorTest ex
         assertTrue(authenticator.canProcess(servletRequestRequest));
 
     }
-
-    public void testConfigure() throws Exception {
-
-        SessionAuthenticator sessionAuthenticator = (SessionAuthenticator)authenticator;
-
-        assertEquals("Persons", sessionAuthenticator.getSessionTable());
-        assertEquals("sessionId", sessionAuthenticator.getSessionColumn());
-        assertEquals("sessionId", sessionAuthenticator.getComparingColumn());
-    }
 }

Modified: airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/test/resources/authenticators.xml
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/test/resources/authenticators.xml?rev=1389558&r1=1389557&r2=1389558&view=diff
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/test/resources/authenticators.xml (original)
+++ airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/test/resources/authenticators.xml Mon Sep 24 20:25:54 2012
@@ -8,7 +8,8 @@ Those configurations are reside inside &
 -->
 
 <authenticators>
-    <authenticator name="sessionAuthenticator" class="org.apache.airavata.services.registry.rest.security.session.SessionAuthenticator" enabled="true" priority="6">
+    <authenticator name="sessionAuthenticator" class="org.apache.airavata.services.registry.rest.security.session.SessionAuthenticator"
+                   enabled="true" priority="6" userstore="org.apache.airavata.security.userstore.SessionDBUserStore">
         <specificConfigurations>
             <database>
                 <!--jdbcUrl>jdbc:h2:modules/commons/airavata-registry-rest/src/test/resources/testdb/test</jdbcUrl-->
@@ -23,7 +24,8 @@ Those configurations are reside inside &
         </specificConfigurations>
     </authenticator>
 
-    <authenticator name="basicAccessAuthenticator" class="org.apache.airavata.services.registry.rest.security.basic.BasicAccessAuthenticator" enabled="true" priority="7">
+    <authenticator name="basicAccessAuthenticator" class="org.apache.airavata.services.registry.rest.security.basic.BasicAccessAuthenticator"
+                   enabled="true" priority="7" userstore="org.apache.airavata.security.userstore.JDBCUserStore">
         <specificConfigurations>
             <database>
                 <!--jdbcUrl>jdbc:h2:modules/commons/airavata-registry-rest/src/test/resources/testdb/test</jdbcUrl-->

Modified: airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/test/resources/testdb/test.h2.db
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/commons/airavata-registry-rest/src/test/resources/testdb/test.h2.db?rev=1389558&r1=1389557&r2=1389558&view=diff
==============================================================================
Binary files - no diff available.

Modified: airavata/sandbox/airavata-rest-security/modules/security/airavata-security.iml
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/airavata-security.iml?rev=1389558&r1=1389557&r2=1389558&view=diff
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/security/airavata-security.iml (original)
+++ airavata/sandbox/airavata-rest-security/modules/security/airavata-security.iml Mon Sep 24 20:25:54 2012
@@ -23,7 +23,7 @@
     <orderEntry type="module-library">
       <library>
         <CLASSES>
-          <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.7/junit-4.7.jar!/" />
+          <root url="jar://$MAVEN_REPOSITORY$/org/apache/shiro/shiro-core/1.2.1/shiro-core-1.2.1.jar!/" />
         </CLASSES>
         <JAVADOC />
         <SOURCES />
@@ -41,6 +41,51 @@
     <orderEntry type="module-library">
       <library>
         <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/commons-beanutils/commons-beanutils/1.8.3/commons-beanutils-1.8.3.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/commons-dbcp/commons-dbcp/1.4/commons-dbcp-1.4.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/commons-pool/commons-pool/1.5.4/commons-pool-1.5.4.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.7/junit-4.7.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MAVEN_REPOSITORY$/com/h2database/h2/1.3.168/h2-1.3.168.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
           <root url="jar://$MAVEN_REPOSITORY$/log4j/log4j/1.2.16/log4j-1.2.16.jar!/" />
         </CLASSES>
         <JAVADOC />

Modified: airavata/sandbox/airavata-rest-security/modules/security/pom.xml
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/pom.xml?rev=1389558&r1=1389557&r2=1389558&view=diff
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/security/pom.xml (original)
+++ airavata/sandbox/airavata-rest-security/modules/security/pom.xml Mon Sep 24 20:25:54 2012
@@ -40,6 +40,22 @@
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-simple</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.shiro</groupId>
+            <artifactId>shiro-core</artifactId>
+            <version>1.2.1</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-dbcp</groupId>
+            <artifactId>commons-dbcp</artifactId>
+            <version>1.4</version>
+        </dependency>
+	 <dependency>
+            <groupId>com.h2database</groupId>
+            <artifactId>h2</artifactId>
+            <version>1.3.168</version>
+        </dependency>
+
     </dependencies>
     <build>
         <plugins>
@@ -52,5 +68,12 @@
                 </configuration>
             </plugin>
         </plugins>
+        <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
+        <testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
+        <testResources>
+            <testResource>
+                <directory>${project.basedir}/src/test/resources</directory>
+            </testResource>
+        </testResources>
     </build>
 </project>

Modified: airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/AbstractAuthenticator.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/AbstractAuthenticator.java?rev=1389558&r1=1389557&r2=1389558&view=diff
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/AbstractAuthenticator.java (original)
+++ airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/AbstractAuthenticator.java Mon Sep 24 20:25:54 2012
@@ -24,6 +24,8 @@ public abstract class AbstractAuthentica
 
     protected boolean enabled = true;
 
+    protected UserStore userStore;
+
     public AbstractAuthenticator() {
 
     }
@@ -32,6 +34,14 @@ public abstract class AbstractAuthentica
         this.authenticatorName = name;
     }
 
+    public void setUserStore(UserStore store) {
+        this.userStore = store;
+    }
+
+    public UserStore getUserStore() {
+        return this.userStore;
+    }
+
     public int getPriority() {
         return priority;
     }

Modified: airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/Authenticator.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/Authenticator.java?rev=1389558&r1=1389557&r2=1389558&view=diff
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/Authenticator.java (original)
+++ airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/Authenticator.java Mon Sep 24 20:25:54 2012
@@ -55,4 +55,17 @@ public interface Authenticator {
      */
     boolean isEnabled();
 
+    /**
+     * User store that should be used by this authenticator. When authenticating a request
+     * authenticator should use the user store set by this method.
+     * @param userStore The user store to be used.
+     */
+    void setUserStore(UserStore userStore);
+
+    /**
+     * Gets the user store used by this authenticator.
+     * @return The user store used by this authenticator.
+     */
+    UserStore getUserStore();
+
 }

Modified: airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/AuthenticatorConfiguration.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/AuthenticatorConfiguration.java?rev=1389558&r1=1389557&r2=1389558&view=diff
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/AuthenticatorConfiguration.java (original)
+++ airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/AuthenticatorConfiguration.java Mon Sep 24 20:25:54 2012
@@ -1,18 +0,0 @@
-package org.apache.airavata.security;
-
-/**
- * An interface class define authenticator configurations. Based on the mechanism we need
- * to implement this interface to get the proper configuration.
- */
-public interface AuthenticatorConfiguration {
-
-    /**
-     * Load configurations from a file or some other place.
-     */
-    void load ();
-
-    /**
-     * Serialize configurations.
-     */
-    void serialize();
-}

Added: airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/UserStore.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/UserStore.java?rev=1389558&view=auto
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/UserStore.java (added)
+++ airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/UserStore.java Mon Sep 24 20:25:54 2012
@@ -0,0 +1,72 @@
+/*
+ *
+ *  *
+ *  * Licensed to the Apache Software Foundation (ASF) under one
+ *  * or more contributor license agreements.  See the NOTICE file
+ *  * distributed with this work for additional information
+ *  * regarding copyright ownership.  The ASF licenses this file
+ *  * to you under the Apache License, Version 2.0 (the
+ *  * "License"); you may not use this file except in compliance
+ *  * with the License.  You may obtain a copy of the License at
+ *  *
+ *  *   http://www.apache.org/licenses/LICENSE-2.0
+ *  *
+ *  * 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.apache.airavata.security;
+
+import org.w3c.dom.Node;
+
+/**
+ * An interface to wrap the functionality of a user store. A user store is place where we keep user attribute
+ * information. Usually this contains, user id, user name, password etc ...
+ * We also authenticate users against the credentials stored in a user store. In addition to user attributes
+ * we also store role information and group information.
+ * This interface provide methods to manipulated data in a user store.
+ * Such operations are as follows,
+ * <ol>
+ *     <li>authenticate user</li>
+ *     <li>add user</li>
+ *     <li>delete user</li>
+ *     <li>add a role</li>
+ *     <li>delete a role</li>
+ *     <li>... etc ...</li>
+ * </ol>
+ */
+public interface UserStore {
+
+    /**
+     * Checks whether given user exists in the user store and its credentials match with the credentials stored
+     * in the user store.
+     * @param userName Name of the user to authenticate.
+     * @param credentials User credentials as an object. User credentials may not be a string always.
+     * @return True if user exists in the user store and its credentials match with the credentials in user store.
+     *          <code>false</code> else.
+     * @throws UserStoreException if a system wide error occurred while authenticating the user.
+     */
+    boolean authenticate(String userName, Object credentials) throws UserStoreException;
+
+    /**
+     * Authenticates a user using a token.
+     * @param credentials The token information.
+     * @return <code>true</code> if authentication successful else <code>false</code>.
+     * @throws UserStoreException if a system wide error occurred while authenticating the user.
+     */
+    boolean authenticate(Object credentials) throws UserStoreException;
+
+    /**
+     * This method will do necessary configurations of the user store.
+     * @param node An XML configuration node.
+     * @throws RuntimeException If an error occurred while configuring the authenticator.
+     */
+    void configure(Node node) throws UserStoreException;
+
+}

Added: airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/UserStoreException.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/UserStoreException.java?rev=1389558&view=auto
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/UserStoreException.java (added)
+++ airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/UserStoreException.java Mon Sep 24 20:25:54 2012
@@ -0,0 +1,47 @@
+/*
+ *
+ *  *
+ *  * Licensed to the Apache Software Foundation (ASF) under one
+ *  * or more contributor license agreements.  See the NOTICE file
+ *  * distributed with this work for additional information
+ *  * regarding copyright ownership.  The ASF licenses this file
+ *  * to you under the Apache License, Version 2.0 (the
+ *  * "License"); you may not use this file except in compliance
+ *  * with the License.  You may obtain a copy of the License at
+ *  *
+ *  *   http://www.apache.org/licenses/LICENSE-2.0
+ *  *
+ *  * 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.apache.airavata.security;
+
+/**
+ * Exception class to wrap user store errors.
+ */
+public class UserStoreException extends Exception {
+
+    public UserStoreException() {
+        super();
+    }
+
+    public UserStoreException(String message) {
+        super(message);
+    }
+
+    public UserStoreException(String message, Exception e) {
+        super(message, e);
+    }
+
+    public UserStoreException(Exception e) {
+        super(e);
+    }
+
+}

Modified: airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/configurations/AbstractAuthenticatorConfigurations.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/configurations/AbstractAuthenticatorConfigurations.java?rev=1389558&r1=1389557&r2=1389558&view=diff
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/configurations/AbstractAuthenticatorConfigurations.java (original)
+++ airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/configurations/AbstractAuthenticatorConfigurations.java Mon Sep 24 20:25:54 2012
@@ -1,30 +0,0 @@
-package org.apache.airavata.security.configurations;
-
-import org.apache.airavata.security.AuthenticatorConfiguration;
-
-/**
- * An abstract implementation of Authenticator configurations.
- * An authenticator configurations will have two types of configurations.
- * <ol>
- *     <li>Configurations common to all authenticators. This includes configurations such as authenticator name,
- *     the priority, whether authenticator is enabled or not.</li>
- *     <li>Configurations which are specific to a particular authenticator.</li>
- * </ol>
- */
-public abstract class AbstractAuthenticatorConfigurations implements AuthenticatorConfiguration {
-
-    private String authenticatorName;
-
-    private String authenticatorClassName;
-
-    private boolean isEnabled;
-
-    private int authenticatorPriority;
-
-    public AbstractAuthenticatorConfigurations() {
-
-    }
-
-
-
-}

Added: airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/configurations/AbstractConfigurationReader.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/configurations/AbstractConfigurationReader.java?rev=1389558&view=auto
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/configurations/AbstractConfigurationReader.java (added)
+++ airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/configurations/AbstractConfigurationReader.java Mon Sep 24 20:25:54 2012
@@ -0,0 +1,58 @@
+/*
+ *
+ *  *
+ *  * Licensed to the Apache Software Foundation (ASF) under one
+ *  * or more contributor license agreements.  See the NOTICE file
+ *  * distributed with this work for additional information
+ *  * regarding copyright ownership.  The ASF licenses this file
+ *  * to you under the Apache License, Version 2.0 (the
+ *  * "License"); you may not use this file except in compliance
+ *  * with the License.  You may obtain a copy of the License at
+ *  *
+ *  *   http://www.apache.org/licenses/LICENSE-2.0
+ *  *
+ *  * 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.apache.airavata.security.configurations;
+
+
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Abstract implementation to read configurations.
+ */
+public abstract class AbstractConfigurationReader {
+
+    public void init(String fileName) throws IOException, SAXException, ParserConfigurationException {
+
+        File configurationFile = new File(fileName);
+
+        if (!configurationFile.canRead()) {
+            throw new IOException("Error reading configuration file " + configurationFile.getAbsolutePath());
+        }
+
+        FileInputStream streamIn = new FileInputStream(configurationFile);
+
+        try {
+            init(streamIn);
+        } finally {
+            streamIn.close();
+        }
+    }
+
+    public abstract void init(InputStream inputStream) throws IOException, ParserConfigurationException, SAXException;
+}

Modified: airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/configurations/AuthenticatorConfigurationReader.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/configurations/AuthenticatorConfigurationReader.java?rev=1389558&r1=1389557&r2=1389558&view=diff
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/configurations/AuthenticatorConfigurationReader.java (original)
+++ airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/configurations/AuthenticatorConfigurationReader.java Mon Sep 24 20:25:54 2012
@@ -2,6 +2,7 @@ package org.apache.airavata.security.con
 
 import org.apache.airavata.security.AbstractAuthenticator;
 import org.apache.airavata.security.Authenticator;
+import org.apache.airavata.security.UserStore;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -13,8 +14,6 @@ import org.xml.sax.SAXException;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
-import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
@@ -25,7 +24,7 @@ import java.util.List;
 /**
  * This class will read authenticators.xml and load all configurations related to authenticators.
  */
-public class AuthenticatorConfigurationReader {
+public class AuthenticatorConfigurationReader extends AbstractConfigurationReader {
 
     private List<Authenticator> authenticatorList = new ArrayList<Authenticator>();
 
@@ -35,23 +34,6 @@ public class AuthenticatorConfigurationR
 
     }
 
-    public void init(String fileName) throws IOException, SAXException, ParserConfigurationException {
-
-        File configurationFile = new File(fileName);
-
-        if (!configurationFile.canRead()) {
-            throw new IOException("Error reading configuration file " + configurationFile.getAbsolutePath());
-        }
-
-        FileInputStream streamIn = new FileInputStream(configurationFile);
-
-        try {
-            init(streamIn);
-        } finally {
-            streamIn.close();
-        }
-    }
-
     public void init(InputStream inputStream) throws IOException, ParserConfigurationException, SAXException {
 
         DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
@@ -72,8 +54,18 @@ public class AuthenticatorConfigurationR
                 String className = namedNodeMap.getNamedItem("class").getNodeValue();
                 String enabled = namedNodeMap.getNamedItem("enabled").getNodeValue();
                 String priority = namedNodeMap.getNamedItem("priority").getNodeValue();
+                String userStoreClass = namedNodeMap.getNamedItem("userstore").getNodeValue();
+
+                if (className == null) {
+                    reportError("class");
+                }
+
+                if (userStoreClass == null) {
+                    reportError("userstore");
+                }
 
-                Authenticator authenticator = createAuthenticator(name, className, enabled, priority);
+                Authenticator authenticator = createAuthenticator(name, className, enabled,
+                        priority, userStoreClass);
 
                 NodeList configurationNodes = node.getChildNodes();
 
@@ -104,7 +96,13 @@ public class AuthenticatorConfigurationR
         }
     }
 
-    protected Authenticator createAuthenticator(String name, String className, String enabled, String priority) {
+    private void reportError(String element) throws ParserConfigurationException {
+        throw new ParserConfigurationException("Error in configuration. Missing mandatory element "
+                + element);
+    }
+
+    protected Authenticator createAuthenticator(String name, String className, String enabled,
+                                                String priority, String userStoreClassName) {
 
         log.info("Loading authenticator class " + className + " and name " + name);
 
@@ -131,6 +129,9 @@ public class AuthenticatorConfigurationR
                 authenticatorInstance.setPriority(Integer.parseInt(priority));
             }
 
+            UserStore userStore = createUserStore(userStoreClassName);
+            authenticatorInstance.setUserStore(userStore);
+
             return authenticatorInstance;
 
         } catch (InstantiationException e) {
@@ -146,6 +147,30 @@ public class AuthenticatorConfigurationR
 
     }
 
+    protected UserStore createUserStore(String userStoreClassName) {
+
+        try {
+            Class userStoreClass = Class.forName(userStoreClassName, true,
+                    Thread.currentThread().getContextClassLoader());
+
+            return (UserStore)userStoreClass.newInstance();
+        } catch (ClassNotFoundException e) {
+            log.error("Error loading authenticator class " + userStoreClassName);
+            throw new RuntimeException("Error loading authenticator class " + userStoreClassName, e);
+
+        } catch (InstantiationException e) {
+            String error = "Error instantiating authenticator class " + userStoreClassName + " object.";
+            log.error(error);
+            throw new RuntimeException(error, e);
+
+        } catch (IllegalAccessException e) {
+            String error = "Not allowed to instantiate authenticator class " + userStoreClassName;
+            log.error(error);
+            throw new RuntimeException(error, e);
+        }
+
+    }
+
     public List<Authenticator> getAuthenticatorList() {
         return Collections.unmodifiableList(authenticatorList);
     }

Added: airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/userstore/AbstractJDBCUserStore.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/userstore/AbstractJDBCUserStore.java?rev=1389558&view=auto
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/userstore/AbstractJDBCUserStore.java (added)
+++ airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/userstore/AbstractJDBCUserStore.java Mon Sep 24 20:25:54 2012
@@ -0,0 +1,115 @@
+/*
+ *
+ *  *
+ *  * Licensed to the Apache Software Foundation (ASF) under one
+ *  * or more contributor license agreements.  See the NOTICE file
+ *  * distributed with this work for additional information
+ *  * regarding copyright ownership.  The ASF licenses this file
+ *  * to you under the Apache License, Version 2.0 (the
+ *  * "License"); you may not use this file except in compliance
+ *  * with the License.  You may obtain a copy of the License at
+ *  *
+ *  *   http://www.apache.org/licenses/LICENSE-2.0
+ *  *
+ *  * 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.apache.airavata.security.userstore;
+
+import org.apache.airavata.security.UserStore;
+import org.apache.airavata.security.UserStoreException;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+
+/**
+ * An abstract implementation of the UserStore. This will encapsulate
+ * JDBC configurations reading code.
+ */
+public abstract class AbstractJDBCUserStore implements UserStore {
+
+    private String databaseURL = null;
+    private String databaseDriver = null;
+    private String databaseUserName = null;
+    private String databasePassword = null;
+
+    public String getDatabaseURL() {
+        return databaseURL;
+    }
+
+    public String getDatabaseDriver() {
+        return databaseDriver;
+    }
+
+    public String getDatabaseUserName() {
+        return databaseUserName;
+    }
+
+    public String getDatabasePassword() {
+        return databasePassword;
+    }
+
+    /**
+     * Configures primary JDBC parameters. i.e
+     * @param node An XML configuration node.
+     * @throws UserStoreException
+     */
+    public void configure(Node node) throws UserStoreException{
+
+        /**
+         <specificConfigurations>
+         <database>
+         <jdbcUrl></jdbcUrl>
+         <databaseDriver></databaseDriver>
+         <userName></userName>
+         <password></password>
+         </database>
+         </specificConfigurations>
+         */
+
+        NodeList databaseNodeList = node.getChildNodes();
+
+        Node databaseNode = null;
+
+        for (int k = 0; k < databaseNodeList.getLength(); ++k) {
+
+            Node n = databaseNodeList.item(k);
+
+            if (n != null && n.getNodeType() == Node.ELEMENT_NODE) {
+                databaseNode = n;
+            }
+        }
+
+        if (databaseNode != null) {
+            NodeList nodeList = databaseNode.getChildNodes();
+
+            for (int i = 0; i < nodeList.getLength(); ++i) {
+                Node n = nodeList.item(i);
+
+                if (n.getNodeType() == Node.ELEMENT_NODE) {
+
+                    Element element = (Element) n;
+
+                    if (element.getNodeName().equals("jdbcUrl")) {
+                        databaseURL = element.getFirstChild().getNodeValue();
+                    } else if (element.getNodeName().equals("databaseDriver")) {
+                        databaseDriver = element.getFirstChild().getNodeValue();
+                    } else if (element.getNodeName().equals("userName")) {
+                        databaseUserName = element.getFirstChild().getNodeValue();
+                    } else if (element.getNodeName().equals("password")) {
+                        databasePassword = element.getFirstChild().getNodeValue();
+                    }
+                }
+            }
+        }
+
+    }
+}

Added: airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/userstore/JDBCUserStore.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/userstore/JDBCUserStore.java?rev=1389558&view=auto
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/userstore/JDBCUserStore.java (added)
+++ airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/userstore/JDBCUserStore.java Mon Sep 24 20:25:54 2012
@@ -0,0 +1,158 @@
+/*
+ *
+ *  *
+ *  * Licensed to the Apache Software Foundation (ASF) under one
+ *  * or more contributor license agreements.  See the NOTICE file
+ *  * distributed with this work for additional information
+ *  * regarding copyright ownership.  The ASF licenses this file
+ *  * to you under the Apache License, Version 2.0 (the
+ *  * "License"); you may not use this file except in compliance
+ *  * with the License.  You may obtain a copy of the License at
+ *  *
+ *  *   http://www.apache.org/licenses/LICENSE-2.0
+ *  *
+ *  * 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.apache.airavata.security.userstore;
+
+import org.apache.airavata.security.UserStore;
+import org.apache.airavata.security.UserStoreException;
+import org.apache.airavata.security.util.DBLookup;
+import org.apache.shiro.authc.AuthenticationException;
+import org.apache.shiro.authc.AuthenticationInfo;
+import org.apache.shiro.authc.AuthenticationToken;
+import org.apache.shiro.authc.UsernamePasswordToken;
+import org.apache.shiro.realm.jdbc.JdbcRealm;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import sun.reflect.generics.reflectiveObjects.NotImplementedException;
+
+import javax.sql.DataSource;
+
+/**
+ * The JDBC user store implementation.
+ */
+public class JDBCUserStore extends AbstractJDBCUserStore {
+
+    protected static Logger log = LoggerFactory.getLogger(JDBCUserStore.class);
+
+    private JdbcRealm jdbcRealm;
+
+    public JDBCUserStore() {
+        jdbcRealm = new JdbcRealm();
+    }
+
+    @Override
+    public boolean authenticate(String userName, Object credentials) throws UserStoreException{
+        AuthenticationToken authenticationToken = new UsernamePasswordToken(userName, (String)credentials);
+
+        AuthenticationInfo authenticationInfo;
+        try {
+            authenticationInfo = jdbcRealm.getAuthenticationInfo(authenticationToken);
+        } catch (AuthenticationException e) {
+            log.warn(e.getLocalizedMessage(), e);
+            return false;
+        }
+
+        return authenticationInfo != null;
+    }
+
+    @Override
+    public boolean authenticate(Object credentials) throws UserStoreException{
+        log.error("JDBC user store only supports user name, password based authentication.");
+        throw new NotImplementedException();
+    }
+
+    @Override
+    public void configure(Node node) throws UserStoreException {
+
+        super.configure(node);
+
+        /**
+         <specificConfigurations>
+         <database>
+         <jdbcUrl></jdbcUrl>
+         <databaseDriver></databaseDriver>
+         <userName></userName>
+         <password></password>
+         <userTableName></userTableName>
+         <userNameColumnName></userNameColumnName>
+         <passwordColumnName></passwordColumnName>
+         </database>
+         </specificConfigurations>
+         */
+
+        NodeList databaseNodeList = node.getChildNodes();
+
+        Node databaseNode = null;
+
+        for (int k = 0; k < databaseNodeList.getLength(); ++k) {
+
+            Node n = databaseNodeList.item(k);
+
+            if (n != null && n.getNodeType() == Node.ELEMENT_NODE) {
+                databaseNode = n;
+            }
+        }
+
+        String userTable = null;
+        String userNameColumn = null;
+        String passwordColumn = null;
+
+        if (databaseNode != null) {
+            NodeList nodeList = databaseNode.getChildNodes();
+
+            for (int i = 0; i < nodeList.getLength(); ++i) {
+                Node n = nodeList.item(i);
+
+                if (n.getNodeType() == Node.ELEMENT_NODE) {
+
+                    Element element = (Element) n;
+
+                    if (element.getNodeName().equals("userTableName")) {
+                        userTable = element.getFirstChild().getNodeValue();
+                    } else if (element.getNodeName().equals("userNameColumnName")) {
+                        userNameColumn = element.getFirstChild().getNodeValue();
+                    } else if (element.getNodeName().equals("passwordColumnName")) {
+                        passwordColumn = element.getFirstChild().getNodeValue();
+                    }
+                }
+            }
+        }
+
+        initializeDatabaseLookup(passwordColumn, userTable, userNameColumn);
+
+        StringBuilder stringBuilder = new StringBuilder("Configuring DB parameters for authenticator with User name Table - ");
+        stringBuilder.append(userTable).append(" User name column - ").append(userNameColumn).append(" Password column - ").
+                append(passwordColumn);
+
+        log.info(stringBuilder.toString());
+    }
+
+    protected void initializeDatabaseLookup(String passwordColumn, String userTable,
+                                            String userNameColumn) {
+
+        DBLookup dbLookup = new DBLookup(getDatabaseURL(), getDatabaseUserName(), getDatabasePassword(),
+                getDatabaseDriver());
+        DataSource dataSource = dbLookup.getDataSource();
+        jdbcRealm.setDataSource(dataSource);
+
+        StringBuilder stringBuilder = new StringBuilder();
+
+        stringBuilder.append("SELECT ").append(passwordColumn).append(" FROM ").append(userTable)
+                .append(" WHERE ").append(userNameColumn).append(" = ?");
+
+        jdbcRealm.setAuthenticationQuery(stringBuilder.toString());
+    }
+}

Added: airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/userstore/LDAPUserStore.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/userstore/LDAPUserStore.java?rev=1389558&view=auto
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/userstore/LDAPUserStore.java (added)
+++ airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/userstore/LDAPUserStore.java Mon Sep 24 20:25:54 2012
@@ -0,0 +1,148 @@
+/*
+ *
+ *  *
+ *  * Licensed to the Apache Software Foundation (ASF) under one
+ *  * or more contributor license agreements.  See the NOTICE file
+ *  * distributed with this work for additional information
+ *  * regarding copyright ownership.  The ASF licenses this file
+ *  * to you under the Apache License, Version 2.0 (the
+ *  * "License"); you may not use this file except in compliance
+ *  * with the License.  You may obtain a copy of the License at
+ *  *
+ *  *   http://www.apache.org/licenses/LICENSE-2.0
+ *  *
+ *  * 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.apache.airavata.security.userstore;
+
+import org.apache.airavata.security.UserStore;
+import org.apache.airavata.security.UserStoreException;
+import org.apache.shiro.authc.AuthenticationException;
+import org.apache.shiro.authc.AuthenticationInfo;
+import org.apache.shiro.authc.AuthenticationToken;
+import org.apache.shiro.authc.UsernamePasswordToken;
+import org.apache.shiro.realm.ldap.JndiLdapContextFactory;
+import org.apache.shiro.realm.ldap.JndiLdapRealm;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import sun.reflect.generics.reflectiveObjects.NotImplementedException;
+
+/**
+ * A user store which talks to LDAP server. User credentials and user information
+ * are stored in a LDAP server.
+ */
+public class LDAPUserStore implements UserStore {
+
+    private JndiLdapRealm ldapRealm;
+
+    protected static Logger log = LoggerFactory.getLogger(LDAPUserStore.class);
+
+    public boolean authenticate(String userName, Object credentials) throws UserStoreException {
+
+        AuthenticationToken authenticationToken = new UsernamePasswordToken(userName, (String)credentials);
+
+        AuthenticationInfo authenticationInfo;
+        try {
+            authenticationInfo = ldapRealm.getAuthenticationInfo(authenticationToken);
+        } catch (AuthenticationException e) {
+            log.warn(e.getLocalizedMessage(), e);
+            return false;
+        }
+
+        return authenticationInfo != null;
+
+    }
+
+    @Override
+    public boolean authenticate(Object credentials) throws UserStoreException {
+        log.error("LDAP user store only supports authenticating with user name and password.");
+        throw new NotImplementedException();
+    }
+
+    public void configure(Node specificConfigurationNode) throws UserStoreException{
+
+        /**
+         * <specificConfiguration>
+         * <ldap>
+         * <url>ldap://localhost:10389</url>
+         * <systemUser>admin</systemUser>
+         * <systemUserPassword>secret</systemUserPassword>
+         * <userDNTemplate>uid={0},ou=system</userDNTemplate>
+         * </ldap>
+         * </specificConfiguration>
+         */
+
+        Node configurationNode = null;
+        if (specificConfigurationNode != null) {
+            NodeList nodeList = specificConfigurationNode.getChildNodes();
+
+            for (int i=0; i < nodeList.getLength(); ++i) {
+                Node n = nodeList.item(i);
+                if (n.getNodeType() == Node.ELEMENT_NODE) {
+                    configurationNode = n;
+                }
+            }
+        }
+
+        String url = null;
+        String systemUser = null;
+        String systemUserPassword = null;
+        String userTemplate = null;
+
+        if (configurationNode != null) {
+            NodeList nodeList = configurationNode.getChildNodes();
+
+            for (int i = 0; i < nodeList.getLength(); ++i) {
+                Node n = nodeList.item(i);
+
+                if (n.getNodeType() == Node.ELEMENT_NODE) {
+
+                    Element element = (Element) n;
+
+                    if (element.getNodeName().equals("url")) {
+                        url = element.getFirstChild().getNodeValue();
+                    } else if (element.getNodeName().equals("systemUser")) {
+                        systemUser = element.getFirstChild().getNodeValue();
+                    } else if (element.getNodeName().equals("systemUserPassword")) {
+                        systemUserPassword = element.getFirstChild().getNodeValue();
+                    } else if (element.getNodeName().equals("userDNTemplate")) {
+                        userTemplate = element.getFirstChild().getNodeValue();
+                    }
+                }
+            }
+        }
+
+        initializeLDAP(url, systemUser, systemUserPassword, userTemplate);
+
+    }
+
+    protected void initializeLDAP(String ldapUrl, String systemUser, String systemUserPassword,
+                                  String userNameTemplate) {
+
+        JndiLdapContextFactory jndiLdapContextFactory = new JndiLdapContextFactory();
+
+        jndiLdapContextFactory.setUrl(ldapUrl);
+        jndiLdapContextFactory.setSystemUsername(systemUser);
+        jndiLdapContextFactory.setSystemPassword(systemUserPassword);
+
+        ldapRealm = new JndiLdapRealm();
+
+        ldapRealm.setContextFactory(jndiLdapContextFactory);
+        ldapRealm.setUserDnTemplate(userNameTemplate);
+
+
+        ldapRealm.init();
+
+    }
+}