Added: 
airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/userstore/SessionDBUserStore.java
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/userstore/SessionDBUserStore.java?rev=1389558&view=auto
==============================================================================
--- 
airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/userstore/SessionDBUserStore.java
 (added)
+++ 
airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/userstore/SessionDBUserStore.java
 Mon Sep 24 20:25:54 2012
@@ -0,0 +1,141 @@
+/*
+ *
+ *  *
+ *  * 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.UserStoreException;
+import org.apache.airavata.security.util.DBLookup;
+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 java.sql.SQLException;
+
+/**
+ * User store which works on sessions. Will talk to database to check
+ * whether session ids are stored in the database.
+ */
+public class SessionDBUserStore extends AbstractJDBCUserStore {
+
+    private String sessionTable;
+    private String sessionColumn;
+    private String comparingColumn;
+
+    protected DBLookup dbLookup;
+
+    protected static Logger log = 
LoggerFactory.getLogger(SessionDBUserStore.class);
+
+
+    @Override
+    public boolean authenticate(String userName, Object credentials) throws 
UserStoreException {
+        // This user store only supports session tokens.
+        throw new NotImplementedException();
+    }
+
+    @Override
+    public boolean authenticate(Object credentials) throws UserStoreException {
+
+        String sessionTicket = (String)credentials;
+
+        try {
+            String sessionString = 
dbLookup.getMatchingColumnValue(sessionTable, sessionColumn, sessionTicket);
+            return (sessionString != null);
+        } catch (SQLException e) {
+            throw new UserStoreException("Error querying database for session 
information.", e);
+        }
+    }
+
+    @Override
+    public void configure(Node node) throws UserStoreException {
+
+        super.configure(node);
+        /**
+         <specificConfigurations>
+         <sessionTable>
+         </sessionTable>
+         <sessionColumn></sessionColumn>
+         <comparingColumn></comparingColumn>
+         </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);
+        }
+    }
+}

Added: 
airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/util/DBLookup.java
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/util/DBLookup.java?rev=1389558&view=auto
==============================================================================
--- 
airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/util/DBLookup.java
 (added)
+++ 
airavata/sandbox/airavata-rest-security/modules/security/src/main/java/org/apache/airavata/security/util/DBLookup.java
 Mon Sep 24 20:25:54 2012
@@ -0,0 +1,108 @@
+package org.apache.airavata.security.util;
+
+import org.apache.commons.dbcp.BasicDataSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.sql.DataSource;
+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();
+    }
+
+    public DataSource getDataSource() {
+        BasicDataSource ds = new BasicDataSource();
+        ds.setDriverClassName(this.driverName);
+        ds.setUsername(this.databaseUserName);
+        ds.setPassword(this.databasePassword);
+        ds.setUrl(this.jdbcUrl);
+
+        return ds;
+    }
+
+    public Connection getConnection() throws SQLException {
+        return DriverManager.getConnection(jdbcUrl, properties);
+    }
+
+}

Modified: 
airavata/sandbox/airavata-rest-security/modules/security/src/test/java/org/apache/airavata/security/configurations/AuthenticatorConfigurationReaderTest.java
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/src/test/java/org/apache/airavata/security/configurations/AuthenticatorConfigurationReaderTest.java?rev=1389558&r1=1389557&r2=1389558&view=diff
==============================================================================
--- 
airavata/sandbox/airavata-rest-security/modules/security/src/test/java/org/apache/airavata/security/configurations/AuthenticatorConfigurationReaderTest.java
 (original)
+++ 
airavata/sandbox/airavata-rest-security/modules/security/src/test/java/org/apache/airavata/security/configurations/AuthenticatorConfigurationReaderTest.java
 Mon Sep 24 20:25:54 2012
@@ -2,6 +2,8 @@ package org.apache.airavata.security.con
 
 import junit.framework.TestCase;
 import org.apache.airavata.security.Authenticator;
+import org.apache.airavata.security.userstore.JDBCUserStore;
+import org.apache.airavata.security.userstore.LDAPUserStore;
 
 import java.io.File;
 import java.util.List;
@@ -46,6 +48,8 @@ public class AuthenticatorConfigurationR
                 assertEquals("org.myqsql.Driver1", ((TestDBAuthenticator1) 
authenticator).getDatabaseDriver());
                 assertEquals("mysql1", ((TestDBAuthenticator1) 
authenticator).getDatabaseUserName());
                 assertEquals("secret1", ((TestDBAuthenticator1) 
authenticator).getDatabasePassword());
+                assertNotNull(authenticator.getUserStore());
+                assertTrue(authenticator.getUserStore() instanceof 
JDBCUserStore);
             } else if (authenticator instanceof TestDBAuthenticator2) {
                 assertEquals("dbAuthenticator2", 
authenticator.getAuthenticatorName());
                 assertEquals(7, authenticator.getPriority());
@@ -54,6 +58,8 @@ public class AuthenticatorConfigurationR
                 assertEquals("org.myqsql.Driver2", ((TestDBAuthenticator2) 
authenticator).getDatabaseDriver());
                 assertEquals("mysql2", ((TestDBAuthenticator2) 
authenticator).getDatabaseUserName());
                 assertEquals("secret2", ((TestDBAuthenticator2) 
authenticator).getDatabasePassword());
+                assertNotNull(authenticator.getUserStore());
+                assertTrue(authenticator.getUserStore() instanceof 
LDAPUserStore);
             }  else if (authenticator instanceof TestDBAuthenticator3) {
                 assertEquals("dbAuthenticator3", 
authenticator.getAuthenticatorName());
                 assertEquals(8, authenticator.getPriority());
@@ -62,6 +68,8 @@ public class AuthenticatorConfigurationR
                 assertEquals("org.myqsql.Driver3", ((TestDBAuthenticator3) 
authenticator).getDatabaseDriver());
                 assertEquals("mysql3", ((TestDBAuthenticator3) 
authenticator).getDatabaseUserName());
                 assertEquals("secret3", ((TestDBAuthenticator3) 
authenticator).getDatabasePassword());
+                assertNotNull(authenticator.getUserStore());
+                assertTrue(authenticator.getUserStore() instanceof 
JDBCUserStore);
             }
         }
 

Added: 
airavata/sandbox/airavata-rest-security/modules/security/src/test/java/org/apache/airavata/security/configurations/TestUserStore.java
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/src/test/java/org/apache/airavata/security/configurations/TestUserStore.java?rev=1389558&view=auto
==============================================================================
--- 
airavata/sandbox/airavata-rest-security/modules/security/src/test/java/org/apache/airavata/security/configurations/TestUserStore.java
 (added)
+++ 
airavata/sandbox/airavata-rest-security/modules/security/src/test/java/org/apache/airavata/security/configurations/TestUserStore.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.configurations;
+
+import org.apache.airavata.security.UserStore;
+import org.w3c.dom.Node;
+
+/**
+ * Test user store class.
+ */
+public class TestUserStore implements UserStore {
+    @Override
+    public boolean authenticate(String userName, Object credentials) {
+        return false;  //To change body of implemented methods use File | 
Settings | File Templates.
+    }
+
+    @Override
+    public boolean authenticate(Object credentials) {
+        return false;  //To change body of implemented methods use File | 
Settings | File Templates.
+    }
+
+    @Override
+    public void configure(Node node) throws RuntimeException {
+        //To change body of implemented methods use File | Settings | File 
Templates.
+    }
+}

Added: 
airavata/sandbox/airavata-rest-security/modules/security/src/test/java/org/apache/airavata/security/userstore/JDBCUserStoreTest.java
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/src/test/java/org/apache/airavata/security/userstore/JDBCUserStoreTest.java?rev=1389558&view=auto
==============================================================================
--- 
airavata/sandbox/airavata-rest-security/modules/security/src/test/java/org/apache/airavata/security/userstore/JDBCUserStoreTest.java
 (added)
+++ 
airavata/sandbox/airavata-rest-security/modules/security/src/test/java/org/apache/airavata/security/userstore/JDBCUserStoreTest.java
 Mon Sep 24 20:25:54 2012
@@ -0,0 +1,77 @@
+/*
+ *
+ *  *
+ *  * 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 junit.framework.TestCase;
+import org.apache.airavata.security.Authenticator;
+import org.apache.airavata.security.UserStore;
+import 
org.apache.airavata.security.configurations.AuthenticatorConfigurationReader;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.File;
+import java.util.List;
+
+/**
+ * Test class for JDBC user store.
+ */
+public class JDBCUserStoreTest extends TestCase {
+
+    /**
+     * <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>
+     <userTableName>AIRAVATA_USER</userTableName>
+     <userNameColumnName>USERID</userNameColumnName>
+     <passwordColumnName>PASSWORD</passwordColumnName>
+     </database>
+     </specificConfigurations>
+     * @throws Exception
+     */
+
+
+
+    public void testAuthenticate() throws Exception {
+
+        DocumentBuilderFactory dbFactory = 
DocumentBuilderFactory.newInstance();
+        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
+        Document doc = 
dBuilder.parse(this.getClass().getClassLoader().getResourceAsStream("jdbc-authenticator.xml"));
+        doc.getDocumentElement().normalize();
+
+        NodeList configurations = 
doc.getElementsByTagName("specificConfigurations");
+        UserStore userStore = new JDBCUserStore();
+        userStore.configure(configurations.item(0));
+
+        assertTrue(userStore.authenticate("amilaj", "secret"));
+        assertFalse(userStore.authenticate("amilaj", "1secret"));
+        assertFalse(userStore.authenticate("lahiru", "1234"));
+
+    }
+}

Added: 
airavata/sandbox/airavata-rest-security/modules/security/src/test/java/org/apache/airavata/security/userstore/LDAPUserStoreTest.java
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/src/test/java/org/apache/airavata/security/userstore/LDAPUserStoreTest.java?rev=1389558&view=auto
==============================================================================
--- 
airavata/sandbox/airavata-rest-security/modules/security/src/test/java/org/apache/airavata/security/userstore/LDAPUserStoreTest.java
 (added)
+++ 
airavata/sandbox/airavata-rest-security/modules/security/src/test/java/org/apache/airavata/security/userstore/LDAPUserStoreTest.java
 Mon Sep 24 20:25:54 2012
@@ -0,0 +1,69 @@
+/*
+ *
+ *  *
+ *  * 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 junit.framework.TestCase;
+import org.apache.airavata.security.UserStore;
+import org.junit.Ignore;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+/**
+ * User store test 2
+ */
+@Ignore("Need LDAP server to run these tests")
+public class LDAPUserStoreTest extends TestCase{
+
+    private LDAPUserStore ldapUserStore;
+
+    public void setUp() {
+        ldapUserStore = new LDAPUserStore();
+
+        ldapUserStore.initializeLDAP("ldap://localhost:10389";, "admin", 
"secret", "uid={0},ou=system");
+    }
+
+    public void testAuthenticate() throws Exception {
+        assertTrue(ldapUserStore.authenticate("amilaj", "secret"));
+        assertFalse(ldapUserStore.authenticate("amilaj", "secret1"));
+    }
+
+    public void testConfigure() throws Exception {
+        DocumentBuilderFactory dbFactory = 
DocumentBuilderFactory.newInstance();
+        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
+        Document doc = 
dBuilder.parse(this.getClass().getClassLoader().getResourceAsStream("ldap-authenticator.xml"));
+        doc.getDocumentElement().normalize();
+
+        NodeList configurations = 
doc.getElementsByTagName("specificConfigurations");
+        UserStore userStore = new LDAPUserStore();
+        userStore.configure(configurations.item(0));
+
+        assertTrue(userStore.authenticate("amilaj", "secret"));
+    }
+
+
+
+}

Added: 
airavata/sandbox/airavata-rest-security/modules/security/src/test/java/org/apache/airavata/security/userstore/SessionDBUserStoreTest.java
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/src/test/java/org/apache/airavata/security/userstore/SessionDBUserStoreTest.java?rev=1389558&view=auto
==============================================================================
--- 
airavata/sandbox/airavata-rest-security/modules/security/src/test/java/org/apache/airavata/security/userstore/SessionDBUserStoreTest.java
 (added)
+++ 
airavata/sandbox/airavata-rest-security/modules/security/src/test/java/org/apache/airavata/security/userstore/SessionDBUserStoreTest.java
 Mon Sep 24 20:25:54 2012
@@ -0,0 +1,63 @@
+/*
+ *
+ *  *
+ *  * 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 junit.framework.TestCase;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.File;
+import java.io.InputStream;
+
+/**
+ * Test class for session DB authenticator.
+ */
+public class SessionDBUserStoreTest extends TestCase {
+
+    private SessionDBUserStore sessionDBUserStore = new SessionDBUserStore();
+
+    private InputStream configurationFileStream
+            = 
this.getClass().getClassLoader().getResourceAsStream("session-authenticator.xml");
+
+    public void setUp() throws Exception {
+        DocumentBuilderFactory dbFactory = 
DocumentBuilderFactory.newInstance();
+        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
+        Document doc = dBuilder.parse(configurationFileStream);
+        doc.getDocumentElement().normalize();
+
+        NodeList specificConfigurations = 
doc.getElementsByTagName("specificConfigurations");
+        sessionDBUserStore.configure(specificConfigurations.item(0));
+    }
+
+    public void testAuthenticate() throws Exception {
+        assertTrue(sessionDBUserStore.authenticate("1234"));
+
+    }
+
+    public void testAuthenticateFailure() throws Exception  {
+        assertFalse(sessionDBUserStore.authenticate("12345"));
+    }
+}

Modified: 
airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/authenticators.xml
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/authenticators.xml?rev=1389558&r1=1389557&r2=1389558&view=diff
==============================================================================
--- 
airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/authenticators.xml
 (original)
+++ 
airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/authenticators.xml
 Mon Sep 24 20:25:54 2012
@@ -8,7 +8,8 @@ Those configurations are reside inside &
 -->
 
 <authenticators>
-    <authenticator name="dbAuthenticator1" 
class="org.apache.airavata.security.configurations.TestDBAuthenticator1" 
enabled="true" priority="6">
+    <authenticator name="dbAuthenticator1" 
class="org.apache.airavata.security.configurations.TestDBAuthenticator1"
+                   enabled="true" priority="6" 
userstore="org.apache.airavata.security.userstore.JDBCUserStore">
         <specificConfigurations>
             <database>
                 <jdbcUrl>jdbc:sql:thin:@//myhost:1521/mysql1</jdbcUrl>
@@ -23,7 +24,8 @@ Those configurations are reside inside &
         </specificConfigurations>
     </authenticator>
 
-    <authenticator name="dbAuthenticator2" 
class="org.apache.airavata.security.configurations.TestDBAuthenticator2" 
enabled="true" priority="7">
+    <authenticator name="dbAuthenticator2" 
class="org.apache.airavata.security.configurations.TestDBAuthenticator2"
+                   enabled="true" priority="7" 
userstore="org.apache.airavata.security.userstore.LDAPUserStore">
         <specificConfigurations>
             <database>
                 <jdbcUrl>jdbc:sql:thin:@//myhost:1521/mysql2</jdbcUrl>
@@ -37,7 +39,8 @@ Those configurations are reside inside &
         </specificConfigurations>
     </authenticator>
 
-    <authenticator name="dbAuthenticator4" 
class="org.apache.airavata.security.configurations.TestDBAuthenticator2" 
enabled="false" priority="7">
+    <authenticator name="dbAuthenticator4" 
class="org.apache.airavata.security.configurations.TestDBAuthenticator2"
+                   enabled="false" priority="7" 
userstore="org.apache.airavata.security.userstore.JDBCUserStore">
         <specificConfigurations>
             <database>
                 <jdbcUrl>jdbc:sql:thin:@//myhost:1521/mysql2</jdbcUrl>
@@ -51,7 +54,8 @@ Those configurations are reside inside &
         </specificConfigurations>
     </authenticator>
 
-    <authenticator name="dbAuthenticator3" 
class="org.apache.airavata.security.configurations.TestDBAuthenticator3" 
enabled="true" priority="8">
+    <authenticator name="dbAuthenticator3" 
class="org.apache.airavata.security.configurations.TestDBAuthenticator3"
+                   enabled="true" priority="8" 
userstore="org.apache.airavata.security.userstore.JDBCUserStore">
         <specificConfigurations>
             <database>
                 <jdbcUrl>jdbc:sql:thin:@//myhost:1521/mysql3</jdbcUrl>

Added: 
airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/jdbc-authenticator.xml
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/jdbc-authenticator.xml?rev=1389558&view=auto
==============================================================================
--- 
airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/jdbc-authenticator.xml
 (added)
+++ 
airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/jdbc-authenticator.xml
 Mon Sep 24 20:25:54 2012
@@ -0,0 +1,39 @@
+<!--
+  ~ /*
+  ~  *
+  ~  * 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.
+  ~  *
+  ~  */
+  -->
+<authenticators>
+    <authenticator name="dbAuthenticator1" 
class="org.apache.airavata.security.configurations.TestDBAuthenticator1"
+                   enabled="true" priority="6" 
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>
+                <userTableName>AIRAVATA_USER</userTableName>
+                <userNameColumnName>USERID</userNameColumnName>
+                <passwordColumnName>PASSWORD</passwordColumnName>
+            </database>
+        </specificConfigurations>
+    </authenticator>
+</authenticators>

Added: 
airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/ldap-authenticator.xml
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/ldap-authenticator.xml?rev=1389558&view=auto
==============================================================================
--- 
airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/ldap-authenticator.xml
 (added)
+++ 
airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/ldap-authenticator.xml
 Mon Sep 24 20:25:54 2012
@@ -0,0 +1,41 @@
+<!--
+  ~ /*
+  ~  *
+  ~  * 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.
+  ~  *
+  ~  */
+  -->
+<authenticators>
+    <authenticator name="dbAuthenticator1" 
class="org.apache.airavata.security.configurations.TestDBAuthenticator1"
+                   enabled="true" priority="6" 
userstore="org.apache.airavata.security.userstore.JDBCUserStore">
+        <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=system</userDNTemplate>
+            </ldap>
+        </specificConfigurations>
+    </authenticator>
+</authenticators>

Added: 
airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/session-authenticator.xml
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/session-authenticator.xml?rev=1389558&view=auto
==============================================================================
--- 
airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/session-authenticator.xml
 (added)
+++ 
airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/session-authenticator.xml
 Mon Sep 24 20:25:54 2012
@@ -0,0 +1,44 @@
+<!--
+  ~ /*
+  ~  *
+  ~  * 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.
+  ~  *
+  ~  */
+  -->
+
+<authenticators>
+    <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-->
+                <!-- Points to 
/Users/thejaka/development/apache/airavata/trunk/modules/commons/airavata-registry-rest/target/tomcat6x/.
 -->
+                <jdbcUrl>jdbc:h2:../../src/test/resources/testdb/test</jdbcUrl>
+                
<!--jdbcUrl>jdbc:h2:modules/security/src/test/resources/testdb/test</jdbcUrl-->
+
+                <userName>sa</userName>
+                <password>sa</password>
+                <databaseDriver>org.h2.Driver</databaseDriver>
+                <sessionTable>Persons</sessionTable>
+                <sessionColumn>sessionId</sessionColumn>
+                <comparingColumn>sessionId</comparingColumn>
+            </database>
+        </specificConfigurations>
+    </authenticator>
+ </authenticators>
+

Added: 
airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/testdb/test.h2.db
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/testdb/test.h2.db?rev=1389558&view=auto
==============================================================================
Binary file - no diff available.

Propchange: 
airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/testdb/test.h2.db
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: 
airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/testdb/test.trace.db
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/testdb/test.trace.db?rev=1389558&view=auto
==============================================================================
--- 
airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/testdb/test.trace.db
 (added)
+++ 
airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/testdb/test.trace.db
 Mon Sep 24 20:25:54 2012
@@ -0,0 +1,53 @@
+09-10 15:20:58 jdbc[2]: exception
+org.h2.jdbc.JdbcSQLException: Column "1234" not found; SQL statement:
+SELECT sessionId FROM Persons WHERE sessionId = "1234" [42122-168]
+       at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
+       at org.h2.message.DbException.get(DbException.java:169)
+       at org.h2.message.DbException.get(DbException.java:146)
+       at 
org.h2.expression.ExpressionColumn.optimize(ExpressionColumn.java:138)
+       at org.h2.expression.Comparison.optimize(Comparison.java:161)
+       at org.h2.command.dml.Select.prepare(Select.java:802)
+       at org.h2.command.Parser.prepareCommand(Parser.java:218)
+       at org.h2.engine.Session.prepareLocal(Session.java:415)
+       at org.h2.engine.Session.prepareCommand(Session.java:364)
+       at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1109)
+       at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:164)
+       at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:152)
+       at org.h2.server.web.WebApp.getResult(WebApp.java:1311)
+       at org.h2.server.web.WebApp.query(WebApp.java:1001)
+       at org.h2.server.web.WebApp$1.next(WebApp.java:964)
+       at org.h2.server.web.WebApp$1.next(WebApp.java:967)
+       at org.h2.server.web.WebThread.process(WebThread.java:166)
+       at org.h2.server.web.WebThread.run(WebThread.java:93)
+       at java.lang.Thread.run(Thread.java:680)
+09-10 15:22:14 jdbc[2]: exception
+org.h2.jdbc.JdbcSQLException: Column "1234" not found; SQL statement:
+SELECT sessionID  FROM Persons where sessionid="1234" [42122-168]
+       at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
+       at org.h2.message.DbException.get(DbException.java:169)
+       at org.h2.message.DbException.get(DbException.java:146)
+       at 
org.h2.expression.ExpressionColumn.optimize(ExpressionColumn.java:138)
+       at org.h2.expression.Comparison.optimize(Comparison.java:161)
+       at org.h2.command.dml.Select.prepare(Select.java:802)
+       at org.h2.command.Parser.prepareCommand(Parser.java:218)
+       at org.h2.engine.Session.prepareLocal(Session.java:415)
+       at org.h2.engine.Session.prepareCommand(Session.java:364)
+       at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1109)
+       at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:164)
+       at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:152)
+       at org.h2.server.web.WebApp.getResult(WebApp.java:1311)
+       at org.h2.server.web.WebApp.query(WebApp.java:1001)
+       at org.h2.server.web.WebApp$1.next(WebApp.java:964)
+       at org.h2.server.web.WebApp$1.next(WebApp.java:967)
+       at org.h2.server.web.WebThread.process(WebThread.java:166)
+       at org.h2.server.web.WebThread.run(WebThread.java:93)
+       at java.lang.Thread.run(Thread.java:680)
+09-11 14:46:11 jdbc[2]: exception
+org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "INSERT INTO 
AIRAVATA_USER (LASTNAME, FIRSTNAME , USERID , PASSWORD ) VALUE[*] 
('Jayasekara', 'Amila', 'amilaj', 'secret') "; expected "DIRECT, SORTED, 
DEFAULT, VALUES, SET, (, SELECT, FROM"; SQL statement:
+insert into airavata_user (LastName, firstname , userid , password ) value 
('Jayasekara', 'Amila', 'amilaj', 'secret') [42001-168]
+09-11 14:46:44 jdbc[2]: exception
+org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "INSERT INTO 
AIRAVATA_USER (LASTNAME, FIRSTNAME , USERID , PASSWORD ) VALUE[*] 
('Jayasekara', 'Amila', 'amilaj', 'secret') "; expected "DIRECT, SORTED, 
DEFAULT, VALUES, SET, (, SELECT, FROM"; SQL statement:
+insert into airavata_user (LastName, firstname , userid , password ) value 
('Jayasekara', 'Amila', 'amilaj', 'secret') [42001-168]
+09-11 14:46:48 jdbc[2]: exception
+org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "INSERT INTO 
AIRAVATA_USER (LASTNAME, FIRSTNAME , USERID , PASSWORD ) VALUE[*] 
('Jayasekara', 'Amila', 'amilaj', 'secret') "; expected "DIRECT, SORTED, 
DEFAULT, VALUES, SET, (, SELECT, FROM"; SQL statement:
+insert into airavata_user (LastName, firstname , userid , password ) value 
('Jayasekara', 'Amila', 'amilaj', 'secret') [42001-168]

Added: 
airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/testdb/test/test.trace.db
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/testdb/test/test.trace.db?rev=1389558&view=auto
==============================================================================
--- 
airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/testdb/test/test.trace.db
 (added)
+++ 
airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/testdb/test/test.trace.db
 Mon Sep 24 20:25:54 2012
@@ -0,0 +1,6 @@
+09-04 16:20:30 jdbc[2]: exception
+org.h2.jdbc.JdbcSQLException: Table "TABLE" not found; SQL statement:
+delete table session [42102-168]
+09-04 16:20:40 jdbc[2]: exception
+org.h2.jdbc.JdbcSQLException: Table "TABLE" not found; SQL statement:
+delete table session [42102-168]

Modified: airavata/sandbox/airavata-rest-security/pom.xml
URL: 
http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/pom.xml?rev=1389558&r1=1389557&r2=1389558&view=diff
==============================================================================
--- airavata/sandbox/airavata-rest-security/pom.xml (original)
+++ airavata/sandbox/airavata-rest-security/pom.xml Mon Sep 24 20:25:54 2012
@@ -1,12 +1,27 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
-<!--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. -->
+<!--
+  ~ /*
+  ~  *
+  ~  * 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.
+  ~  *
+  ~  */
+  -->
 
 <project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
 


Reply via email to