You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sa...@apache.org on 2014/04/14 20:31:30 UTC
[88/90] [abbrv] AIRAVATA-1124
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/security/src/main/java/org/apache/airavata/security/userstore/LDAPUserStore.java
----------------------------------------------------------------------
diff --git a/modules/security/src/main/java/org/apache/airavata/security/userstore/LDAPUserStore.java b/modules/security/src/main/java/org/apache/airavata/security/userstore/LDAPUserStore.java
new file mode 100644
index 0000000..c0ba288
--- /dev/null
+++ b/modules/security/src/main/java/org/apache/airavata/security/userstore/LDAPUserStore.java
@@ -0,0 +1,147 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.security.userstore;
+
+import org.apache.airavata.security.UserStore;
+import org.apache.airavata.security.UserStoreException;
+import org.apache.airavata.security.util.PasswordDigester;
+import org.apache.shiro.authc.AuthenticationException;
+import org.apache.shiro.authc.AuthenticationInfo;
+import org.apache.shiro.authc.AuthenticationToken;
+import org.apache.shiro.authc.UsernamePasswordToken;
+import org.apache.shiro.realm.ldap.JndiLdapContextFactory;
+import org.apache.shiro.realm.ldap.JndiLdapRealm;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import sun.reflect.generics.reflectiveObjects.NotImplementedException;
+
+/**
+ * A user store which talks to LDAP server. User credentials and user information are stored in a LDAP server.
+ */
+public class LDAPUserStore implements UserStore {
+
+ private JndiLdapRealm ldapRealm;
+
+ protected static Logger log = LoggerFactory.getLogger(LDAPUserStore.class);
+
+ private PasswordDigester passwordDigester;
+
+ public boolean authenticate(String userName, Object credentials) throws UserStoreException {
+
+ AuthenticationToken authenticationToken = new UsernamePasswordToken(userName,
+ passwordDigester.getPasswordHashValue((String) credentials));
+
+ AuthenticationInfo authenticationInfo;
+ try {
+ authenticationInfo = ldapRealm.getAuthenticationInfo(authenticationToken);
+ } catch (AuthenticationException e) {
+ log.warn(e.getLocalizedMessage(), e);
+ return false;
+ }
+
+ return authenticationInfo != null;
+
+ }
+
+ @Override
+ public boolean authenticate(Object credentials) throws UserStoreException {
+ log.error("LDAP user store only supports authenticating with user name and password.");
+ throw new NotImplementedException();
+ }
+
+ public void configure(Node specificConfigurationNode) throws UserStoreException {
+
+ /**
+ * <specificConfiguration> <ldap> <url>ldap://localhost:10389</url> <systemUser>admin</systemUser>
+ * <systemUserPassword>secret</systemUserPassword> <userDNTemplate>uid={0},ou=system</userDNTemplate> </ldap>
+ * </specificConfiguration>
+ */
+
+ Node configurationNode = null;
+ if (specificConfigurationNode != null) {
+ NodeList nodeList = specificConfigurationNode.getChildNodes();
+
+ for (int i = 0; i < nodeList.getLength(); ++i) {
+ Node n = nodeList.item(i);
+ if (n.getNodeType() == Node.ELEMENT_NODE) {
+ configurationNode = n;
+ }
+ }
+ }
+
+ String url = null;
+ String systemUser = null;
+ String systemUserPassword = null;
+ String userTemplate = null;
+ String passwordHashMethod = null;
+
+ if (configurationNode != null) {
+ NodeList nodeList = configurationNode.getChildNodes();
+
+ for (int i = 0; i < nodeList.getLength(); ++i) {
+ Node n = nodeList.item(i);
+
+ if (n.getNodeType() == Node.ELEMENT_NODE) {
+
+ Element element = (Element) n;
+
+ if (element.getNodeName().equals("url")) {
+ url = element.getFirstChild().getNodeValue();
+ } else if (element.getNodeName().equals("systemUser")) {
+ systemUser = element.getFirstChild().getNodeValue();
+ } else if (element.getNodeName().equals("systemUserPassword")) {
+ systemUserPassword = element.getFirstChild().getNodeValue();
+ } else if (element.getNodeName().equals("userDNTemplate")) {
+ userTemplate = element.getFirstChild().getNodeValue();
+ } else if (element.getNodeName().equals("passwordHashMethod")) {
+ passwordHashMethod = element.getFirstChild().getNodeValue();
+ }
+ }
+ }
+ }
+
+ passwordDigester = new PasswordDigester(passwordHashMethod);
+
+ initializeLDAP(url, systemUser, systemUserPassword, userTemplate);
+
+ }
+
+ protected void initializeLDAP(String ldapUrl, String systemUser, String systemUserPassword, String userNameTemplate) {
+
+ JndiLdapContextFactory jndiLdapContextFactory = new JndiLdapContextFactory();
+
+ jndiLdapContextFactory.setUrl(ldapUrl);
+ jndiLdapContextFactory.setSystemUsername(systemUser);
+ jndiLdapContextFactory.setSystemPassword(systemUserPassword);
+
+ ldapRealm = new JndiLdapRealm();
+
+ ldapRealm.setContextFactory(jndiLdapContextFactory);
+ ldapRealm.setUserDnTemplate(userNameTemplate);
+
+ ldapRealm.init();
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/security/src/main/java/org/apache/airavata/security/userstore/SessionDBUserStore.java
----------------------------------------------------------------------
diff --git a/modules/security/src/main/java/org/apache/airavata/security/userstore/SessionDBUserStore.java b/modules/security/src/main/java/org/apache/airavata/security/userstore/SessionDBUserStore.java
new file mode 100644
index 0000000..b332e68
--- /dev/null
+++ b/modules/security/src/main/java/org/apache/airavata/security/userstore/SessionDBUserStore.java
@@ -0,0 +1,132 @@
+/*
+ *
+ * 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.common.utils.DBUtil;
+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 DBUtil dbUtil;
+
+ 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 = dbUtil.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.debug(stringBuilder.toString());
+ }
+
+ private void initializeDatabaseLookup() throws RuntimeException {
+
+ try {
+ this.dbUtil = new DBUtil(getDatabaseURL(), getDatabaseUserName(), getDatabasePassword(), getDatabaseDriver());
+ } 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);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/security/src/main/java/org/apache/airavata/security/util/PasswordDigester.java
----------------------------------------------------------------------
diff --git a/modules/security/src/main/java/org/apache/airavata/security/util/PasswordDigester.java b/modules/security/src/main/java/org/apache/airavata/security/util/PasswordDigester.java
new file mode 100644
index 0000000..113189c
--- /dev/null
+++ b/modules/security/src/main/java/org/apache/airavata/security/util/PasswordDigester.java
@@ -0,0 +1,111 @@
+/*
+ *
+ * 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.util;
+
+import org.apache.airavata.common.utils.SecurityUtil;
+import org.apache.airavata.security.UserStoreException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+/**
+ * Contains some utility methods related to security.
+ */
+public class PasswordDigester {
+
+ protected static Logger log = LoggerFactory.getLogger(PasswordDigester.class);
+
+ private String hashMethod;
+
+ /**
+ * Creates password digester
+ *
+ * @param method
+ * The particular hash method. E.g :- MD5, SHA1 etc ...
+ */
+ public PasswordDigester(String method) throws UserStoreException {
+ hashMethod = method;
+ validateHashAlgorithm();
+ }
+
+ /**
+ * Gets the hash value of a password.
+ *
+ * @param password
+ * Password.
+ * @return Hashed password.
+ * @throws UserStoreException
+ * If an invalid hash method is given.
+ */
+ public String getPasswordHashValue(String password) throws UserStoreException {
+
+ if (hashMethod.equals(SecurityUtil.PASSWORD_HASH_METHOD_PLAINTEXT)) {
+ return password;
+ } else {
+ MessageDigest messageDigest = null;
+ try {
+ messageDigest = MessageDigest.getInstance(hashMethod);
+ } catch (NoSuchAlgorithmException e) {
+ throw new UserStoreException("Error creating message digest with hash algorithm - " + hashMethod, e);
+ }
+ try {
+ return new String(messageDigest.digest(password.getBytes("UTF-8")));
+ } catch (UnsupportedEncodingException e) {
+ throw new UserStoreException("Unable to create password digest", e);
+ }
+ }
+
+ }
+
+ private void validateHashAlgorithm() throws UserStoreException {
+
+ if (hashMethod == null) {
+ log.warn("Password hash method is not configured. Setting default to plaintext.");
+ hashMethod = SecurityUtil.PASSWORD_HASH_METHOD_PLAINTEXT;
+ } else {
+
+ // Validating configured hash method is correct.
+ if (!hashMethod.equals(SecurityUtil.PASSWORD_HASH_METHOD_PLAINTEXT)) {
+ try {
+ MessageDigest.getInstance(hashMethod);
+ } catch (NoSuchAlgorithmException e) {
+ String msg = "Invalid hash algorithm - " + hashMethod
+ + ". Use Java style way of specifying hash algorithm. E.g :- MD5";
+ log.error(msg);
+ throw new UserStoreException(msg, e);
+ }
+ }
+ }
+
+ }
+
+ public String getHashMethod() {
+ return hashMethod;
+ }
+
+ public void setHashMethod(String hashMethod) {
+ this.hashMethod = hashMethod;
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/security/src/test/java/org/apache/airavata/security/configurations/AuthenticatorConfigurationReaderTest.java
----------------------------------------------------------------------
diff --git a/modules/security/src/test/java/org/apache/airavata/security/configurations/AuthenticatorConfigurationReaderTest.java b/modules/security/src/test/java/org/apache/airavata/security/configurations/AuthenticatorConfigurationReaderTest.java
new file mode 100644
index 0000000..d0f99ac
--- /dev/null
+++ b/modules/security/src/test/java/org/apache/airavata/security/configurations/AuthenticatorConfigurationReaderTest.java
@@ -0,0 +1,119 @@
+/*
+ *
+ * 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 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.net.URLDecoder;
+import java.util.List;
+
+/**
+ * A test class for authenticator configuration reader. Reads the authenticators.xml in resources directory.
+ */
+public class AuthenticatorConfigurationReaderTest extends TestCase {
+
+ private String configurationFile = URLDecoder.decode(this.getClass().getClassLoader()
+ .getResource("authenticators.xml").getFile());
+
+ public void setUp() throws Exception {
+
+ File f = new File(".");
+ System.out.println(f.getAbsolutePath());
+
+ File file = new File(configurationFile);
+
+ if (!file.exists() && !file.canRead()) {
+ throw new Exception("Error reading configuration file " + configurationFile);
+
+ }
+ }
+
+ public void testInit() throws Exception {
+
+ AuthenticatorConfigurationReader authenticatorConfigurationReader = new AuthenticatorConfigurationReader();
+ authenticatorConfigurationReader.init(configurationFile);
+
+ assertTrue(AuthenticatorConfigurationReader.isAuthenticationEnabled());
+
+ List<Authenticator> authenticators = authenticatorConfigurationReader.getAuthenticatorList();
+
+ assertEquals(authenticators.size(), 3);
+
+ for (Authenticator authenticator : authenticators) {
+ if (authenticator instanceof TestDBAuthenticator1) {
+ assertEquals("dbAuthenticator1", authenticator.getAuthenticatorName());
+ assertEquals(6, authenticator.getPriority());
+ assertEquals(true, authenticator.isEnabled());
+ assertEquals("jdbc:sql:thin:@//myhost:1521/mysql1",
+ ((TestDBAuthenticator1) authenticator).getDatabaseURL());
+ assertEquals("org.apache.derby.jdbc.ClientDriver", ((TestDBAuthenticator1) authenticator).getDatabaseDriver());
+ assertEquals("mysql1", ((TestDBAuthenticator1) authenticator).getDatabaseUserName());
+ assertEquals("secret1", ((TestDBAuthenticator1) authenticator).getDatabasePassword());
+ assertNotNull(authenticator.getUserStore());
+ assertTrue(authenticator.getUserStore() instanceof JDBCUserStore);
+
+ JDBCUserStore jdbcUserStore = (JDBCUserStore) authenticator.getUserStore();
+ assertEquals("MD5", jdbcUserStore.getPasswordDigester().getHashMethod());
+ } else if (authenticator instanceof TestDBAuthenticator2) {
+ assertEquals("dbAuthenticator2", authenticator.getAuthenticatorName());
+ assertEquals(7, authenticator.getPriority());
+ assertEquals(true, authenticator.isEnabled());
+ assertTrue(authenticator.getUserStore() instanceof LDAPUserStore);
+
+ } else if (authenticator instanceof TestDBAuthenticator3) {
+ assertEquals("dbAuthenticator3", authenticator.getAuthenticatorName());
+ assertEquals(8, authenticator.getPriority());
+ assertEquals(true, authenticator.isEnabled());
+ assertEquals("jdbc:sql:thin:@//myhost:1521/mysql3",
+ ((TestDBAuthenticator3) authenticator).getDatabaseURL());
+ assertEquals("org.apache.derby.jdbc.ClientDriver", ((TestDBAuthenticator3) authenticator).getDatabaseDriver());
+ assertEquals("mysql3", ((TestDBAuthenticator3) authenticator).getDatabaseUserName());
+ assertEquals("secret3", ((TestDBAuthenticator3) authenticator).getDatabasePassword());
+ assertNotNull(authenticator.getUserStore());
+ assertTrue(authenticator.getUserStore() instanceof JDBCUserStore);
+
+ }
+ }
+
+ assertEquals(8, authenticators.get(0).getPriority());
+ assertEquals(7, authenticators.get(1).getPriority());
+ assertEquals(6, authenticators.get(2).getPriority());
+
+ }
+
+ public void testDisabledAuthenticator() throws Exception {
+
+ String disabledConfiguration = URLDecoder.decode(this.getClass().getClassLoader()
+ .getResource("disabled-authenticator.xml").getFile());
+
+ AuthenticatorConfigurationReader authenticatorConfigurationReader = new AuthenticatorConfigurationReader();
+ authenticatorConfigurationReader.init(disabledConfiguration);
+
+ assertFalse(AuthenticatorConfigurationReader.isAuthenticationEnabled());
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/security/src/test/java/org/apache/airavata/security/configurations/TestDBAuthenticator1.java
----------------------------------------------------------------------
diff --git a/modules/security/src/test/java/org/apache/airavata/security/configurations/TestDBAuthenticator1.java b/modules/security/src/test/java/org/apache/airavata/security/configurations/TestDBAuthenticator1.java
new file mode 100644
index 0000000..00712c0
--- /dev/null
+++ b/modules/security/src/test/java/org/apache/airavata/security/configurations/TestDBAuthenticator1.java
@@ -0,0 +1,57 @@
+/*
+ *
+ * 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.AbstractDatabaseAuthenticator;
+import org.apache.airavata.security.AuthenticationException;
+
+public class TestDBAuthenticator1 extends AbstractDatabaseAuthenticator {
+
+ public TestDBAuthenticator1() {
+ super();
+ }
+
+ @Override
+ public void onSuccessfulAuthentication(Object authenticationInfo) {
+ // To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public void onFailedAuthentication(Object authenticationInfo) {
+ // To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public boolean authenticate(Object credentials) throws AuthenticationException {
+ return false; // To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ protected boolean doAuthentication(Object credentials) throws AuthenticationException {
+ return false; // To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public boolean isAuthenticated(Object credentials) {
+ return false; // To change body of implemented methods use File | Settings | File Templates.
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/security/src/test/java/org/apache/airavata/security/configurations/TestDBAuthenticator2.java
----------------------------------------------------------------------
diff --git a/modules/security/src/test/java/org/apache/airavata/security/configurations/TestDBAuthenticator2.java b/modules/security/src/test/java/org/apache/airavata/security/configurations/TestDBAuthenticator2.java
new file mode 100644
index 0000000..75f45c4
--- /dev/null
+++ b/modules/security/src/test/java/org/apache/airavata/security/configurations/TestDBAuthenticator2.java
@@ -0,0 +1,58 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.security.configurations;
+
+import org.apache.airavata.security.AbstractAuthenticator;
+import org.apache.airavata.security.AuthenticationException;
+import org.w3c.dom.Node;
+
+public class TestDBAuthenticator2 extends AbstractAuthenticator {
+
+ public TestDBAuthenticator2() {
+ super();
+ }
+
+ @Override
+ protected boolean doAuthentication(Object credentials) throws AuthenticationException {
+ return false; // To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public void onSuccessfulAuthentication(Object authenticationInfo) {
+ // To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public void onFailedAuthentication(Object authenticationInfo) {
+ // To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public boolean isAuthenticated(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.
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/security/src/test/java/org/apache/airavata/security/configurations/TestDBAuthenticator3.java
----------------------------------------------------------------------
diff --git a/modules/security/src/test/java/org/apache/airavata/security/configurations/TestDBAuthenticator3.java b/modules/security/src/test/java/org/apache/airavata/security/configurations/TestDBAuthenticator3.java
new file mode 100644
index 0000000..7523835
--- /dev/null
+++ b/modules/security/src/test/java/org/apache/airavata/security/configurations/TestDBAuthenticator3.java
@@ -0,0 +1,57 @@
+/*
+ *
+ * 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.AbstractDatabaseAuthenticator;
+import org.apache.airavata.security.AuthenticationException;
+
+public class TestDBAuthenticator3 extends AbstractDatabaseAuthenticator {
+
+ public TestDBAuthenticator3() {
+ super();
+ }
+
+ @Override
+ public void onSuccessfulAuthentication(Object authenticationInfo) {
+ // To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public void onFailedAuthentication(Object authenticationInfo) {
+ // To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public boolean authenticate(Object credentials) throws AuthenticationException {
+ return false; // To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ protected boolean doAuthentication(Object credentials) throws AuthenticationException {
+ return false; // To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public boolean isAuthenticated(Object credentials) {
+ return false; // To change body of implemented methods use File | Settings | File Templates.
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/security/src/test/java/org/apache/airavata/security/configurations/TestUserStore.java
----------------------------------------------------------------------
diff --git a/modules/security/src/test/java/org/apache/airavata/security/configurations/TestUserStore.java b/modules/security/src/test/java/org/apache/airavata/security/configurations/TestUserStore.java
new file mode 100644
index 0000000..a16c0ac
--- /dev/null
+++ b/modules/security/src/test/java/org/apache/airavata/security/configurations/TestUserStore.java
@@ -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.
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/security/src/test/java/org/apache/airavata/security/userstore/JDBCUserStoreTest.java
----------------------------------------------------------------------
diff --git a/modules/security/src/test/java/org/apache/airavata/security/userstore/JDBCUserStoreTest.java b/modules/security/src/test/java/org/apache/airavata/security/userstore/JDBCUserStoreTest.java
new file mode 100644
index 0000000..65bb924
--- /dev/null
+++ b/modules/security/src/test/java/org/apache/airavata/security/userstore/JDBCUserStoreTest.java
@@ -0,0 +1,106 @@
+/*
+ *
+ * *
+ * * 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.common.utils.DatabaseTestCases;
+import org.apache.airavata.common.utils.DerbyUtil;
+import org.apache.airavata.security.UserStore;
+import org.junit.*;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+/**
+ * Test class for JDBC user store.
+ */
+public class JDBCUserStoreTest extends DatabaseTestCases {
+
+ /**
+ * <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
+ */
+
+
+ @BeforeClass
+ public static void setUpDatabase() throws Exception{
+ DerbyUtil.startDerbyInServerMode(getHostAddress(), getPort(), getUserName(), getPassword());
+
+ waitTillServerStarts();
+
+ String dropTable = "drop table AIRAVATA_USER";
+
+ try {
+ executeSQL(dropTable);
+ } catch (Exception e) {
+ }
+
+ String createTable = "create table AIRAVATA_USER ( USERID varchar(255), PASSWORD varchar(255) )";
+ executeSQL(createTable);
+
+ String insertSQL = "INSERT INTO AIRAVATA_USER VALUES('amilaj', 'secret')";
+ executeSQL(insertSQL);
+
+
+ }
+
+ @AfterClass
+ public static void shutDownDatabase() throws Exception {
+ DerbyUtil.stopDerbyServer();
+ }
+
+ @Before
+ public void setUp() throws Exception{
+ }
+
+ @Test
+ 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));
+
+ Assert.assertTrue(userStore.authenticate("amilaj", "secret"));
+ Assert.assertFalse(userStore.authenticate("amilaj", "1secret"));
+ Assert.assertFalse(userStore.authenticate("lahiru", "1234"));
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/security/src/test/java/org/apache/airavata/security/userstore/LDAPUserStoreTest.java
----------------------------------------------------------------------
diff --git a/modules/security/src/test/java/org/apache/airavata/security/userstore/LDAPUserStoreTest.java b/modules/security/src/test/java/org/apache/airavata/security/userstore/LDAPUserStoreTest.java
new file mode 100644
index 0000000..5749d8a
--- /dev/null
+++ b/modules/security/src/test/java/org/apache/airavata/security/userstore/LDAPUserStoreTest.java
@@ -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"));
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/security/src/test/java/org/apache/airavata/security/userstore/SessionDBUserStoreTest.java
----------------------------------------------------------------------
diff --git a/modules/security/src/test/java/org/apache/airavata/security/userstore/SessionDBUserStoreTest.java b/modules/security/src/test/java/org/apache/airavata/security/userstore/SessionDBUserStoreTest.java
new file mode 100644
index 0000000..9059c9a
--- /dev/null
+++ b/modules/security/src/test/java/org/apache/airavata/security/userstore/SessionDBUserStoreTest.java
@@ -0,0 +1,101 @@
+/*
+ *
+ * *
+ * * 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.common.utils.DatabaseTestCases;
+import org.apache.airavata.common.utils.DerbyUtil;
+import org.junit.*;
+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 DatabaseTestCases {
+
+ @BeforeClass
+ public static void setUpDatabase() throws Exception{
+ DerbyUtil.startDerbyInServerMode(getHostAddress(), getPort(), getUserName(), getPassword());
+
+ waitTillServerStarts();
+
+ String dropTable = "drop table Persons";
+
+ try {
+ executeSQL(dropTable);
+ } catch (Exception e) {
+ }
+
+ String createTable = "create table Persons ( sessionId varchar(255) )";
+ executeSQL(createTable);
+
+ String insertSQL = "INSERT INTO Persons VALUES('1234')";
+ executeSQL(insertSQL);
+ }
+
+ @AfterClass
+ public static void shutDownDatabase() throws Exception {
+ DerbyUtil.stopDerbyServer();
+ }
+
+ @Before
+ public void setUp() throws Exception{
+
+ loadConfigurations();
+
+ }
+
+ private SessionDBUserStore sessionDBUserStore = new SessionDBUserStore();
+
+ private InputStream configurationFileStream
+ = this.getClass().getClassLoader().getResourceAsStream("session-authenticator.xml");
+
+ private void loadConfigurations () 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));
+ }
+
+ @Test
+ public void testAuthenticate() throws Exception {
+ Assert.assertTrue(sessionDBUserStore.authenticate("1234"));
+
+ }
+
+ @Test
+ public void testAuthenticateFailure() throws Exception {
+ Assert.assertFalse(sessionDBUserStore.authenticate("12345"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/security/src/test/resources/authenticators.xml
----------------------------------------------------------------------
diff --git a/modules/security/src/test/resources/authenticators.xml b/modules/security/src/test/resources/authenticators.xml
new file mode 100644
index 0000000..46d71cd
--- /dev/null
+++ b/modules/security/src/test/resources/authenticators.xml
@@ -0,0 +1,88 @@
+<?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. -->
+
+<!--
+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>
+ <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>
+ <passwordHashMethod>MD5</passwordHashMethod>
+ <databaseDriver>org.apache.derby.jdbc.ClientDriver</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>
+ <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>
+
+ <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.apache.derby.jdbc.ClientDriver</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.apache.derby.jdbc.ClientDriver</databaseDriver>
+ <sessionTable>Session3</sessionTable>
+ <sessionColumn>sessioncolumn3</sessionColumn>
+ <comparingColumn>comparecolumn3</comparingColumn>
+ </database>
+ </specificConfigurations>
+ </authenticator>
+
+</authenticators>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/security/src/test/resources/disabled-authenticator.xml
----------------------------------------------------------------------
diff --git a/modules/security/src/test/resources/disabled-authenticator.xml b/modules/security/src/test/resources/disabled-authenticator.xml
new file mode 100644
index 0000000..627ba57
--- /dev/null
+++ b/modules/security/src/test/resources/disabled-authenticator.xml
@@ -0,0 +1,84 @@
+<?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. -->
+
+<!--
+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.apache.derby.jdbc.ClientDriver</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.JDBCUserStore">
+ <specificConfigurations>
+ <database>
+ <jdbcUrl>jdbc:sql:thin:@//myhost:1521/mysql2</jdbcUrl>
+ <userName>mysql2</userName>
+ <password>secret2</password>
+ <databaseDriver>org.apache.derby.jdbc.ClientDriver</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.apache.derby.jdbc.ClientDriver</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.apache.derby.jdbc.ClientDriver</databaseDriver>
+ <sessionTable>Session3</sessionTable>
+ <sessionColumn>sessioncolumn3</sessionColumn>
+ <comparingColumn>comparecolumn3</comparingColumn>
+ </database>
+ </specificConfigurations>
+ </authenticator>
+
+</authenticators>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/security/src/test/resources/jdbc-authenticator.xml
----------------------------------------------------------------------
diff --git a/modules/security/src/test/resources/jdbc-authenticator.xml b/modules/security/src/test/resources/jdbc-authenticator.xml
new file mode 100644
index 0000000..c27b60f
--- /dev/null
+++ b/modules/security/src/test/resources/jdbc-authenticator.xml
@@ -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:derby://localhost:20000/persistent_data;create=true</jdbcUrl>
+ <userName>admin</userName>
+ <password>admin</password>
+ <databaseDriver>org.apache.derby.jdbc.ClientDriver</databaseDriver>
+ <userTableName>AIRAVATA_USER</userTableName>
+ <userNameColumnName>USERID</userNameColumnName>
+ <passwordColumnName>PASSWORD</passwordColumnName>
+ </database>
+ </specificConfigurations>
+ </authenticator>
+</authenticators>
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/security/src/test/resources/ldap-authenticator.xml
----------------------------------------------------------------------
diff --git a/modules/security/src/test/resources/ldap-authenticator.xml b/modules/security/src/test/resources/ldap-authenticator.xml
new file mode 100644
index 0000000..651920f
--- /dev/null
+++ b/modules/security/src/test/resources/ldap-authenticator.xml
@@ -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.LDAPUserStore">
+ <specificConfigurations>
+ <ldap>
+ <!--
+ url - The URL which LDAP server is listening for requests
+ systemUser - The DN of the LDAP server connection user
+ systemUserPassword - The password of the LDAP server connection user
+ userDNTemplate - The DN structure of the users in LDAP
+ -->
+ <url>ldap://localhost:10389</url>
+ <systemUser>admin</systemUser>
+ <systemUserPassword>secret</systemUserPassword>
+ <userDNTemplate>uid={0},ou=system</userDNTemplate>
+ </ldap>
+ </specificConfigurations>
+ </authenticator>
+</authenticators>
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/security/src/test/resources/session-authenticator.xml
----------------------------------------------------------------------
diff --git a/modules/security/src/test/resources/session-authenticator.xml b/modules/security/src/test/resources/session-authenticator.xml
new file mode 100644
index 0000000..670913e
--- /dev/null
+++ b/modules/security/src/test/resources/session-authenticator.xml
@@ -0,0 +1,45 @@
+<!--
+ ~ /*
+ ~ *
+ ~ * 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:derby://localhost:20000/persistent_data;create=true</jdbcUrl>
+
+ <!--jdbcUrl>jdbc:h2:modules/security/src/test/resources/testdb/test</jdbcUrl-->
+
+ <userName>admin</userName>
+ <password>admin</password>
+ <databaseDriver>org.apache.derby.jdbc.ClientDriver</databaseDriver>
+ <sessionTable>Persons</sessionTable>
+ <sessionColumn>sessionId</sessionColumn>
+ <comparingColumn>sessionId</comparingColumn>
+ </database>
+ </specificConfigurations>
+ </authenticator>
+ </authenticators>
+
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/ws-messenger/messagebox/maven-eclipse.xml
----------------------------------------------------------------------
diff --git a/modules/ws-messenger/messagebox/maven-eclipse.xml b/modules/ws-messenger/messagebox/maven-eclipse.xml
new file mode 100644
index 0000000..3f67e06
--- /dev/null
+++ b/modules/ws-messenger/messagebox/maven-eclipse.xml
@@ -0,0 +1,16 @@
+<!--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 default="copy-resources">
+ <target name="init"/>
+ <target name="copy-resources" depends="init">
+ <copy todir="target/classes/META-INF" filtering="false">
+ <fileset dir="resources" includes="**/*.wsdl|**/*.xml" excludes="**/*.java"/>
+ </copy>
+ </target>
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/ws-messenger/messagebox/pom.xml
----------------------------------------------------------------------
diff --git a/modules/ws-messenger/messagebox/pom.xml b/modules/ws-messenger/messagebox/pom.xml
new file mode 100644
index 0000000..c1a83e5
--- /dev/null
+++ b/modules/ws-messenger/messagebox/pom.xml
@@ -0,0 +1,100 @@
+<?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. -->
+
+<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">
+
+ <parent>
+ <groupId>org.apache.airavata</groupId>
+ <artifactId>airavata-ws-messenger</artifactId>
+ <version>0.12-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>airavata-message-box</artifactId>
+ <packaging>jar</packaging>
+ <name>Airavata Message Box</name>
+ <url>http://airavata.apache.org/</url>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.airavata</groupId>
+ <artifactId>airavata-messenger-commons</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.airavata</groupId>
+ <artifactId>airavata-client-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.airavata</groupId>
+ <artifactId>airavata-common-utils</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <!-- Logging -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+
+ <!-- Test -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.airavata</groupId>
+ <artifactId>airavata-messenger-client</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.airavata</groupId>
+ <artifactId>airavata-server-configuration</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <!-- Axis2 for test only -->
+ <dependency>
+ <groupId>org.apache.axis2</groupId>
+ <artifactId>axis2-transport-http</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.axis2</groupId>
+ <artifactId>axis2-transport-local</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <defaultGoal>install</defaultGoal>
+ <plugins>
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <version>${antrun.version}</version><!--$NO-MVN-MAN-VER$-->
+ <executions>
+ <execution>
+ <id>restore-persistence</id>
+ <phase>prepare-package</phase>
+ <configuration>
+ <tasks>
+ <copy file="${project.build.outputDirectory}/services.xml" tofile="${project.build.outputDirectory}/META-INF/services.xml" />
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/ws-messenger/messagebox/src/main/java/org/apache/airavata/wsmg/msgbox/MsgBoxServiceLifeCycle.java
----------------------------------------------------------------------
diff --git a/modules/ws-messenger/messagebox/src/main/java/org/apache/airavata/wsmg/msgbox/MsgBoxServiceLifeCycle.java b/modules/ws-messenger/messagebox/src/main/java/org/apache/airavata/wsmg/msgbox/MsgBoxServiceLifeCycle.java
new file mode 100644
index 0000000..f0a62b4
--- /dev/null
+++ b/modules/ws-messenger/messagebox/src/main/java/org/apache/airavata/wsmg/msgbox/MsgBoxServiceLifeCycle.java
@@ -0,0 +1,192 @@
+/*
+ *
+ * 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.wsmg.msgbox;
+
+import java.net.URI;
+
+import org.apache.airavata.client.AiravataAPIFactory;
+import org.apache.airavata.client.api.AiravataAPI;
+import org.apache.airavata.client.api.exception.AiravataAPIInvocationException;
+import org.apache.airavata.client.tools.PeriodicExecutorThread;
+import org.apache.airavata.common.utils.AiravataUtils;
+import org.apache.airavata.common.utils.ServerSettings;
+import org.apache.airavata.common.utils.ServiceUtils;
+import org.apache.airavata.wsmg.commons.config.ConfigurationManager;
+import org.apache.airavata.wsmg.commons.util.Axis2Utils;
+import org.apache.airavata.wsmg.msgbox.Storage.MsgBoxStorage;
+import org.apache.airavata.wsmg.msgbox.Storage.dbpool.DatabaseStorageImpl;
+import org.apache.airavata.wsmg.msgbox.Storage.memory.InMemoryImpl;
+import org.apache.airavata.wsmg.msgbox.util.ConfigKeys;
+import org.apache.airavata.wsmg.msgbox.util.MsgBoxCommonConstants;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.engine.ServiceLifeCycle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class initialize the messageBox service by setting the messageStore based on the configuration done by the user
+ * This is the LifeCycle class
+ */
+public class MsgBoxServiceLifeCycle implements ServiceLifeCycle {
+
+ private static final Logger logger = LoggerFactory.getLogger(MsgBoxServiceLifeCycle.class);
+// private static final String CONFIGURATION_FILE_NAME = "airavata-server.properties";
+ private static final String TRUE = Boolean.toString(true);
+// public static final String REPOSITORY_PROPERTIES = "airavata-server.properties";
+ public static final int GFAC_URL_UPDATE_INTERVAL = 1000 * 60 * 60 * 3;
+
+ public static final int JCR_AVAIALABILITY_WAIT_INTERVAL = 1000 * 10;
+ public static final String JCR_CLASS = "jcr.class";
+ public static final String JCR_USER = "jcr.user";
+ public static final String JCR_PASS = "jcr.pass";
+ public static final String ORG_APACHE_JACKRABBIT_REPOSITORY_URI = "org.apache.jackrabbit.repository.uri";
+ private static final String MESSAGE_BOX_SERVICE_NAME = "MsgBoxService";
+ private static final String SERVICE_URL = "message_box_service_url";
+ private static final String JCR_REGISTRY = "registry";
+ private Thread thread;
+
+ public void shutDown(ConfigurationContext configurationcontext, AxisService axisservice) {
+ logger.info("Message box shutting down");
+ AiravataAPI registry = (AiravataAPI) configurationcontext.getProperty(JCR_REGISTRY);
+ if (registry != null && thread != null) {
+ try {
+ registry.getAiravataManager().unsetMessageBoxURI();
+ } catch (AiravataAPIInvocationException e) {
+ e.printStackTrace();
+ }
+ thread.interrupt();
+ try {
+ thread.join();
+ } catch (InterruptedException e) {
+ logger.info("Message box url update thread is interrupted");
+ }
+ }
+ if (configurationcontext.getProperty(MsgBoxCommonConstants.MSGBOX_STORAGE) != null) {
+ MsgBoxStorage msgBoxStorage = (MsgBoxStorage) configurationcontext
+ .getProperty(MsgBoxCommonConstants.MSGBOX_STORAGE);
+ msgBoxStorage.dispose();
+ }
+ }
+
+ public void startUp(ConfigurationContext configurationcontext, AxisService axisservice) {
+ AiravataUtils.setExecutionAsServer();
+ Axis2Utils.overrideAddressingPhaseHander(configurationcontext, new StoreMessageHandler());
+
+ // Load the configuration file from the classpath
+ ConfigurationManager confmanager = new ConfigurationManager();
+ initDatabase(configurationcontext, confmanager);
+ configurationcontext.setProperty(ConfigKeys.MSG_PRESV_INTERVAL,getIntervaltoExecuteDelete(confmanager));
+ final ConfigurationContext context=configurationcontext;
+ new Thread(){
+ @Override
+ public void run() {
+// Properties properties = new Properties();
+ try {
+// URL url = this.getClass().getClassLoader().getResource(REPOSITORY_PROPERTIES);
+// properties.load(url.openStream());
+// Map<String, String> map = new HashMap<String, String>((Map) properties);
+ try {
+ Thread.sleep(JCR_AVAIALABILITY_WAIT_INTERVAL);
+ } catch (InterruptedException e1) {
+ e1.printStackTrace();
+ }
+
+ String userName = ServerSettings.getSystemUser();
+ String gateway = ServerSettings.getSystemUserGateway();
+
+ AiravataAPI airavataAPI = AiravataAPIFactory.getAPI(gateway, userName);
+ String localAddress = ServiceUtils.generateServiceURLFromConfigurationContext(context, MESSAGE_BOX_SERVICE_NAME);
+ logger.debug("MESSAGE BOX SERVICE_ADDRESS:" + localAddress);
+ context.setProperty(SERVICE_URL,new URI(localAddress));
+ context.setProperty(JCR_REGISTRY,airavataAPI);
+ /*
+ * Heart beat message to registry
+ */
+ thread = new MsgBoxURLRegisterThread(airavataAPI, context);
+ thread.start();
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+ }.start();
+ }
+
+ public void initDatabase(ConfigurationContext configurationcontext, ConfigurationManager confmanager) {
+ /*
+ * Determine Storage
+ */
+ String useDatabase = confmanager.getConfig(ConfigKeys.USE_DATABASE_STORAGE, TRUE);
+ MsgBoxStorage msgBoxStorage = null;
+ long time = getInterval(confmanager);
+ if (useDatabase.equalsIgnoreCase(TRUE)) {
+ String jdbcUrl = confmanager.getConfig(ConfigKeys.MSG_BOX_JDBC_URL);
+ String jdbcDriver = confmanager.getConfig(ConfigKeys.MSG_BOX_JDBC_DRIVER);
+ msgBoxStorage = new DatabaseStorageImpl(jdbcUrl, jdbcDriver, time);
+ } else {
+ msgBoxStorage = new InMemoryImpl(time);
+ }
+ configurationcontext.setProperty(MsgBoxCommonConstants.MSGBOX_STORAGE, msgBoxStorage);
+
+ }
+
+ private long getInterval(ConfigurationManager configs) {
+ int messagePreservationDays = configs.getConfig(ConfigKeys.MSG_PRESV_DAYS, 2);
+ int messagePreservationHours = configs.getConfig(ConfigKeys.MSG_PRESV_HRS, 0);
+ int messagePreservationMinutes = configs.getConfig(ConfigKeys.MSG_PRESV_MINS, 0);
+
+ long interval = messagePreservationDays * 24l;
+ interval = (interval + messagePreservationHours) * 60;
+ interval = (interval + messagePreservationMinutes) * 60;
+ interval = interval * 1000;
+ return interval;
+ }
+
+ private long getIntervaltoExecuteDelete(ConfigurationManager configs) {
+ int messagePreservationDays = configs.getConfig(ConfigKeys.MSG_PRESV_INTERVAL_DAYS, 0);
+ int messagePreservationHours = configs.getConfig(ConfigKeys.MSG_PRESV_INTERVAL_HRS, 0);
+ int messagePreservationMinutes = configs.getConfig(ConfigKeys.MSG_PRESV_INTERVAL_MINS, 5);
+
+ long interval = messagePreservationDays * 24l;
+ interval = (interval + messagePreservationHours) * 60;
+ interval = (interval + messagePreservationMinutes) * 60;
+ interval = interval * 1000;
+ return interval;
+ }
+
+ class MsgBoxURLRegisterThread extends PeriodicExecutorThread {
+ private ConfigurationContext context = null;
+
+ MsgBoxURLRegisterThread(AiravataAPI registry, ConfigurationContext context) {
+ super(registry);
+ this.context = context;
+ }
+
+ @Override
+ protected void updateRegistry(AiravataAPI registry) throws Exception {
+ URI localAddress = (URI) this.context.getProperty(SERVICE_URL);
+ registry.getAiravataManager().setMessageBoxURI(localAddress);
+ logger.debug("Updated Message box service URL in to Repository");
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/ws-messenger/messagebox/src/main/java/org/apache/airavata/wsmg/msgbox/MsgBoxServiceMessageReceiverInOut.java
----------------------------------------------------------------------
diff --git a/modules/ws-messenger/messagebox/src/main/java/org/apache/airavata/wsmg/msgbox/MsgBoxServiceMessageReceiverInOut.java b/modules/ws-messenger/messagebox/src/main/java/org/apache/airavata/wsmg/msgbox/MsgBoxServiceMessageReceiverInOut.java
new file mode 100644
index 0000000..cf18f49
--- /dev/null
+++ b/modules/ws-messenger/messagebox/src/main/java/org/apache/airavata/wsmg/msgbox/MsgBoxServiceMessageReceiverInOut.java
@@ -0,0 +1,138 @@
+/*
+ *
+ * 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.wsmg.msgbox;
+
+import org.apache.airavata.wsmg.msgbox.util.MsgBoxOperations;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.receivers.AbstractInOutMessageReceiver;
+import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.axis2.util.JavaUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * MsgBoxServiceMessageReceiverInOut message receiver, this is the actual location where the service operations get
+ * invoked.
+ */
+
+public class MsgBoxServiceMessageReceiverInOut extends AbstractInOutMessageReceiver {
+
+ private static Logger logger = LoggerFactory.getLogger(MsgBoxServiceMessageReceiverInOut.class);
+
+ public void invokeBusinessLogic(MessageContext inMsgContext, MessageContext outMsgContext) throws AxisFault {
+
+ // get the implementation class for the Web Service
+ MsgBoxServiceSkeleton skel = (MsgBoxServiceSkeleton) getTheImplementationObject(inMsgContext);
+
+ OMElement response = null;
+
+ try {
+
+ String operationName = getOperationName(inMsgContext);
+ MsgBoxOperations msgType = MsgBoxOperations.valueFrom(operationName);
+
+ switch (msgType) {
+
+ case STORE_MSGS: {
+ SOAPEnvelope enlp = inMsgContext.getEnvelope();
+ OMElement message = enlp.getBody().getFirstElement();
+ String msgBoxId = getClientId(inMsgContext);
+ String messageId = inMsgContext.getMessageID();
+ String soapAction = inMsgContext.getSoapAction();
+ response = skel.storeMessages(msgBoxId, messageId, soapAction, message);
+ break;
+ }
+
+ case DESTROY_MSGBOX: {
+ String msgBoxId = getClientId(inMsgContext);
+ response = skel.destroyMsgBox(msgBoxId);
+ break;
+ }
+
+ case TAKE_MSGS: {
+ String msgBoxId = getClientId(inMsgContext);
+ response = skel.takeMessages(msgBoxId);
+ break;
+ }
+
+ case CREATE_MSGBOX: {
+ response = skel.createMsgBox();
+ break;
+ }
+ default:
+ throw new AxisFault("unsupported operation" + msgType.toString());
+ }
+
+ } catch (AxisFault afe) {
+ throw afe;
+ } catch (Exception e) {
+ logger.error("Exception", e);
+ throw new AxisFault("Exception in Message Box ", e);
+ }
+
+ /*
+ * Output
+ */
+ SOAPFactory soapFactory = getSOAPFactory(inMsgContext);
+ SOAPEnvelope envelope = toEnvelope(soapFactory, response);
+ outMsgContext.setEnvelope(envelope);
+ outMsgContext.getOptions().setProperty(HTTPConstants.CHUNKED, Boolean.FALSE);
+ }
+
+ private String getClientId(MessageContext inMsg) throws AxisFault {
+ String toAddress = inMsg.getTo().getAddress();
+ int biginIndex = toAddress.indexOf("clientid");
+ if (biginIndex == -1) {
+ throw new AxisFault("clientid cannot be found");
+ }
+ String clientId = toAddress.substring(biginIndex + "clientid".length() + 1);
+ return clientId;
+ }
+
+ private SOAPEnvelope toEnvelope(SOAPFactory factory, OMElement response) {
+ SOAPEnvelope envelop = factory.getDefaultEnvelope();
+ envelop.getBody().addChild(response);
+ return envelop;
+ }
+
+ protected String getOperationName(MessageContext inMsg) throws AxisFault {
+
+ AxisOperation op = inMsg.getOperationContext().getAxisOperation();
+ if (op == null) {
+ throw new AxisFault(
+ "Operation is not located, if this is doclit style the SOAP-ACTION should specified via the SOAP Action to use the RawXMLProvider");
+ }
+
+ String operationName = null;
+ if ((op.getName() == null) || ((operationName = JavaUtils.xmlNameToJava(op.getName().getLocalPart())) == null)) {
+ throw new AxisFault("invalid operation found");
+ }
+
+ return operationName;
+ }
+
+}