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/10/30 19:52:29 UTC
svn commit: r1403813 [2/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/resources/
modules/commons/airavata-reg...
Added: airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/impl/db/CommunityUserDAO.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/impl/db/CommunityUserDAO.java?rev=1403813&view=auto
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/impl/db/CommunityUserDAO.java (added)
+++ airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/impl/db/CommunityUserDAO.java Tue Oct 30 18:52:27 2012
@@ -0,0 +1,173 @@
+package org.apache.airavata.credential.store.impl.db;
+
+import org.apache.airavata.credential.store.CommunityUser;
+import org.apache.airavata.credential.store.CredentialStoreException;
+import org.apache.airavata.credential.store.util.DBUtil;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Data access class for community_user table.
+ */
+public class CommunityUserDAO extends ParentDAO {
+
+ public CommunityUserDAO(DBUtil dbUtil) {
+ super(dbUtil);
+ }
+
+ public void addCommunityUser(CommunityUser user) throws CredentialStoreException {
+
+ String sql = "insert into community_user values (?, ?, ?)";
+
+ Connection connection = null;
+ PreparedStatement preparedStatement = null;
+
+ try {
+ connection = dbUtil.getConnection();
+ preparedStatement = connection.prepareStatement(sql);
+
+ preparedStatement.setString(1, user.getGatewayName());
+ preparedStatement.setString(2, user.getUserName());
+ preparedStatement.setString(3, user.getUserEmail());
+
+ preparedStatement.executeUpdate();
+
+ connection.commit();
+
+ } catch (SQLException e) {
+ StringBuilder stringBuilder = new StringBuilder("Error persisting community user.");
+ stringBuilder.append("gateway - ").append(user.getGatewayName());
+ stringBuilder.append("community user name - ").append(user.getUserName());
+ stringBuilder.append("community user email - ").append(user.getUserEmail());
+
+ log.error(stringBuilder.toString(), e);
+
+ throw new CredentialStoreException(stringBuilder.toString(), e);
+ } finally {
+
+ dbUtil.cleanup(preparedStatement, connection);
+ }
+ }
+
+
+ public void deleteCommunityUser(CommunityUser user) throws CredentialStoreException {
+
+ String sql = "delete from community_user where gateway_name=? and community_user_name=?;";
+
+ Connection connection = null;
+ PreparedStatement preparedStatement = null;
+
+ try {
+ connection = dbUtil.getConnection();
+ preparedStatement = connection.prepareStatement(sql);
+
+ preparedStatement.setString(1, user.getGatewayName());
+ preparedStatement.setString(2, user.getUserName());
+
+ preparedStatement.executeUpdate();
+
+ connection.commit();
+
+ } catch (SQLException e) {
+ StringBuilder stringBuilder = new StringBuilder("Error deleting community user.");
+ stringBuilder.append("gateway - ").append(user.getGatewayName());
+ stringBuilder.append("community user name - ").append(user.getUserName());
+
+ log.error(stringBuilder.toString(), e);
+
+ throw new CredentialStoreException(stringBuilder.toString(), e);
+ } finally {
+ dbUtil.cleanup(preparedStatement, connection);
+ }
+ }
+
+ public void updateCommunityUser(CommunityUser user) throws CredentialStoreException {
+
+ //TODO
+ }
+
+ public CommunityUser getCommunityUser(String gatewayName, String communityUserName) throws CredentialStoreException{
+
+ String sql = "select * from community_user where gateway_name=? and community_user_name=?;";
+
+ Connection connection = null;
+ PreparedStatement preparedStatement = null;
+
+ try {
+ connection = dbUtil.getConnection();
+ preparedStatement = connection.prepareStatement(sql);
+
+ preparedStatement.setString(1, gatewayName);
+ preparedStatement.setString(2, communityUserName);
+
+ ResultSet resultSet = preparedStatement.executeQuery();
+
+ if (resultSet.next()) {
+ String email = resultSet.getString("COMMUNITY_USER_EMAIL"); //TODO fix typo
+
+ return new CommunityUser(gatewayName, communityUserName, email);
+
+ }
+
+ } catch (SQLException e) {
+ StringBuilder stringBuilder = new StringBuilder("Error retrieving community user.");
+ stringBuilder.append("gateway - ").append(gatewayName);
+ stringBuilder.append("community user name - ").append(communityUserName);
+
+ log.error(stringBuilder.toString(), e);
+
+ throw new CredentialStoreException(stringBuilder.toString(), e);
+ } finally {
+ dbUtil.cleanup(preparedStatement, connection);
+ }
+
+ return null;
+ }
+
+ public List<CommunityUser> getCommunityUsers(String gatewayName)
+ throws CredentialStoreException{
+
+ List<CommunityUser> userList = new ArrayList<CommunityUser>();
+
+ String sql = "select * from community_user where gateway_name=?";
+
+ Connection connection = null;
+ PreparedStatement preparedStatement = null;
+
+ try {
+ connection = dbUtil.getConnection();
+ preparedStatement = connection.prepareStatement(sql);
+
+ preparedStatement.setString(1, gatewayName);
+
+ ResultSet resultSet = preparedStatement.executeQuery();
+
+ while (resultSet.next()) {
+ String userName = resultSet.getString("COMMUNITY_USER_NAME");
+ String email = resultSet.getString("COMMUNITY_USER_EMAIL"); //TODO fix typo
+
+ userList.add(new CommunityUser(gatewayName, userName, email));
+
+ }
+
+ } catch (SQLException e) {
+ StringBuilder stringBuilder = new StringBuilder("Error retrieving community users for ");
+ stringBuilder.append("gateway - ").append(gatewayName);
+
+ log.error(stringBuilder.toString(), e);
+
+ throw new CredentialStoreException(stringBuilder.toString(), e);
+ } finally {
+ dbUtil.cleanup(preparedStatement, connection);
+ }
+
+ return userList;
+ }
+
+
+}
Added: airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/impl/db/CredentialsDAO.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/impl/db/CredentialsDAO.java?rev=1403813&view=auto
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/impl/db/CredentialsDAO.java (added)
+++ airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/impl/db/CredentialsDAO.java Tue Oct 30 18:52:27 2012
@@ -0,0 +1,239 @@
+package org.apache.airavata.credential.store.impl.db;
+
+import org.apache.airavata.credential.store.CommunityUser;
+import org.apache.airavata.credential.store.CredentialStoreException;
+import org.apache.airavata.credential.store.CertificateCredential;
+import org.apache.airavata.credential.store.util.DBUtil;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Data access class for credential store.
+ */
+public class CredentialsDAO extends ParentDAO {
+
+ public CredentialsDAO(DBUtil dbUtil) {
+ super(dbUtil);
+ }
+
+ public void addCredentials(CertificateCredential certificateCredential) throws CredentialStoreException {
+
+ String sql = "insert into credentials values (?, ?, ?, ?, ?, ?, ?, ?, CURDATE())";
+ //TODO By any chance will we use some other database other than MySQL ?
+
+ Connection connection = null;
+ PreparedStatement preparedStatement = null;
+
+ try {
+ connection = dbUtil.getConnection();
+ preparedStatement = connection.prepareStatement(sql);
+
+ preparedStatement.setString(1, certificateCredential.getCommunityUser().getGatewayName());
+ preparedStatement.setString(2, certificateCredential.getCommunityUser().getUserName());
+ preparedStatement.setString(3, certificateCredential.getCertificate());
+ preparedStatement.setString(4, certificateCredential.getPrivateKey());
+ preparedStatement.setString(5, certificateCredential.getNotBefore());
+ preparedStatement.setString(6, certificateCredential.getNotAfter());
+ preparedStatement.setLong(7, certificateCredential.getLifeTime());
+ preparedStatement.setString(8, certificateCredential.getPortalUserName());
+
+
+ preparedStatement.executeUpdate();
+
+ connection.commit();
+
+ } catch (SQLException e) {
+ StringBuilder stringBuilder = new StringBuilder("Error persisting community credentials.");
+ stringBuilder.append(" gateway - ").append(certificateCredential.getCommunityUser().getGatewayName());
+ stringBuilder.append(" community user name - ").append(certificateCredential.
+ getCommunityUser().getUserName());
+ stringBuilder.append(" life time - ").append(certificateCredential.getLifeTime());
+
+ log.error(stringBuilder.toString(), e);
+
+ throw new CredentialStoreException(stringBuilder.toString(), e);
+ } finally {
+
+ dbUtil.cleanup(preparedStatement, connection);
+ }
+ }
+
+
+ public void deleteCredentials(String gatewayName, String communityUserName) throws CredentialStoreException {
+
+ String sql = "delete from credentials where gateway_name=? and community_user_name=?;";
+
+ Connection connection = null;
+ PreparedStatement preparedStatement = null;
+
+ try {
+ connection = dbUtil.getConnection();
+ preparedStatement = connection.prepareStatement(sql);
+
+ preparedStatement.setString(1, gatewayName);
+ preparedStatement.setString(2, communityUserName);
+
+ preparedStatement.executeUpdate();
+
+ connection.commit();
+
+ } catch (SQLException e) {
+ StringBuilder stringBuilder = new StringBuilder("Error deleting credentials for .");
+ stringBuilder.append("gateway - ").append(gatewayName);
+ stringBuilder.append("community user name - ").append(communityUserName);
+
+ log.error(stringBuilder.toString(), e);
+
+ throw new CredentialStoreException(stringBuilder.toString(), e);
+ } finally {
+ dbUtil.cleanup(preparedStatement, connection);
+ }
+ }
+
+ public void updateCredentials(CertificateCredential certificateCredential) throws CredentialStoreException {
+
+ String sql = "update credentials set credential = ?, private_key = ?, lifetime = ?, " +
+ "requesting_portal_user_name = ?, " + "not_before = ?," + "not_after = ?," +
+ "requested_time = CURDATE() where gateway_name = ? and community_user_name = ?";
+ //TODO By any chance will we use some other database other than MySQL ?
+
+ Connection connection = null;
+ PreparedStatement preparedStatement = null;
+
+ try {
+ connection = dbUtil.getConnection();
+ preparedStatement = connection.prepareStatement(sql);
+
+ preparedStatement.setString(1, certificateCredential.getCertificate());
+ preparedStatement.setString(2, certificateCredential.getPrivateKey());
+ preparedStatement.setLong(3, certificateCredential.getLifeTime());
+ preparedStatement.setString(4, certificateCredential.getPortalUserName());
+ preparedStatement.setString(5, certificateCredential.getNotBefore());
+ preparedStatement.setString(6, certificateCredential.getNotAfter());
+ preparedStatement.setString(7, certificateCredential.getCommunityUser().getGatewayName());
+ preparedStatement.setString(8, certificateCredential.getCommunityUser().getUserName());
+
+
+ preparedStatement.executeUpdate();
+
+ connection.commit();
+
+ } catch (SQLException e) {
+ StringBuilder stringBuilder = new StringBuilder("Error updating credentials.");
+ stringBuilder.append(" gateway - ").append(certificateCredential.getCommunityUser().getGatewayName());
+ stringBuilder.append(" community user name - ").append(certificateCredential.
+ getCommunityUser().getUserName());
+ stringBuilder.append(" life time - ").append(certificateCredential.getLifeTime());
+
+ log.error(stringBuilder.toString(), e);
+
+ throw new CredentialStoreException(stringBuilder.toString(), e);
+ } finally {
+
+ dbUtil.cleanup(preparedStatement, connection);
+ }
+
+ }
+
+ public CertificateCredential getCredential(String gatewayName, String communityUserName)
+ throws CredentialStoreException {
+
+ String sql = "select * from credentials where gateway_name=? and community_user_name=?;";
+
+ Connection connection = null;
+ PreparedStatement preparedStatement = null;
+
+ try {
+ connection = dbUtil.getConnection();
+ preparedStatement = connection.prepareStatement(sql);
+
+ preparedStatement.setString(1, gatewayName);
+ preparedStatement.setString(2, communityUserName);
+
+ ResultSet resultSet = preparedStatement.executeQuery();
+
+
+ if (resultSet.next()) {
+ CertificateCredential certificateCredential = new CertificateCredential();
+
+ certificateCredential.setCertificate(resultSet.getString("CREDENTIAL"));
+ certificateCredential.setPrivateKey(resultSet.getString("PRIVATE_KEY"));
+ certificateCredential.setLifeTime(resultSet.getLong("LIFETIME"));
+ certificateCredential.setCommunityUser(new CommunityUser(gatewayName, communityUserName, null));
+ certificateCredential.setPortalUserName(resultSet.getString("REQUESTING_PORTAL_USER_NAME"));
+ certificateCredential.setCertificateRequestedTime(resultSet.getTimestamp("REQUESTED_TIME"));
+
+ return certificateCredential;
+ }
+
+ } catch (SQLException e) {
+ StringBuilder stringBuilder = new StringBuilder("Error retrieving credentials for community user.");
+ stringBuilder.append("gateway - ").append(gatewayName);
+ stringBuilder.append("community user name - ").append(communityUserName);
+
+ log.error(stringBuilder.toString(), e);
+
+ throw new CredentialStoreException(stringBuilder.toString(), e);
+ } finally {
+ dbUtil.cleanup(preparedStatement, connection);
+ }
+
+ return null;
+ }
+
+ public List<CertificateCredential> getCredentials(String gatewayName)
+ throws CredentialStoreException {
+
+ List<CertificateCredential> credentialList = new ArrayList<CertificateCredential>();
+
+ String sql = "select * from credentials where gateway_name=?";
+
+ Connection connection = null;
+ PreparedStatement preparedStatement = null;
+
+ try {
+ connection = dbUtil.getConnection();
+ preparedStatement = connection.prepareStatement(sql);
+
+ preparedStatement.setString(1, gatewayName);
+
+ ResultSet resultSet = preparedStatement.executeQuery();
+
+ CertificateCredential certificateCredential;
+
+ while (resultSet.next()) {
+ certificateCredential = new CertificateCredential();
+
+ certificateCredential.setCommunityUser(new CommunityUser(gatewayName,
+ resultSet.getString("COMMUNITY_USER_NAME"), null));
+ certificateCredential.setCertificate(resultSet.getString("CREDENTIAL"));
+ certificateCredential.setPrivateKey(resultSet.getString("PRIVATE_KEY"));
+ certificateCredential.setNotBefore(resultSet.getString("NOT_BEFORE"));
+ certificateCredential.setNotBefore(resultSet.getString("NOT_AFTER"));
+ certificateCredential.setLifeTime(resultSet.getLong("LIFETIME"));
+ certificateCredential.setPortalUserName(resultSet.getString("REQUESTING_PORTAL_USER_NAME"));
+ certificateCredential.setCertificateRequestedTime(resultSet.getTimestamp("REQUESTED_TIME"));
+
+ credentialList.add(certificateCredential);
+ }
+
+ } catch (SQLException e) {
+ StringBuilder stringBuilder = new StringBuilder("Error retrieving credential list for ");
+ stringBuilder.append("gateway - ").append(gatewayName);
+
+ log.error(stringBuilder.toString(), e);
+
+ throw new CredentialStoreException(stringBuilder.toString(), e);
+ } finally {
+ dbUtil.cleanup(preparedStatement, connection);
+ }
+
+ return credentialList;
+ }
+
+}
Added: airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/impl/db/MappingDAO.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/impl/db/MappingDAO.java?rev=1403813&view=auto
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/impl/db/MappingDAO.java (added)
+++ airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/impl/db/MappingDAO.java Tue Oct 30 18:52:27 2012
@@ -0,0 +1,235 @@
+package org.apache.airavata.credential.store.impl.db;
+
+import org.apache.airavata.credential.store.CredentialStoreException;
+import org.apache.airavata.credential.store.Mapping;
+import org.apache.airavata.credential.store.util.DBUtil;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Data access class for Mapping table.
+ */
+public class MappingDAO extends ParentDAO {
+
+ public MappingDAO(DBUtil dbUtil) {
+ super(dbUtil);
+ }
+
+ public void addMapping (Mapping mapping) throws CredentialStoreException {
+
+ String sql = "insert into mapping values (?, ?, ?)";
+
+ Connection connection = null;
+ PreparedStatement preparedStatement = null;
+
+ try {
+ connection = dbUtil.getConnection();
+ preparedStatement = connection.prepareStatement(sql);
+
+ preparedStatement.setString(1, mapping.getGatewayName());
+ preparedStatement.setString(2, mapping.getCommunityUser());
+ preparedStatement.setString(3, mapping.getPortalUser());
+
+ preparedStatement.executeUpdate();
+
+ connection.commit();
+
+ } catch (SQLException e) {
+ StringBuilder stringBuilder = new StringBuilder("Error persisting community user.");
+ stringBuilder.append("gateway - ").append(mapping.getGatewayName());
+ stringBuilder.append("community user name - ").append(mapping.getCommunityUser());
+ stringBuilder.append("portal user name - ").append(mapping.getPortalUser());
+
+ log.error(stringBuilder.toString(), e);
+
+ throw new CredentialStoreException(stringBuilder.toString(), e);
+ } finally {
+ dbUtil.cleanup(preparedStatement, connection);
+ }
+ }
+
+
+ public void deleteGatewayMapping(String portalUser, String gatewayName) throws CredentialStoreException {
+
+ String sql = "delete from mapping where gateway_name=? and portal_user_name=?;";
+
+ Connection connection = null;
+ PreparedStatement preparedStatement = null;
+
+ try {
+ connection = dbUtil.getConnection();
+ preparedStatement = connection.prepareStatement(sql);
+
+ preparedStatement.setString(1, gatewayName);
+ preparedStatement.setString(2, portalUser);
+
+ preparedStatement.executeUpdate();
+
+ connection.commit();
+
+ } catch (SQLException e) {
+ StringBuilder stringBuilder = new StringBuilder("Error deleting mapping for portal user.");
+ stringBuilder.append("gateway - ").append(gatewayName);
+ stringBuilder.append("portal user name - ").append(portalUser);
+
+ log.error(stringBuilder.toString(), e);
+
+ throw new CredentialStoreException(stringBuilder.toString(), e);
+ } finally {
+ dbUtil.cleanup(preparedStatement, connection);
+ }
+ }
+
+ public void deleteGatewayCommunityAccountMappings(String communityUserName,
+ String gatewayName) throws CredentialStoreException {
+
+ String sql = "delete from mapping where gateway_name=? and community_user_name=?;";
+
+ Connection connection = null;
+ PreparedStatement preparedStatement = null;
+
+ try {
+ connection = dbUtil.getConnection();
+ preparedStatement = connection.prepareStatement(sql);
+
+ preparedStatement.setString(1, gatewayName);
+ preparedStatement.setString(2, communityUserName);
+
+ preparedStatement.executeUpdate();
+
+ connection.commit();
+
+ } catch (SQLException e) {
+ StringBuilder stringBuilder = new StringBuilder("Error deleting mapping for portal user.");
+ stringBuilder.append("gateway - ").append(gatewayName);
+ stringBuilder.append("community user name - ").append(communityUserName);
+
+ log.error(stringBuilder.toString(), e);
+
+ throw new CredentialStoreException(stringBuilder.toString(), e);
+ } finally {
+ dbUtil.cleanup(preparedStatement, connection);
+ }
+ }
+
+
+
+ public List<String> getMappingPortalUsers (String communityUserName, String gatewayName) throws
+ CredentialStoreException{
+
+ String sql = "select portal_user_name from mapping where gateway_name=? and community_user_name=?;";
+
+ List<String> portalUsers = new ArrayList<String>();
+
+ Connection connection = null;
+ PreparedStatement preparedStatement = null;
+
+ try {
+ connection = dbUtil.getConnection();
+ preparedStatement = connection.prepareStatement(sql);
+
+ preparedStatement.setString(1, gatewayName);
+ preparedStatement.setString(2, communityUserName);
+
+ ResultSet resultSet = preparedStatement.executeQuery();
+
+ while (resultSet.next()) {
+ portalUsers.add(resultSet.getString("portal_user_name"));
+ }
+
+ } catch (SQLException e) {
+ StringBuilder stringBuilder = new StringBuilder("Error retrieving mapping user.");
+ stringBuilder.append("gateway - ").append(gatewayName);
+ stringBuilder.append("community user name - ").append(communityUserName);
+
+ log.error(stringBuilder.toString(), e);
+
+ throw new CredentialStoreException(stringBuilder.toString(), e);
+ } finally {
+ dbUtil.cleanup(preparedStatement, connection);
+ }
+
+ return portalUsers;
+ }
+
+ public String getMappingCommunityUser (String portalUserName, String gatewayName) throws CredentialStoreException {
+
+ String sql = "select community_user_name from mapping where gateway_name=? and portal_user_name=?;";
+
+ Connection connection = null;
+ PreparedStatement preparedStatement = null;
+
+ try {
+ connection = dbUtil.getConnection();
+ preparedStatement = connection.prepareStatement(sql);
+
+ preparedStatement.setString(1, gatewayName);
+ preparedStatement.setString(2, portalUserName);
+
+ ResultSet resultSet = preparedStatement.executeQuery();
+
+ if (resultSet.next()) {
+ return resultSet.getString("community_user_name");
+ }
+
+ } catch (SQLException e) {
+ StringBuilder stringBuilder = new StringBuilder("Error retrieving mapping user.");
+ stringBuilder.append("gateway - ").append(gatewayName);
+ stringBuilder.append("portal user name - ").append(portalUserName);
+
+ log.error(stringBuilder.toString(), e);
+
+ throw new CredentialStoreException(stringBuilder.toString(), e);
+ } finally {
+ dbUtil.cleanup(preparedStatement, connection);
+ }
+
+ return null;
+
+ }
+
+ public String getCredentials(String portalUserName, String gatewayName) throws Exception {
+
+ String sql = "select credential from credentials where credentials.community_user_name in " +
+ "(select mapping.community_user_name from mapping where mapping.gateway_name = ?" +
+ "and mapping.portal_user_name = ?);";
+
+ Connection connection = null;
+ PreparedStatement preparedStatement = null;
+
+ try {
+ connection = dbUtil.getConnection();
+ preparedStatement = connection.prepareStatement(sql);
+
+ preparedStatement.setString(1, gatewayName);
+ preparedStatement.setString(2, portalUserName);
+
+ ResultSet resultSet = preparedStatement.executeQuery();
+
+ if (resultSet.next()) {
+ return resultSet.getString("credential");
+ }
+
+ } catch (SQLException e) {
+ StringBuilder stringBuilder = new StringBuilder("Error retrieving credentials for ");
+ stringBuilder.append("gateway - ").append(gatewayName);
+ stringBuilder.append("portal user name - ").append(portalUserName);
+
+ log.error(stringBuilder.toString(), e);
+
+ throw new CredentialStoreException(stringBuilder.toString(), e);
+ } finally {
+ dbUtil.cleanup(preparedStatement, connection);
+ }
+
+ return null;
+
+ }
+
+}
+
Added: airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/impl/db/ParentDAO.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/impl/db/ParentDAO.java?rev=1403813&view=auto
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/impl/db/ParentDAO.java (added)
+++ airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/impl/db/ParentDAO.java Tue Oct 30 18:52:27 2012
@@ -0,0 +1,19 @@
+package org.apache.airavata.credential.store.impl.db;
+
+import org.apache.airavata.credential.store.util.DBUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Super class to abstract out Data access classes.
+ */
+public class ParentDAO {
+ protected static Logger log = LoggerFactory.getLogger(CommunityUserDAO.class);
+
+ protected DBUtil dbUtil;
+
+ public ParentDAO(DBUtil dbUtil) {
+ this.dbUtil = dbUtil;
+ }
+
+}
Added: airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/servlet/CredentialBootstrapper.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/servlet/CredentialBootstrapper.java?rev=1403813&view=auto
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/servlet/CredentialBootstrapper.java (added)
+++ airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/servlet/CredentialBootstrapper.java Tue Oct 30 18:52:27 2012
@@ -0,0 +1,27 @@
+package org.apache.airavata.credential.store.servlet;
+
+import edu.uiuc.ncsa.myproxy.oa4mp.client.loader.ClientBootstrapper;
+import edu.uiuc.ncsa.security.core.util.ConfigurationLoader;
+
+import javax.servlet.ServletContext;
+import java.io.File;
+
+/**
+ * Bootstrapper class for credential-store.
+ */
+public class CredentialBootstrapper extends ClientBootstrapper {
+
+ public ConfigurationLoader getConfigurationLoader(ServletContext servletContext)
+ throws Exception {
+
+ File currentDirectory = new File(".");
+ System.out.println("Current directory is - " + currentDirectory.getAbsolutePath());
+
+
+ return super.getConfigurationLoader(servletContext);
+
+
+ }
+
+
+}
Added: airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/servlet/CredentialStoreCallbackServlet.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/servlet/CredentialStoreCallbackServlet.java?rev=1403813&view=auto
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/servlet/CredentialStoreCallbackServlet.java (added)
+++ airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/servlet/CredentialStoreCallbackServlet.java Tue Oct 30 18:52:27 2012
@@ -0,0 +1,146 @@
+package org.apache.airavata.credential.store.servlet;
+
+import edu.uiuc.ncsa.myproxy.oa4mp.client.AssetResponse;
+import edu.uiuc.ncsa.myproxy.oa4mp.client.ClientEnvironment;
+import edu.uiuc.ncsa.myproxy.oa4mp.client.OA4MPService;
+import edu.uiuc.ncsa.myproxy.oa4mp.client.servlet.ClientServlet;
+import edu.uiuc.ncsa.security.core.exceptions.GeneralException;
+import edu.uiuc.ncsa.security.servlet.JSPUtil;
+import edu.uiuc.ncsa.security.util.pkcs.CertUtil;
+import org.apache.airavata.credential.store.CertificateCredential;
+import org.apache.airavata.credential.store.CommunityUser;
+import org.apache.airavata.credential.store.impl.CertificateCredentialWriter;
+import org.apache.airavata.credential.store.util.DBUtil;
+import org.apache.airavata.credential.store.util.Utility;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.security.cert.X509Certificate;
+
+/**
+ * Callback from the portal will come here. In this class we will store incomming
+ * certificate to the database.
+ * Partly taken from OA4MP code base.
+ */
+public class CredentialStoreCallbackServlet extends ClientServlet {
+
+ private static final String ERROR_PAGE = "/credential-store/error.jsp";
+ private static final String SUCCESS_PAGE = "/credential-store/success.jsp";
+
+ private OA4MPService oa4mpService;
+
+ private CertificateCredentialWriter certificateCredentialWriter;
+
+ public void init() throws ServletException {
+
+ DBUtil dbUtil;
+
+ try {
+ dbUtil = DBUtil.getDBUtil(getServletContext());
+ } catch (Exception e) {
+ throw new ServletException("Error initializing database operations.", e);
+ }
+
+ super.init();
+ certificateCredentialWriter = new CertificateCredentialWriter(dbUtil);
+
+ info("Credential store callback initialized successfully.");
+ }
+
+ @Override
+ public OA4MPService getOA4MPService() {
+ return oa4mpService;
+ }
+
+ @Override
+ public void loadEnvironment() throws IOException {
+ environment = getConfigurationLoader().load();
+ oa4mpService = new CredentialStoreOA4MPServer((ClientEnvironment) environment);
+ }
+
+ @Override
+ protected void doIt(HttpServletRequest request, HttpServletResponse response) throws Throwable {
+
+ String gatewayName = request.getParameter("gatewayName");
+ String portalUserName = request.getParameter("portalUserName");
+ String durationParameter = request.getParameter("duration");
+ String contactEmail = request.getParameter("email");
+
+ //TODO remove hard coded values, once passing query parameters is
+ //fixed in OA4MP client api
+ long duration = 800;
+ contactEmail = "ogce@sciencegateway.org";
+
+ if (durationParameter != null) {
+ duration = Long.parseLong(durationParameter);
+ }
+
+
+ info("Gateway name " + gatewayName);
+ info("Portal user name " + portalUserName);
+ info("Community user contact email " + portalUserName);
+
+ //TODO remove later
+ gatewayName = "defaultGateway";
+ portalUserName = "defaultPortal";
+
+ info("2.a. Getting token and verifier.");
+ String token = request.getParameter(TOKEN_KEY);
+ String verifier = request.getParameter(VERIFIER_KEY);
+ if (token == null || verifier == null) {
+ warn("2.a. The token is " + (token == null ? "null" : token) + " and the verifier is " + (verifier == null ? "null" : verifier));
+ GeneralException ge = new GeneralException("Error: This servlet requires parameters for the token and verifier. It cannot be called directly.");
+ request.setAttribute("exception", ge);
+ JSPUtil.fwd(request, response, ERROR_PAGE);
+ return;
+ }
+ info("2.a Token and verifier found.");
+ X509Certificate cert = null;
+ AssetResponse assetResponse = null;
+
+ try {
+ info("2.a. Getting the cert(s) from the service");
+ assetResponse = getOA4MPService().getCert(token, verifier);
+ cert = assetResponse.getX509Certificates()[0];
+
+ // The work in this call
+ } catch (Throwable t) {
+ warn("2.a. Exception from the server: " + t.getCause().getMessage());
+ error("Exception while trying to get cert. message:" + t.getMessage());
+ request.setAttribute("exception", t);
+ JSPUtil.fwd(request, response, ERROR_PAGE);
+ return;
+ }
+ info("2.b. Done! Displaying success page.");
+
+ CertificateCredential certificateCredential = new CertificateCredential();
+
+ certificateCredential.setNotBefore(Utility.convertDateToString(cert.getNotBefore()));
+ certificateCredential.setNotAfter(Utility.convertDateToString(cert.getNotAfter()));
+ certificateCredential.setCertificate(CertUtil.toPEM(assetResponse.getX509Certificates()));
+ certificateCredential.setCommunityUser(new CommunityUser(gatewayName, assetResponse.getUsername(),
+ contactEmail));
+ certificateCredential.setPortalUserName(portalUserName);
+ certificateCredential.setLifeTime(duration);
+
+ certificateCredentialWriter.writeCredentials(certificateCredential);
+
+ StringBuilder stringBuilder = new StringBuilder("Certificate for community user ");
+ stringBuilder.append(assetResponse.getUsername()).append(" successfully persisted.");
+ stringBuilder.append(" Certificate DN - ").append(cert.getSubjectDN());
+
+ info(stringBuilder.toString());
+
+ String contextPath = request.getContextPath();
+ if (!contextPath.endsWith("/")) {
+ contextPath = contextPath + "/";
+ }
+ request.setAttribute("action", contextPath);
+ JSPUtil.fwd(request, response, SUCCESS_PAGE);
+ info("2.a. Completely finished with delegation.");
+
+ }
+}
+
Added: airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/servlet/CredentialStoreOA4MPServer.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/servlet/CredentialStoreOA4MPServer.java?rev=1403813&view=auto
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/servlet/CredentialStoreOA4MPServer.java (added)
+++ airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/servlet/CredentialStoreOA4MPServer.java Tue Oct 30 18:52:27 2012
@@ -0,0 +1,60 @@
+package org.apache.airavata.credential.store.servlet;
+
+import edu.uiuc.ncsa.myproxy.oa4mp.client.ClientEnvironment;
+import edu.uiuc.ncsa.myproxy.oa4mp.client.OA4MPResponse;
+import edu.uiuc.ncsa.myproxy.oa4mp.client.OA4MPService;
+import edu.uiuc.ncsa.security.core.exceptions.GeneralException;
+import edu.uiuc.ncsa.security.delegation.client.request.DelegationRequest;
+import edu.uiuc.ncsa.security.delegation.client.request.DelegationResponse;
+import org.apache.commons.codec.binary.Base64;
+import org.bouncycastle.jce.PKCS10CertificationRequest;
+
+import java.security.KeyPair;
+import java.util.HashMap;
+import java.util.Map;
+
+import static edu.uiuc.ncsa.myproxy.oa4mp.client.ClientEnvironment.CALLBACK_URI_KEY;
+import static edu.uiuc.ncsa.security.util.pkcs.CertUtil.createCertRequest;
+import static edu.uiuc.ncsa.security.util.pkcs.KeyUtil.generateKeyPair;
+
+/**
+ * Credential store specific OA4MPService.
+ * Only change is add support to include get parameters.
+ */
+public class CredentialStoreOA4MPServer extends OA4MPService {
+ public CredentialStoreOA4MPServer(ClientEnvironment environment) {
+ super(environment);
+ }
+
+ public OA4MPResponse requestCert(Map additionalParameters) {
+ if (additionalParameters == null) {
+ additionalParameters = new HashMap();
+ }
+ try {
+ KeyPair keyPair = generateKeyPair();
+ PKCS10CertificationRequest certReq = createCertRequest(keyPair);
+ OA4MPResponse mpdsResponse = new OA4MPResponse();
+ mpdsResponse.setPrivateKey(keyPair.getPrivate());
+ additionalParameters.put(ClientEnvironment.CERT_REQUEST_KEY, Base64.encodeBase64String(certReq.getDEREncoded()));
+
+ if (additionalParameters.get(getEnvironment().getConstants().get(CALLBACK_URI_KEY)) == null) {
+ additionalParameters.put(getEnvironment().getConstants().get(CALLBACK_URI_KEY), getEnvironment().
+ getCallback().toString());
+ }
+
+ DelegationRequest daReq = new DelegationRequest();
+ daReq.setParameters(additionalParameters);
+ daReq.setClient(getEnvironment().getClient());
+ daReq.setBaseUri(getEnvironment().getAuthorizationUri());
+ DelegationResponse daResp = (DelegationResponse) getEnvironment().getDelegationService().process(daReq);
+ mpdsResponse.setRedirect(daResp.getRedirectUri());
+ return mpdsResponse;
+ } catch (Throwable e) {
+ if (e instanceof RuntimeException) {
+ throw (RuntimeException) e;
+ }
+ throw new GeneralException("Error generating request", e);
+ }
+
+ }
+}
Added: airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/servlet/CredentialStoreStartServlet.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/servlet/CredentialStoreStartServlet.java?rev=1403813&view=auto
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/servlet/CredentialStoreStartServlet.java (added)
+++ airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/servlet/CredentialStoreStartServlet.java Tue Oct 30 18:52:27 2012
@@ -0,0 +1,122 @@
+package org.apache.airavata.credential.store.servlet;
+
+import edu.uiuc.ncsa.myproxy.oa4mp.client.OA4MPResponse;
+import edu.uiuc.ncsa.myproxy.oa4mp.client.servlet.ClientServlet;
+import edu.uiuc.ncsa.security.servlet.JSPUtil;
+import edu.uiuc.ncsa.security.util.pkcs.KeyUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import static edu.uiuc.ncsa.myproxy.oa4mp.client.ClientEnvironment.CALLBACK_URI_KEY;
+
+/**
+ * When portal initiate a request to get credentials it will hit this servlet.
+ */
+public class CredentialStoreStartServlet extends ClientServlet {
+
+ private String errorUrl;
+ private String redirectUrl;
+
+ private static Logger log = LoggerFactory.getLogger(CredentialStoreStartServlet.class);
+
+ protected String decorateURI(URI inputURI, Map<String, String> parameters) {
+
+ if (parameters.isEmpty()) {
+ return inputURI.toString();
+ }
+
+ String stringUri = inputURI.toString();
+ StringBuilder stringBuilder = new StringBuilder(stringUri);
+
+ boolean isFirst = true;
+
+ for (Map.Entry<String, String> entry : parameters.entrySet()) {
+ if (isFirst) {
+ stringBuilder.append("?");
+ isFirst = false;
+ } else {
+ stringBuilder.append("&");
+ }
+
+ stringBuilder.append(entry.getKey()).append("=").append(entry.getValue());
+ }
+
+ return stringBuilder.toString();
+
+ }
+
+ @Override
+ protected void doIt(HttpServletRequest request, HttpServletResponse response)
+ throws Throwable {
+
+ String gatewayName = request.getParameter("gatewayName");
+ String portalUserName = request.getParameter("portalUserName");
+ String contactEmail = request.getParameter("email");
+
+ if (gatewayName == null) {
+ JSPUtil.handleException(new RuntimeException("Please specify a gateway name."), request,
+ response, "/credential-store/error.jsp");
+ return;
+ }
+
+ if (portalUserName == null) {
+ JSPUtil.handleException(new RuntimeException("Please specify a portal user name."), request,
+ response, "/credential-store/error.jsp");
+ return;
+ }
+
+ if (contactEmail == null) {
+ JSPUtil.handleException(new RuntimeException("Please specify a contact email address for community" +
+ " user account."), request,
+ response, "/credential-store/error.jsp");
+ return;
+ }
+
+ log.info("1.a. Starting transaction");
+ OA4MPResponse gtwResp = null;
+
+ Map<String, String> queryParameters = new HashMap<String, String>();
+ queryParameters.put("gatewayName", gatewayName);
+ queryParameters.put("portalUserName", portalUserName);
+ queryParameters.put("email", contactEmail);
+
+ Map<String, String> additionalParameters = new HashMap<String, String>();
+
+ String modifiedCallbackUri = decorateURI(getOA4MPService().getEnvironment().getCallback(), queryParameters);
+
+ info("The modified callback URI - " + modifiedCallbackUri);
+
+ additionalParameters.put(getEnvironment().getConstants().get(CALLBACK_URI_KEY), modifiedCallbackUri);
+
+
+ // Drumroll please: here is the work for this call.
+ try {
+ gtwResp = getOA4MPService().requestCert(additionalParameters);
+ } catch (Throwable t) {
+ JSPUtil.handleException(t, request, response, "/credential-store/error.jsp");
+ return;
+ }
+ log.info("1.b. Got response. Creating page with redirect for " + gtwResp.getRedirect().getHost());
+ // Normally, we'd just do a redirect, but we will put up a page and show the redirect to the user.
+ // The client response contains the generated private key as well
+ // In a real application, the private key would be stored. This, however, exceeds the scope of this
+ // sample application -- all we need to do to complete the process is send along the redirect url.
+
+ request.setAttribute(REDIR, REDIR);
+ request.setAttribute("redirectUrl", gtwResp.getRedirect().toString());
+ request.setAttribute(ACTION_KEY, ACTION_KEY);
+ request.setAttribute("action", ACTION_REDIRECT_VALUE);
+ log.info("1.b. Showing redirect page.");
+ JSPUtil.fwd(request, response, "/credential-store/show-redirect.jsp");
+
+ }
+}
Added: airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/util/DBUtil.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/util/DBUtil.java?rev=1403813&view=auto
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/util/DBUtil.java (added)
+++ airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/util/DBUtil.java Tue Oct 30 18:52:27 2012
@@ -0,0 +1,124 @@
+package org.apache.airavata.credential.store.util;
+
+import org.apache.commons.dbcp.BasicDataSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.ServletContext;
+import javax.sql.DataSource;
+import java.sql.*;
+import java.util.Properties;
+
+/**
+ * Database utility class.
+ */
+public class DBUtil {
+
+ private String jdbcUrl;
+ private String databaseUserName;
+ private String databasePassword;
+ private String driverName;
+
+ protected static Logger log = LoggerFactory.getLogger(DBUtil.class);
+
+ private Properties properties;
+
+ public DBUtil(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();
+ }
+
+ 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;
+ }
+
+ /**
+ * Mainly useful for tests.
+ * @param tableName The table name.
+ * @param connection The connection to be used.
+ */
+ public static void truncate(String tableName, Connection connection) throws SQLException {
+
+ String sql = "delete from " + tableName;
+
+ PreparedStatement preparedStatement = connection.prepareStatement(sql);
+ preparedStatement.executeUpdate();
+
+ connection.commit();
+
+ }
+
+ public Connection getConnection() throws SQLException {
+ Connection connection = DriverManager.getConnection(jdbcUrl, properties);
+ connection.setAutoCommit(false);
+
+ return connection;
+ }
+
+ public void cleanup(PreparedStatement preparedStatement, Connection connection) {
+ if (preparedStatement != null) {
+ try {
+ preparedStatement.close();
+ } catch (SQLException e) {
+ log.error("Error closing prepared statement.", e);
+ }
+ }
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (SQLException e) {
+ log.error("Error closing database connection.", e);
+ }
+ }
+ }
+
+ public static DBUtil getDBUtil(ServletContext servletContext) throws Exception{
+
+ String jdbcUrl = servletContext.getInitParameter("credential-store-jdbc-url");
+ String userName = servletContext.getInitParameter("credential-store-db-user");
+ String password = servletContext.getInitParameter("credential-store-db-password");
+ String driverName = servletContext.getInitParameter("credential-store-db-driver");
+
+ StringBuilder stringBuilder = new StringBuilder("Starting credential store, connecting to database - ");
+ stringBuilder.append(jdbcUrl).append(" DB user - ").append(userName).
+ append(" driver name - ").append(driverName);
+
+ log.info(stringBuilder.toString());
+
+ DBUtil dbUtil = new DBUtil(jdbcUrl, userName, password, driverName);
+ try {
+ dbUtil.init();
+ } catch (Exception e) {
+ log.error("Error initializing database operations.", e);
+ throw e;
+ }
+
+ return dbUtil;
+ }
+
+}
+
Added: airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/util/Utility.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/util/Utility.java?rev=1403813&view=auto
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/util/Utility.java (added)
+++ airavata/sandbox/airavata-rest-security/modules/credential-store/src/main/java/org/apache/airavata/credential/store/util/Utility.java Tue Oct 30 18:52:27 2012
@@ -0,0 +1,20 @@
+package org.apache.airavata.credential.store.util;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Contains some utility methods.
+ */
+public class Utility {
+
+ private static final String DATE_FORMAT = "MM/dd/yyyy HH:mm:ss";
+
+ public static String convertDateToString(Date date) {
+
+ DateFormat df = new SimpleDateFormat(DATE_FORMAT);
+ return df.format(date);
+ }
+
+}
Added: airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/java/org/apache/airavata/credential/store/impl/db/CommunityUserDAOTest.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/java/org/apache/airavata/credential/store/impl/db/CommunityUserDAOTest.java?rev=1403813&view=auto
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/java/org/apache/airavata/credential/store/impl/db/CommunityUserDAOTest.java (added)
+++ airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/java/org/apache/airavata/credential/store/impl/db/CommunityUserDAOTest.java Tue Oct 30 18:52:27 2012
@@ -0,0 +1,86 @@
+package org.apache.airavata.credential.store.impl.db;
+
+import org.apache.airavata.credential.store.CommunityUser;
+import org.apache.airavata.credential.store.util.DBUtil;
+
+import java.sql.Connection;
+import java.util.List;
+
+/**
+ * Test for community user DAO.
+ */
+public class CommunityUserDAOTest extends DAOBaseTestCase {
+
+ private CommunityUserDAO communityUserDAO;
+
+ public void setUp() throws Exception {
+ super.setUp();
+
+ communityUserDAO = new CommunityUserDAO(getDbUtil());
+
+ Connection connection = getDbUtil().getConnection();
+ DBUtil.truncate("community_user", connection);
+
+ connection.close();
+ }
+
+ public void testAddCommunityUser() throws Exception {
+
+ CommunityUser communityUser = new CommunityUser("gw1", "ogce","ogce@sciencegateway.org");
+ communityUserDAO.addCommunityUser(communityUser);
+
+ communityUser = new CommunityUser("gw1", "ogce2","ogce@sciencegateway.org");
+ communityUserDAO.addCommunityUser(communityUser);
+
+ CommunityUser user = communityUserDAO.getCommunityUser("gw1", "ogce");
+ assertNotNull(user);
+ assertEquals("ogce@sciencegateway.org", user.getUserEmail());
+
+ user = communityUserDAO.getCommunityUser("gw1", "ogce2");
+ assertNotNull(user);
+ assertEquals("ogce@sciencegateway.org", user.getUserEmail());
+ }
+
+ public void testDeleteCommunityUser() throws Exception {
+
+ CommunityUser communityUser = new CommunityUser("gw1", "ogce","ogce@sciencegateway.org");
+ communityUserDAO.addCommunityUser(communityUser);
+
+ CommunityUser user = communityUserDAO.getCommunityUser("gw1", "ogce");
+ assertNotNull(user);
+
+ communityUser = new CommunityUser("gw1", "ogce","ogce@sciencegateway.org");
+ communityUserDAO.deleteCommunityUser(communityUser);
+
+ user = communityUserDAO.getCommunityUser("gw1", "ogce");
+ assertNull(user);
+
+ }
+
+ public void testGetCommunityUsers() throws Exception {
+
+ CommunityUser communityUser = new CommunityUser("gw1", "ogce","ogce@sciencegateway.org");
+ communityUserDAO.addCommunityUser(communityUser);
+
+ CommunityUser user = communityUserDAO.getCommunityUser("gw1", "ogce");
+ assertNotNull(user);
+ assertEquals("ogce@sciencegateway.org", user.getUserEmail());
+
+ }
+
+ public void testGetCommunityUsersForGateway() throws Exception {
+
+ CommunityUser communityUser = new CommunityUser("gw1", "ogce","ogce@sciencegateway.org");
+ communityUserDAO.addCommunityUser(communityUser);
+
+ communityUser = new CommunityUser("gw1", "ogce2","ogce@sciencegateway.org");
+ communityUserDAO.addCommunityUser(communityUser);
+
+ List<CommunityUser> users = communityUserDAO.getCommunityUsers("gw1");
+ assertNotNull(users);
+ assertEquals(2, users.size());
+
+ assertEquals(users.get(0).getUserName(), "ogce");
+ assertEquals(users.get(1).getUserName(), "ogce2");
+ }
+}
Added: airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/java/org/apache/airavata/credential/store/impl/db/CredentialsDAOTest.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/java/org/apache/airavata/credential/store/impl/db/CredentialsDAOTest.java?rev=1403813&view=auto
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/java/org/apache/airavata/credential/store/impl/db/CredentialsDAOTest.java (added)
+++ airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/java/org/apache/airavata/credential/store/impl/db/CredentialsDAOTest.java Tue Oct 30 18:52:27 2012
@@ -0,0 +1,161 @@
+package org.apache.airavata.credential.store.impl.db;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+import org.apache.airavata.credential.store.CertificateCredential;
+import org.apache.airavata.credential.store.CommunityUser;
+import org.apache.airavata.credential.store.CredentialStoreException;
+import org.apache.airavata.credential.store.util.DBUtil;
+
+import java.sql.Connection;
+import java.util.List;
+
+/**
+ * Test class for credential class
+ */
+public class CredentialsDAOTest extends DAOBaseTestCase {
+
+ private CredentialsDAO credentialsDAO;
+
+ private String certificateString = "-----BEGIN CERTIFICATE-----\n" +
+ "MIIDWjCCAkKgAwIBAgIEUHMnRzANBgkqhkiG9w0BAQUFADBvMQswCQYDVQQGEwJV\n" +
+ "UzEQMA4GA1UECBMHSW5kaWFuYTEUMBIGA1UEBxMLQmxvb21pbmd0b24xEDAOBgNV\n" +
+ "BAoTB0luZGlhbmExCzAJBgNVBAsTAklVMRkwFwYDVQQDExBBbWlsYSBKYXlhc2Vr\n" +
+ "YXJhMB4XDTEyMTAwODE5MTkzNVoXDTEzMDEwNjE5MTkzNVowbzELMAkGA1UEBhMC\n" +
+ "VVMxEDAOBgNVBAgTB0luZGlhbmExFDASBgNVBAcTC0Jsb29taW5ndG9uMRAwDgYD\n" +
+ "VQQKEwdJbmRpYW5hMQswCQYDVQQLEwJJVTEZMBcGA1UEAxMQQW1pbGEgSmF5YXNl\n" +
+ "a2FyYTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJEdoR4gu32xf8C+\n" +
+ "H6bVymFWkO6SAM4iAbP5hruDG8HftyfaEmz8MM651X3CoEiPRUeYyoxl5CwSARx6\n" +
+ "mex1h4Hy7lbVwRKEOnsJwF0POwDo6qV5eFII1ac/XiWpBjEeHpLwoOoOm55pZC6M\n" +
+ "d/YXQcZhWqpru3OOkK7nozADpOY32A7gAndMjPuuLtT1TsY+mRuHM+o7jv0cKkTM\n" +
+ "SfJMScqSAWlMrDYyI3lr2nkPsYvCxP+eFp6oY0U604TAYH7ycDmemtm4OEP7pylj\n" +
+ "HjmH9EpBj+kDwtexpLs6VBcavRne7Mh7JBejkORPcgcEQFSkSURUk6PSrzYMo4oq\n" +
+ "Y+GxPUMCAwEAATANBgkqhkiG9w0BAQUFAAOCAQEAJamQWGcmDx59KYeo0WLMQ7Xj\n" +
+ "15XKddqrdxSJetaFtBJ23XhOFHBesMAVtCKImxw9brRetUYpKV9YfBZdGInolMPX\n" +
+ "HAeACHVkEeXhGft2sMt/Y9gqFSpROO5ifGKnPRosBzjiWZPAXi6giH8bf3vrQQPB\n" +
+ "z7j3Dz/1u3zxwMYuTRScZ9b/RQ65Fbs2WmNnlhr8qLkgHke9Hb2r1SV0V7AkxnWb\n" +
+ "gfsK27V3RUlxZvc24lhWXeRKZDrLPZrU/DscCW4x439IE+9B+Vvq4cD4g8BPoNzM\n" +
+ "2jZWzXAHStjOsOpCohkXO53jiC8zW6rrqqos83Oo9E2WG8RW801vXegJif1fNQ==\n" +
+ "-----END CERTIFICATE-----";
+
+ private String privateKey = "-----BEGIN PRIVATE KEY-----\n" +
+ "MIIDWjCCAkKgAwIBAgIEUHMnRzANBgkqhkiG9w0BAQUFADBvMQswCQYDVQQGEwJV\n" +
+ "UzEQMA4GA1UECBMHSW5kaWFuYTEUMBIGA1UEBxMLQmxvb21pbmd0b24xEDAOBgNV\n" +
+ "BAoTB0luZGlhbmExCzAJBgNVBAsTAklVMRkwFwYDVQQDExBBbWlsYSBKYXlhc2Vr\n" +
+ "YXJhMB4XDTEyMTAwODE5MTkzNVoXDTEzMDEwNjE5MTkzNVowbzELMAkGA1UEBhMC\n" +
+ "VVMxEDAOBgNVBAgTB0luZGlhbmExFDASBgNVBAcTC0Jsb29taW5ndG9uMRAwDgYD\n" +
+ "VQQKEwdJbmRpYW5hMQswCQYDVQQLEwJJVTEZMBcGA1UEAxMQQW1pbGEgSmF5YXNl\n" +
+ "a2FyYTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJEdoR4gu32xf8C+\n" +
+ "H6bVymFWkO6SAM4iAbP5hruDG8HftyfaEmz8MM651X3CoEiPRUeYyoxl5CwSARx6\n" +
+ "mex1h4Hy7lbVwRKEOnsJwF0POwDo6qV5eFII1ac/XiWpBjEeHpLwoOoOm55pZC6M\n" +
+ "d/YXQcZhWqpru3OOkK7nozADpOY32A7gAndMjPuuLtT1TsY+mRuHM+o7jv0cKkTM\n" +
+ "SfJMScqSAWlMrDYyI3lr2nkPsYvCxP+eFp6oY0U604TAYH7ycDmemtm4OEP7pylj\n" +
+ "HjmH9EpBj+kDwtexpLs6VBcavRne7Mh7JBejkORPcgcEQFSkSURUk6PSrzYMo4oq\n" +
+ "Y+GxPUMCAwEAATANBgkqhkiG9w0BAQUFAAOCAQEAJamQWGcmDx59KYeo0WLMQ7Xj\n" +
+ "15XKddqrdxSJetaFtBJ23XhOFHBesMAVtCKImxw9brRetUYpKV9YfBZdGInolMPX\n" +
+ "HAeACHVkEeXhGft2sMt/Y9gqFSpROO5ifGKnPRosBzjiWZPAXi6giH8bf3vrQQPB\n" +
+ "z7j3Dz/1u3zxwMYuTRScZ9b/RQ65Fbs2WmNnlhr8qLkgHke9Hb2r1SV0V7AkxnWb\n" +
+ "gfsK27V3RUlxZvc24lhWXeRKZDrLPZrU/DscCW4x439IE+9B+Vvq4cD4g8BPoNzM\n" +
+ "2jZWzXAHStjOsOpCohkXO53jiC8zW6rrqqos83Oo9E2WG8RW801vXegJif1fNQ==\n" +
+ "-----END PRIVATE KEY-----";
+
+ private CommunityUser getCommunityUser(String gateway, String name) {
+ return new CommunityUser(gateway, name, "amila@sciencegateway.org");
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ credentialsDAO = new CredentialsDAO(getDbUtil());
+
+ // Cleanup tables;
+ Connection connection = getDbUtil().getConnection();
+ DBUtil.truncate("credentials", connection);
+ DBUtil.truncate("community_user", connection);
+
+ connection.close();
+ }
+
+ private void addTestCredentials() throws Exception {
+
+ CertificateCredential certificateCredential = new CertificateCredential();
+ certificateCredential.setCertificate(certificateString);
+ certificateCredential.setPrivateKey(privateKey);
+ certificateCredential.setCommunityUser(getCommunityUser("gw1", "tom"));
+ certificateCredential.setLifeTime(1000);
+ certificateCredential.setPortalUserName("jerry");
+ certificateCredential.setNotBefore("13 OCT 2012 5:34:23");
+ certificateCredential.setNotAfter("14 OCT 2012 5:34:23");
+
+ credentialsDAO.addCredentials(certificateCredential);
+
+ }
+
+ public void testAddCredentials() throws Exception {
+
+ addTestCredentials();
+
+ CertificateCredential certificateCredential
+ = credentialsDAO.getCredential("gw1", "tom");
+ Assert.assertNotNull(certificateCredential);
+ Assert.assertEquals("jerry", certificateCredential.getPortalUserName());
+ Assert.assertEquals(certificateString, certificateCredential.getCertificate());
+ Assert.assertEquals(privateKey, certificateCredential.getPrivateKey());
+
+ }
+
+ public void testDeleteCredentials() throws Exception {
+
+ addTestCredentials();
+
+ CertificateCredential certificateCredential
+ = credentialsDAO.getCredential("gw1", "tom");
+ Assert.assertNotNull(certificateCredential);
+
+ credentialsDAO.deleteCredentials("gw1", "tom");
+
+ certificateCredential = credentialsDAO.getCredential("gw1", "tom");
+ Assert.assertNull(certificateCredential);
+ }
+
+ public void testUpdateCredentials() throws Exception {
+
+ addTestCredentials();
+
+ CertificateCredential certificateCredential = new CertificateCredential();
+ certificateCredential.setCommunityUser(getCommunityUser("gw1", "tom"));
+ certificateCredential.setCertificate("new.........Cert");
+ certificateCredential.setPrivateKey("new..........PrivateKey");
+ certificateCredential.setPortalUserName("test2");
+ certificateCredential.setLifeTime(50);
+ certificateCredential.setNotBefore("15 OCT 2012 5:34:23");
+ certificateCredential.setNotAfter("16 OCT 2012 5:34:23");
+
+ credentialsDAO.updateCredentials(certificateCredential);
+
+ certificateCredential = credentialsDAO.getCredential("gw1", "tom");
+
+ Assert.assertEquals("new.........Cert", certificateCredential.getCertificate());
+ Assert.assertEquals("new..........PrivateKey", certificateCredential.getPrivateKey());
+ Assert.assertEquals("test2", certificateCredential.getPortalUserName());
+
+ }
+
+ public void testGetCredentials() throws Exception {
+
+ addTestCredentials();
+
+ CertificateCredential certificateCredential = credentialsDAO.getCredential("gw1", "tom");
+
+ Assert.assertEquals(certificateString, certificateCredential.getCertificate());
+ Assert.assertEquals(privateKey, certificateCredential.getPrivateKey());
+ }
+
+ public void testGetGatewayCredentials() throws Exception {
+
+ addTestCredentials();
+
+ List<CertificateCredential> list = credentialsDAO.getCredentials("gw1");
+
+ Assert.assertEquals(1, list.size());
+ }
+}
Added: airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/java/org/apache/airavata/credential/store/impl/db/DAOBaseTestCase.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/java/org/apache/airavata/credential/store/impl/db/DAOBaseTestCase.java?rev=1403813&view=auto
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/java/org/apache/airavata/credential/store/impl/db/DAOBaseTestCase.java (added)
+++ airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/java/org/apache/airavata/credential/store/impl/db/DAOBaseTestCase.java Tue Oct 30 18:52:27 2012
@@ -0,0 +1,35 @@
+package org.apache.airavata.credential.store.impl.db;
+
+import junit.framework.TestCase;
+import org.apache.airavata.credential.store.util.DBUtil;
+
+/**
+ * Base test class for DB operation testing.
+ */
+public class DAOBaseTestCase extends TestCase {
+
+ private DBUtil dbUtil;
+
+ public DAOBaseTestCase() {
+
+ dbUtil = new DBUtil(//"jdbc:mysql://localhost/airavata",
+ // "jdbc:mysql://localhost/airavata",
+
+ "jdbc:h2:../../src/test/resources/testdb/test",
+ // "airavata", "secret", "com.mysql.jdbc.Driver");
+ // "root", "root123", "com.mysql.jdbc.Driver");
+ "sa", "sa", "org.h2.Driver");
+ try {
+ dbUtil.init();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+
+ }
+
+ protected DBUtil getDbUtil() {
+ return dbUtil;
+ }
+
+}
Added: airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/java/org/apache/airavata/credential/store/impl/db/MappingDAOTest.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/java/org/apache/airavata/credential/store/impl/db/MappingDAOTest.java?rev=1403813&view=auto
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/java/org/apache/airavata/credential/store/impl/db/MappingDAOTest.java (added)
+++ airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/java/org/apache/airavata/credential/store/impl/db/MappingDAOTest.java Tue Oct 30 18:52:27 2012
@@ -0,0 +1,72 @@
+package org.apache.airavata.credential.store.impl.db;
+
+import junit.framework.Assert;
+import org.apache.airavata.credential.store.Mapping;
+import org.junit.Ignore;
+
+import java.util.List;
+
+/**
+ * DAO class for Mapping.
+ */
+@Ignore
+public class MappingDAOTest extends DAOBaseTestCase {
+
+ private MappingDAO mappingDAO;
+
+ public void setUp() throws Exception {
+ super.setUp();
+ mappingDAO = new MappingDAO(getDbUtil());
+ }
+
+ public void testAddMapping() throws Exception {
+ Mapping m = new Mapping("gw3", "amila", "lahiru");
+ mappingDAO.addMapping(m);
+
+ String communityUser = mappingDAO.getMappingCommunityUser("lahiru", "gw3");
+ Assert.assertEquals(communityUser, "amila");
+ }
+
+ public void testDeleteGatewayMapping() throws Exception {
+ Mapping m = new Mapping("gw4", "amila", "lahiru");
+ mappingDAO.addMapping(m);
+
+ mappingDAO.deleteGatewayMapping("lahiru", "gw4");
+ String communityUser = mappingDAO.getMappingCommunityUser("lahiru", "gw4");
+ Assert.assertNull(communityUser);
+
+ }
+
+ public void testDeleteGatewayCommunityAccountMappings() throws Exception {
+ Mapping m = new Mapping("gw5", "c2", "lahiru");
+ mappingDAO.addMapping(m);
+
+ mappingDAO.deleteGatewayCommunityAccountMappings("c2", "gw1");
+ List<String> portalUsers = mappingDAO.getMappingPortalUsers("c2", "gw1");
+
+ Assert.assertEquals(0, portalUsers.size());
+ }
+
+ public void testGetMappingPortalUsers() throws Exception {
+ Mapping m = new Mapping("gw6", "c2", "lahiru");
+ mappingDAO.addMapping(m);
+
+ List<String> portalUsers = mappingDAO.getMappingPortalUsers("c2", "gw6");
+ Assert.assertEquals(1, portalUsers.size());
+ Assert.assertEquals("lahiru", portalUsers.get(0));
+
+ }
+
+ public void testGetMappingCommunityUser() throws Exception {
+ Mapping m = new Mapping("gw7", "c2", "lahiru");
+ mappingDAO.addMapping(m);
+
+ String communityUser = mappingDAO.getMappingCommunityUser("lahiru", "gw7");
+ Assert.assertEquals(communityUser, "c2");
+ }
+
+ public void testGetCredentialsForPortalUser() throws Exception {
+ String certificate = mappingDAO.getCredentials("lahiru", "gw2");
+ System.out.println(certificate);
+ }
+}
Added: airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/resources/keystore.jks
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/resources/keystore.jks?rev=1403813&view=auto
==============================================================================
Binary file - no diff available.
Propchange: airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/resources/keystore.jks
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/resources/testdb/test.h2.db
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/resources/testdb/test.h2.db?rev=1403813&view=auto
==============================================================================
Binary file - no diff available.
Propchange: airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/resources/testdb/test.h2.db
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/resources/testdb/test.trace.db
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/resources/testdb/test.trace.db?rev=1403813&view=auto
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/resources/testdb/test.trace.db (added)
+++ airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/resources/testdb/test.trace.db Tue Oct 30 18:52:27 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/credential-store/src/test/resources/testdb/test/test.trace.db
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/resources/testdb/test/test.trace.db?rev=1403813&view=auto
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/resources/testdb/test/test.trace.db (added)
+++ airavata/sandbox/airavata-rest-security/modules/credential-store/src/test/resources/testdb/test/test.trace.db Tue Oct 30 18:52:27 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/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=1403813&r1=1403812&r2=1403813&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 Tue Oct 30 18:52:27 2012
@@ -30,6 +30,8 @@ public class AuthenticatorConfigurationR
protected static Logger log = LoggerFactory.getLogger(AuthenticatorConfigurationReader.class);
+ protected static boolean authenticationEnabled = true;
+
public AuthenticatorConfigurationReader() {
}
@@ -41,6 +43,27 @@ public class AuthenticatorConfigurationR
Document doc = dBuilder.parse(inputStream);
doc.getDocumentElement().normalize();
+ NodeList rootNodeList = doc.getElementsByTagName("authenticators");
+
+ if (rootNodeList == null || rootNodeList.getLength() == 0) {
+ throw new ParserConfigurationException("authenticators.xml should have authenticators root element.");
+ }
+
+ Node authenticatorsNode = rootNodeList.item(0);
+ NamedNodeMap rootAttributes = authenticatorsNode.getAttributes();
+
+ if (rootAttributes != null && rootAttributes.getNamedItem("enabled") != null) {
+
+ String enabledAttribute = rootAttributes.getNamedItem("enabled").getNodeValue();
+ if ( enabledAttribute != null) {
+
+ if (enabledAttribute.equals("false")) {
+ authenticationEnabled = false;
+ }
+ }
+ }
+
+
NodeList authenticators = doc.getElementsByTagName("authenticator");
for (int i = 0; i < authenticators.getLength(); ++i) {
@@ -175,6 +198,17 @@ public class AuthenticatorConfigurationR
return Collections.unmodifiableList(authenticatorList);
}
+ /**
+ * We can specify whether authentication is enabled in the system for all request or not.
+ * This we can state in the configuration. AuthenticatorConfigurationReader will read that information
+ * and will populate that to static boolean authenticationEnabled. This method will say whether
+ * authentication is enabled in the system or disabled in the system.
+ * @return <code>true</code> if authentication is enabled. Else <code>false</code>.
+ */
+ public static boolean isAuthenticationEnabled() {
+ return authenticationEnabled;
+ }
+
/**
* Comparator to sort authenticators based on authenticator priority.
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=1403813&r1=1403812&r2=1403813&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 Tue Oct 30 18:52:27 2012
@@ -35,6 +35,8 @@ public class AuthenticatorConfigurationR
= new AuthenticatorConfigurationReader();
authenticatorConfigurationReader.init(configurationFile);
+ assertTrue(AuthenticatorConfigurationReader.isAuthenticationEnabled());
+
List<Authenticator> authenticators = authenticatorConfigurationReader.getAuthenticatorList();
assertEquals(authenticators.size(), 3);
@@ -78,4 +80,18 @@ public class AuthenticatorConfigurationR
assertEquals(6, authenticators.get(2).getPriority());
}
+
+ public void testDisabledAuthenticator() throws Exception {
+
+ String disabledConfiguration
+ = this.getClass().getClassLoader().getResource("disabled-authenticator.xml").getFile();
+
+
+ AuthenticatorConfigurationReader authenticatorConfigurationReader
+ = new AuthenticatorConfigurationReader();
+ authenticatorConfigurationReader.init(disabledConfiguration);
+
+ assertFalse(AuthenticatorConfigurationReader.isAuthenticationEnabled());
+
+ }
}
Added: airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/disabled-authenticator.xml
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/disabled-authenticator.xml?rev=1403813&view=auto
==============================================================================
--- airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/disabled-authenticator.xml (added)
+++ airavata/sandbox/airavata-rest-security/modules/security/src/test/resources/disabled-authenticator.xml Tue Oct 30 18:52:27 2012
@@ -0,0 +1,72 @@
+<?xml version="1.0"?>
+
+<!--
+This file contains a sample authenticator configuration. We can define all authenticators in this file. Each authenticator
+configuration has to start with tag "authenticator". The name is the name given to the authenticator. The actual
+authenticator implementation is implemented in the class. There are configurations specific to authenticators.
+Those configurations are reside inside <specificConfigurations> tags.
+-->
+
+<authenticators enabled="false">
+ <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>
+ <userName>mysql1</userName>
+ <password>secret1</password>
+ <databaseDriver>org.myqsql.Driver1</databaseDriver>
+ <sessionTable>Session1</sessionTable>
+ <sessionColumn>sessioncolumn</sessionColumn>
+ <comparingColumn>comparecolumn</comparingColumn>
+ <!-- TODO add datasource.name></datasource.name -->
+ </database>
+ </specificConfigurations>
+ </authenticator>
+
+ <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>
+ <userName>mysql2</userName>
+ <password>secret2</password>
+ <databaseDriver>org.myqsql.Driver2</databaseDriver>
+ <sessionTable>Session2</sessionTable>
+ <sessionColumn>sessioncolumn2</sessionColumn>
+ <comparingColumn>comparecolumn2</comparingColumn>
+ </database>
+ </specificConfigurations>
+ </authenticator>
+
+ <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>
+ <userName>mysql2</userName>
+ <password>secret2</password>
+ <databaseDriver>org.myqsql.Driver2</databaseDriver>
+ <sessionTable>Session2</sessionTable>
+ <sessionColumn>sessioncolumn2</sessionColumn>
+ <comparingColumn>comparecolumn2</comparingColumn>
+ </database>
+ </specificConfigurations>
+ </authenticator>
+
+ <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>
+ <userName>mysql3</userName>
+ <password>secret3</password>
+ <databaseDriver>org.myqsql.Driver3</databaseDriver>
+ <sessionTable>Session3</sessionTable>
+ <sessionColumn>sessioncolumn3</sessionColumn>
+ <comparingColumn>comparecolumn3</comparingColumn>
+ </database>
+ </specificConfigurations>
+ </authenticator>
+
+</authenticators>
\ No newline at end of file
Modified: 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=1403813&r1=1403812&r2=1403813&view=diff
==============================================================================
Binary files - no diff available.
Modified: airavata/sandbox/airavata-rest-security/pom.xml
URL: http://svn.apache.org/viewvc/airavata/sandbox/airavata-rest-security/pom.xml?rev=1403813&r1=1403812&r2=1403813&view=diff
==============================================================================
--- airavata/sandbox/airavata-rest-security/pom.xml (original)
+++ airavata/sandbox/airavata-rest-security/pom.xml Tue Oct 30 18:52:27 2012
@@ -596,6 +596,7 @@
<modules>
<module>modules/security</module>
<module>modules/commons</module>
+ <module>modules/credential-store</module>
</modules>
</profile>
<profile>