Return-Path: X-Original-To: apmail-airavata-commits-archive@www.apache.org Delivered-To: apmail-airavata-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 50829D161 for ; Wed, 14 Nov 2012 21:23:38 +0000 (UTC) Received: (qmail 89995 invoked by uid 500); 14 Nov 2012 21:23:38 -0000 Delivered-To: apmail-airavata-commits-archive@airavata.apache.org Received: (qmail 89962 invoked by uid 500); 14 Nov 2012 21:23:38 -0000 Mailing-List: contact commits-help@airavata.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@airavata.apache.org Delivered-To: mailing list commits@airavata.apache.org Received: (qmail 89953 invoked by uid 99); 14 Nov 2012 21:23:38 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Nov 2012 21:23:38 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Nov 2012 21:23:34 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 19DE42388900 for ; Wed, 14 Nov 2012 21:23:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1409413 - in /airavata/trunk/modules/airavata-rest-services/src: main/java/org/apache/airavata/services/registry/rest/security/ main/java/org/apache/airavata/services/registry/rest/security/basic/ main/java/org/apache/airavata/services/reg... Date: Wed, 14 Nov 2012 21:23:13 -0000 To: commits@airavata.apache.org From: lahiru@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121114212314.19DE42388900@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: lahiru Date: Wed Nov 14 21:23:10 2012 New Revision: 1409413 URL: http://svn.apache.org/viewvc?rev=1409413&view=rev Log: adding amila's commit for issue https://issues.apache.org/jira/browse/AIRAVATA-560. Added: airavata/trunk/modules/airavata-rest-services/src/main/java/org/apache/airavata/services/registry/rest/security/ airavata/trunk/modules/airavata-rest-services/src/main/java/org/apache/airavata/services/registry/rest/security/HttpAuthenticatorFilter.java airavata/trunk/modules/airavata-rest-services/src/main/java/org/apache/airavata/services/registry/rest/security/basic/ airavata/trunk/modules/airavata-rest-services/src/main/java/org/apache/airavata/services/registry/rest/security/basic/BasicAccessAuthenticator.java airavata/trunk/modules/airavata-rest-services/src/main/java/org/apache/airavata/services/registry/rest/security/session/ airavata/trunk/modules/airavata-rest-services/src/main/java/org/apache/airavata/services/registry/rest/security/session/SessionAuthenticator.java airavata/trunk/modules/airavata-rest-services/src/main/resources/authenticators.xml airavata/trunk/modules/airavata-rest-services/src/test/java/ airavata/trunk/modules/airavata-rest-services/src/test/java/org/ airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/ airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/ airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/ airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/configurations/ airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/configurations/AuthenticatorConfigurationReaderTest.java airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/configurations/TestDBAuthenticator1.java airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/configurations/TestDBAuthenticator2.java airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/configurations/TestDBAuthenticator3.java airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/configurations/TestUserStore.java airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/userstore/ airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/userstore/JDBCUserStoreTest.java airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/userstore/LDAPUserStoreTest.java airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/userstore/SessionDBUserStoreTest.java airavata/trunk/modules/airavata-rest-services/src/test/resources/authenticators.xml airavata/trunk/modules/airavata-rest-services/src/test/resources/disabled-authenticator.xml airavata/trunk/modules/airavata-rest-services/src/test/resources/jdbc-authenticator.xml airavata/trunk/modules/airavata-rest-services/src/test/resources/ldap-authenticator.xml airavata/trunk/modules/airavata-rest-services/src/test/resources/session-authenticator.xml airavata/trunk/modules/airavata-rest-services/src/test/resources/testdb/ airavata/trunk/modules/airavata-rest-services/src/test/resources/testdb/test/ airavata/trunk/modules/airavata-rest-services/src/test/resources/testdb/test.h2.db (with props) airavata/trunk/modules/airavata-rest-services/src/test/resources/testdb/test.trace.db airavata/trunk/modules/airavata-rest-services/src/test/resources/testdb/test/test.trace.db Added: airavata/trunk/modules/airavata-rest-services/src/main/java/org/apache/airavata/services/registry/rest/security/HttpAuthenticatorFilter.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-rest-services/src/main/java/org/apache/airavata/services/registry/rest/security/HttpAuthenticatorFilter.java?rev=1409413&view=auto ============================================================================== --- airavata/trunk/modules/airavata-rest-services/src/main/java/org/apache/airavata/services/registry/rest/security/HttpAuthenticatorFilter.java (added) +++ airavata/trunk/modules/airavata-rest-services/src/main/java/org/apache/airavata/services/registry/rest/security/HttpAuthenticatorFilter.java Wed Nov 14 21:23:10 2012 @@ -0,0 +1,182 @@ +/* + * 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.services.registry.rest.security; + +import org.apache.airavata.security.AuthenticationException; +import org.apache.airavata.security.Authenticator; +import org.apache.airavata.security.configurations.AuthenticatorConfigurationReader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.xml.sax.SAXException; + +import javax.servlet.*; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.parsers.ParserConfigurationException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Calendar; +import java.util.List; + +/** + * A servlet filter class which intercepts the request and do authentication. + */ +public class HttpAuthenticatorFilter implements Filter { + + private List authenticatorList; + + private static Logger log = LoggerFactory.getLogger(HttpAuthenticatorFilter.class); + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + String authenticatorConfiguration = filterConfig.getInitParameter("authenticatorConfigurations"); + + //TODO make this able to read from a file as well + + + InputStream configurationFileStream = HttpAuthenticatorFilter.class.getClassLoader(). + getResourceAsStream(authenticatorConfiguration); + + if (configurationFileStream == null) { + String msg = "Invalid authenticator configuration. Cannot read file - ".concat(authenticatorConfiguration); + log.error(msg); + throw new ServletException(msg); + } + + AuthenticatorConfigurationReader authenticatorConfigurationReader + = new AuthenticatorConfigurationReader(); + try { + authenticatorConfigurationReader.init(configurationFileStream); + } catch (IOException e) { + String msg = "Error reading authenticator configurations."; + + log.error(msg, e); + throw new ServletException(msg, e); + } catch (ParserConfigurationException e) { + String msg = "Error parsing authenticator configurations."; + + log.error(msg, e); + throw new ServletException(msg, e); + } catch (SAXException e) { + String msg = "Error parsing authenticator configurations."; + + log.error(msg, e); + throw new ServletException(msg, e); + } finally { + try { + configurationFileStream.close(); + } catch (IOException e) { + log.error("Error closing authenticator file stream.", e); + } + } + + this.authenticatorList = authenticatorConfigurationReader.getAuthenticatorList(); + + if (this.authenticatorList.isEmpty()) { + String msg = "No authenticators registered in the system. System cannot function without authenticators"; + log.error(msg); + throw new ServletException(msg); + } + + } + + @Override + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { + + // Firs check whether authenticators are disabled + if (! AuthenticatorConfigurationReader.isAuthenticationEnabled()) { + filterChain.doFilter(servletRequest, servletResponse); + return; + } + + HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest; + + Authenticator authenticator = getAuthenticator(httpServletRequest); + + if (authenticator == null) { + //sendUnauthorisedError(servletResponse, "Invalid request. Request does not contain sufficient credentials to authenticate"); + populateUnauthorisedData(servletResponse, "Invalid request. Request does not contain sufficient credentials to authenticate"); + } else { + if (authenticator.isAuthenticated(httpServletRequest)) { + // Allow request to flow + filterChain.doFilter(servletRequest, servletResponse); + } else { + try { + if (!authenticator.authenticate(httpServletRequest)) { + //sendUnauthorisedError(servletResponse, "Unauthorised : Provided credentials are not valid."); + populateUnauthorisedData(servletResponse, "Invalid request. Request does not contain sufficient credentials to authenticate"); + } else { + // Allow request to flow + filterChain.doFilter(servletRequest, servletResponse); + } + } catch (AuthenticationException e) { + String msg = "An error occurred while authenticating request."; + log.error(msg, e); + //sendUnauthorisedError(servletResponse, e.getMessage()); + populateUnauthorisedData(servletResponse, "Invalid request. Request does not contain sufficient credentials to authenticate"); + } + } + } + } + + protected void sendUnauthorisedError(ServletResponse servletResponse, String message) throws IOException { + HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse; + httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, message); + } + + @Override + public void destroy() { + if (this.authenticatorList != null) { + this.authenticatorList.clear(); + } + + this.authenticatorList = null; + } + + private Authenticator getAuthenticator(HttpServletRequest httpServletRequest) { + + for (Authenticator authenticator : authenticatorList) { + if (authenticator.canProcess(httpServletRequest)) { + return authenticator; + } + } + + return null; + } + + /** + * This method will create a 401 unauthorized response to be sent. + * + * @param servletResponse The HTTP response. + */ + private void populateUnauthorisedData(ServletResponse servletResponse, String message) { + + HttpServletResponse httpServletResponse = (HttpServletResponse)servletResponse; + + httpServletResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED); + httpServletResponse.addHeader("Server", "Airavata Server"); + httpServletResponse.addHeader("Description", message); + httpServletResponse.addDateHeader("Date", Calendar.getInstance().getTimeInMillis()); + httpServletResponse.addHeader("WWW-Authenticate", "Basic realm=Airavata"); + httpServletResponse.setContentType("text/html"); + + } +} Added: airavata/trunk/modules/airavata-rest-services/src/main/java/org/apache/airavata/services/registry/rest/security/basic/BasicAccessAuthenticator.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-rest-services/src/main/java/org/apache/airavata/services/registry/rest/security/basic/BasicAccessAuthenticator.java?rev=1409413&view=auto ============================================================================== --- airavata/trunk/modules/airavata-rest-services/src/main/java/org/apache/airavata/services/registry/rest/security/basic/BasicAccessAuthenticator.java (added) +++ airavata/trunk/modules/airavata-rest-services/src/main/java/org/apache/airavata/services/registry/rest/security/basic/BasicAccessAuthenticator.java Wed Nov 14 21:23:10 2012 @@ -0,0 +1,214 @@ +/* + * 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.services.registry.rest.security.basic; + +import org.apache.airavata.security.AbstractAuthenticator; +import org.apache.airavata.security.AuthenticationException; +import org.apache.airavata.security.UserStoreException; +import org.apache.commons.codec.binary.Base64; +import org.w3c.dom.Node; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +/** + * This authenticator handles basic access authentication requests. In basic access authentication + * we get user name and password as HTTP headers. The password is encoded with base64. + * More information @link{http://en.wikipedia.org/wiki/Basic_access_authentication} + */ +public class BasicAccessAuthenticator extends AbstractAuthenticator { + + + private static final String AUTHENTICATOR_NAME = "BasicAccessAuthenticator"; + + /** + * Header names + */ + private static final String AUTHORISATION_HEADER_NAME = "Authorization"; + private static final String USER_IN_SESSION = "userName"; + + public BasicAccessAuthenticator() { + super(AUTHENTICATOR_NAME); + } + + private String decode(String encoded) { + return new String(Base64.decodeBase64(encoded.getBytes())); + } + + /** + * Returns user name and password as an array. The first element is user name and second is password. + * + * @param httpServletRequest The servlet request. + * @return User name password pair as an array. + * @throws AuthenticationException If an error occurred while extracting user name and password. + */ + private String[] getUserNamePassword(HttpServletRequest httpServletRequest) throws AuthenticationException { + + String basicHeader = httpServletRequest.getHeader(AUTHORISATION_HEADER_NAME); + + if (basicHeader == null) { + throw new AuthenticationException("Authorization Required"); + } + + String[] userNamePasswordArray = basicHeader.split(" "); + + if (userNamePasswordArray == null || userNamePasswordArray.length != 2) { + throw new AuthenticationException("Authorization Required"); + } + + String decodedString = decode(userNamePasswordArray[1]); + + String[] array = decodedString.split(":"); + + if (array == null || array.length != 2) { + throw new AuthenticationException("Authorization Required"); + } + + return array; + + } + + @Override + protected boolean doAuthentication(Object credentials) throws AuthenticationException { + if (this.getUserStore() == null) { + throw new AuthenticationException("Authenticator is not initialized. Error processing request."); + } + + if (credentials == null) + return false; + + HttpServletRequest httpServletRequest = (HttpServletRequest) credentials; + + String[] array = getUserNamePassword(httpServletRequest); + + String userName = array[0]; + String password = array[1]; + + try { + return this.getUserStore().authenticate(userName, password); + + } catch (UserStoreException e) { + throw new AuthenticationException("Error querying database for session information.", e); + } + } + + protected void addUserToSession(String userName, HttpServletRequest servletRequest) { + + if (servletRequest.getSession() != null) { + servletRequest.getSession().setAttribute(USER_IN_SESSION, userName); + } + } + + @Override + public void onSuccessfulAuthentication(Object authenticationInfo) { + + HttpServletRequest httpServletRequest = (HttpServletRequest) authenticationInfo; + + try { + String[] array = getUserNamePassword(httpServletRequest); + + StringBuilder stringBuilder = new StringBuilder("User : "); + + if (array != null) { + + addUserToSession(array[0], httpServletRequest); + + stringBuilder.append(array[0]).append(" successfully logged into system at ").append(getCurrentTime()); + log.info(stringBuilder.toString()); + + } else { + log.error("System error occurred while extracting user name after authentication. " + + "Couldn't extract user name from the request."); + } + } catch (AuthenticationException e) { + log.error("System error occurred while extracting user name after authentication.", e); + } + + } + + @Override + public void onFailedAuthentication(Object authenticationInfo) { + + HttpServletRequest httpServletRequest = (HttpServletRequest) authenticationInfo; + + try { + String[] array = getUserNamePassword(httpServletRequest); + + StringBuilder stringBuilder = new StringBuilder("User : "); + + if (array != null) { + + stringBuilder.append(array[0]).append(" Failed login attempt to system at ").append(getCurrentTime()); + log.warn(stringBuilder.toString()); + + } else { + stringBuilder.append("Failed login attempt to system at ").append(getCurrentTime()).append( ". User unknown."); + log.warn(stringBuilder.toString()); + } + } catch (AuthenticationException e) { + log.error("System error occurred while extracting user name after authentication.", e); + } + } + + @Override + public boolean isAuthenticated(Object credentials) { + HttpServletRequest httpServletRequest = (HttpServletRequest) credentials; + + HttpSession httpSession = httpServletRequest.getSession(); + + return httpSession != null && httpSession.getAttribute(USER_IN_SESSION) != null; + + } + + @Override + public boolean canProcess(Object credentials) { + + HttpServletRequest httpServletRequest = (HttpServletRequest) credentials; + + return (httpServletRequest.getHeader(AUTHORISATION_HEADER_NAME) != null); + } + + @Override + public void configure(Node node) throws RuntimeException { + + /** + + + + + + + + + + + + */ + + try { + this.getUserStore().configure(node); + } catch (UserStoreException e) { + throw new RuntimeException("Error while configuring authenticator user store", e); + } + + } + +} Added: airavata/trunk/modules/airavata-rest-services/src/main/java/org/apache/airavata/services/registry/rest/security/session/SessionAuthenticator.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-rest-services/src/main/java/org/apache/airavata/services/registry/rest/security/session/SessionAuthenticator.java?rev=1409413&view=auto ============================================================================== --- airavata/trunk/modules/airavata-rest-services/src/main/java/org/apache/airavata/services/registry/rest/security/session/SessionAuthenticator.java (added) +++ airavata/trunk/modules/airavata-rest-services/src/main/java/org/apache/airavata/services/registry/rest/security/session/SessionAuthenticator.java Wed Nov 14 21:23:10 2012 @@ -0,0 +1,120 @@ +/* + * 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.services.registry.rest.security.session; + +import org.apache.airavata.security.AbstractAuthenticator; +import org.apache.airavata.security.AuthenticationException; +import org.apache.airavata.security.UserStoreException; +import org.w3c.dom.Node; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +/** + * This authenticator will authenticate requests based on a session (NOT HTTP Session) id stored + * in the database. + */ +public class SessionAuthenticator extends AbstractAuthenticator { + + private static final String AUTHENTICATOR_NAME = "SessionAuthenticator"; + + private static final String SESSION_TICKET = "sessionTicket"; + + public SessionAuthenticator() { + super(AUTHENTICATOR_NAME); + } + + @Override + public boolean doAuthentication(Object credentials) throws AuthenticationException { + + if (credentials == null) + return false; + + HttpServletRequest httpServletRequest = (HttpServletRequest)credentials; + String sessionTicket = httpServletRequest.getHeader(SESSION_TICKET); + try { + return this.getUserStore().authenticate(sessionTicket); + } catch (UserStoreException e) { + throw new AuthenticationException("Error querying database for session information.", e); + } + } + + @Override + public boolean canProcess(Object credentials) { + + if (credentials instanceof HttpServletRequest) { + HttpServletRequest request = (HttpServletRequest) credentials; + + String ticket = request.getHeader(SESSION_TICKET); + if (ticket != null) { + return true; + } + } + + return false; + } + + @Override + public void onSuccessfulAuthentication(Object authenticationInfo) { + + HttpServletRequest httpServletRequest = (HttpServletRequest)authenticationInfo; + String sessionTicket = httpServletRequest.getHeader(SESSION_TICKET); + + // Add sessionTicket to http session + HttpSession httpSession = httpServletRequest.getSession(); + + if (httpSession != null) { + httpSession.setAttribute(SESSION_TICKET, sessionTicket); + } + + log.info("A request with a session ticket is successfully logged in."); + + } + + @Override + public void onFailedAuthentication(Object authenticationInfo) { + log.warn("Failed attempt to login."); + } + + @Override + public void configure(Node node) throws RuntimeException { + + try { + this.getUserStore().configure(node); + } catch (UserStoreException e) { + throw new RuntimeException("Error while configuring authenticator user store", e); + } + } + + + @Override + public boolean isAuthenticated(Object credentials) { + HttpServletRequest httpServletRequest = (HttpServletRequest)credentials; + + if (httpServletRequest.getSession() != null) { + String sessionTicket = (String)httpServletRequest.getSession().getAttribute(SESSION_TICKET); + return (sessionTicket != null); + } + + return false; + + } +} Added: airavata/trunk/modules/airavata-rest-services/src/main/resources/authenticators.xml URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-rest-services/src/main/resources/authenticators.xml?rev=1409413&view=auto ============================================================================== --- airavata/trunk/modules/airavata-rest-services/src/main/resources/authenticators.xml (added) +++ airavata/trunk/modules/airavata-rest-services/src/main/resources/authenticators.xml Wed Nov 14 21:23:10 2012 @@ -0,0 +1,64 @@ + + + + + + + + + + + jdbc:h2:../../src/test/resources/testdb/test + sa + sa + org.h2.Driver + Persons + sessionId + sessionId + + + + + + + + + jdbc:mysql://localhost/airavata + root + root123 + com.mysql.jdbc.Driver + AIRAVATA_USER + USERID + PASSWORD + + + + + + + + + ldap://localhost:10389 + admin + secret + uid={0},ou=users,ou=system + + + + + \ No newline at end of file Added: airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/configurations/AuthenticatorConfigurationReaderTest.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/configurations/AuthenticatorConfigurationReaderTest.java?rev=1409413&view=auto ============================================================================== --- airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/configurations/AuthenticatorConfigurationReaderTest.java (added) +++ airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/configurations/AuthenticatorConfigurationReaderTest.java Wed Nov 14 21:23:10 2012 @@ -0,0 +1,117 @@ +/* + * 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.util.List; + +/** + * A test class for authenticator configuration reader. + * Reads the authenticators.xml in resources directory. + */ +public class AuthenticatorConfigurationReaderTest extends TestCase { + + private String configurationFile = 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 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.myqsql.Driver1", ((TestDBAuthenticator1) authenticator).getDatabaseDriver()); + assertEquals("mysql1", ((TestDBAuthenticator1) authenticator).getDatabaseUserName()); + assertEquals("secret1", ((TestDBAuthenticator1) authenticator).getDatabasePassword()); + assertNotNull(authenticator.getUserStore()); + assertTrue(authenticator.getUserStore() instanceof JDBCUserStore); + } else if (authenticator instanceof TestDBAuthenticator2) { + assertEquals("dbAuthenticator2", authenticator.getAuthenticatorName()); + assertEquals(7, authenticator.getPriority()); + assertEquals(true, authenticator.isEnabled()); + assertEquals("jdbc:sql:thin:@//myhost:1521/mysql2", ((TestDBAuthenticator2) authenticator).getDatabaseURL()); + assertEquals("org.myqsql.Driver2", ((TestDBAuthenticator2) authenticator).getDatabaseDriver()); + assertEquals("mysql2", ((TestDBAuthenticator2) authenticator).getDatabaseUserName()); + assertEquals("secret2", ((TestDBAuthenticator2) authenticator).getDatabasePassword()); + assertNotNull(authenticator.getUserStore()); + assertTrue(authenticator.getUserStore() instanceof LDAPUserStore); + } else if (authenticator instanceof TestDBAuthenticator3) { + assertEquals("dbAuthenticator3", authenticator.getAuthenticatorName()); + assertEquals(8, authenticator.getPriority()); + assertEquals(true, authenticator.isEnabled()); + assertEquals("jdbc:sql:thin:@//myhost:1521/mysql3", ((TestDBAuthenticator3) authenticator).getDatabaseURL()); + assertEquals("org.myqsql.Driver3", ((TestDBAuthenticator3) authenticator).getDatabaseDriver()); + assertEquals("mysql3", ((TestDBAuthenticator3) authenticator).getDatabaseUserName()); + assertEquals("secret3", ((TestDBAuthenticator3) authenticator).getDatabasePassword()); + assertNotNull(authenticator.getUserStore()); + assertTrue(authenticator.getUserStore() instanceof JDBCUserStore); + } + } + + 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 + = this.getClass().getClassLoader().getResource("disabled-authenticator.xml").getFile(); + + + AuthenticatorConfigurationReader authenticatorConfigurationReader + = new AuthenticatorConfigurationReader(); + authenticatorConfigurationReader.init(disabledConfiguration); + + assertFalse(AuthenticatorConfigurationReader.isAuthenticationEnabled()); + + } +} Added: airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/configurations/TestDBAuthenticator1.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/configurations/TestDBAuthenticator1.java?rev=1409413&view=auto ============================================================================== --- airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/configurations/TestDBAuthenticator1.java (added) +++ airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/configurations/TestDBAuthenticator1.java Wed Nov 14 21:23:10 2012 @@ -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. + } +} + Added: airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/configurations/TestDBAuthenticator2.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/configurations/TestDBAuthenticator2.java?rev=1409413&view=auto ============================================================================== --- airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/configurations/TestDBAuthenticator2.java (added) +++ airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/configurations/TestDBAuthenticator2.java Wed Nov 14 21:23:10 2012 @@ -0,0 +1,59 @@ +/* + * 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; + +/** + * Test class for authenticator. + */ +public class TestDBAuthenticator2 extends AbstractDatabaseAuthenticator { + + public TestDBAuthenticator2() { + 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. + } +} Added: airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/configurations/TestDBAuthenticator3.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/configurations/TestDBAuthenticator3.java?rev=1409413&view=auto ============================================================================== --- airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/configurations/TestDBAuthenticator3.java (added) +++ airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/configurations/TestDBAuthenticator3.java Wed Nov 14 21:23:10 2012 @@ -0,0 +1,43 @@ +package org.apache.airavata.security.configurations; + +import org.apache.airavata.security.AbstractDatabaseAuthenticator; +import org.apache.airavata.security.AuthenticationException; + +/** + * Created with IntelliJ IDEA. + * User: thejaka + * Date: 9/6/12 + * Time: 6:30 PM + * To change this template use File | Settings | File Templates. + */ +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. + } +} Added: airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/configurations/TestUserStore.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/configurations/TestUserStore.java?rev=1409413&view=auto ============================================================================== --- airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/configurations/TestUserStore.java (added) +++ airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/configurations/TestUserStore.java Wed Nov 14 21:23:10 2012 @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.airavata.security.configurations; + +import org.apache.airavata.security.UserStore; +import org.w3c.dom.Node; + +/** + * Test user store class. + */ +public class TestUserStore implements UserStore { + @Override + public boolean authenticate(String userName, Object credentials) { + return false; //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public boolean authenticate(Object credentials) { + return false; //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public void configure(Node node) throws RuntimeException { + //To change body of implemented methods use File | Settings | File Templates. + } +} Added: airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/userstore/JDBCUserStoreTest.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/userstore/JDBCUserStoreTest.java?rev=1409413&view=auto ============================================================================== --- airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/userstore/JDBCUserStoreTest.java (added) +++ airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/userstore/JDBCUserStoreTest.java Wed Nov 14 21:23:10 2012 @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.airavata.security.userstore; + +import junit.framework.TestCase; +import org.apache.airavata.security.Authenticator; +import org.apache.airavata.security.UserStore; +import org.apache.airavata.security.configurations.AuthenticatorConfigurationReader; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import java.io.File; +import java.util.List; + +/** + * Test class for JDBC user store. + */ +public class JDBCUserStoreTest extends TestCase { + + /** + * + + + jdbc:h2:src/test/resources/testdb/test + sa + sa + org.h2.Driver + AIRAVATA_USER + USERID + PASSWORD + + + * @throws Exception + */ + + + + public void testAuthenticate() throws Exception { + + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + Document doc = dBuilder.parse(this.getClass().getClassLoader().getResourceAsStream("jdbc-authenticator.xml")); + doc.getDocumentElement().normalize(); + + NodeList configurations = doc.getElementsByTagName("specificConfigurations"); + UserStore userStore = new JDBCUserStore(); + userStore.configure(configurations.item(0)); + + assertTrue(userStore.authenticate("amilaj", "secret")); + assertFalse(userStore.authenticate("amilaj", "1secret")); + assertFalse(userStore.authenticate("lahiru", "1234")); + + } +} Added: airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/userstore/LDAPUserStoreTest.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/userstore/LDAPUserStoreTest.java?rev=1409413&view=auto ============================================================================== --- airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/userstore/LDAPUserStoreTest.java (added) +++ airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/userstore/LDAPUserStoreTest.java Wed Nov 14 21:23:10 2012 @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.airavata.security.userstore; + +import junit.framework.TestCase; +import org.apache.airavata.security.UserStore; +import org.junit.Ignore; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +/** + * User store test 2 + */ +@Ignore("Need LDAP server to run these tests") +public class LDAPUserStoreTest extends TestCase{ + + private LDAPUserStore ldapUserStore; + + public void setUp() { + ldapUserStore = new LDAPUserStore(); + + ldapUserStore.initializeLDAP("ldap://localhost:10389", "admin", "secret", "uid={0},ou=system"); + } + + public void testAuthenticate() throws Exception { + assertTrue(ldapUserStore.authenticate("amilaj", "secret")); + assertFalse(ldapUserStore.authenticate("amilaj", "secret1")); + } + + public void testConfigure() throws Exception { + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + Document doc = dBuilder.parse(this.getClass().getClassLoader().getResourceAsStream("ldap-authenticator.xml")); + doc.getDocumentElement().normalize(); + + NodeList configurations = doc.getElementsByTagName("specificConfigurations"); + UserStore userStore = new LDAPUserStore(); + userStore.configure(configurations.item(0)); + + assertTrue(userStore.authenticate("amilaj", "secret")); + } + + + +} Added: airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/userstore/SessionDBUserStoreTest.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/userstore/SessionDBUserStoreTest.java?rev=1409413&view=auto ============================================================================== --- airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/userstore/SessionDBUserStoreTest.java (added) +++ airavata/trunk/modules/airavata-rest-services/src/test/java/org/apache/airavata/security/userstore/SessionDBUserStoreTest.java Wed Nov 14 21:23:10 2012 @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.airavata.security.userstore; + +import junit.framework.TestCase; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import java.io.File; +import java.io.InputStream; + +/** + * Test class for session DB authenticator. + */ +public class SessionDBUserStoreTest extends TestCase { + + private SessionDBUserStore sessionDBUserStore = new SessionDBUserStore(); + + private InputStream configurationFileStream + = this.getClass().getClassLoader().getResourceAsStream("session-authenticator.xml"); + + public void setUp() throws Exception { + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + Document doc = dBuilder.parse(configurationFileStream); + doc.getDocumentElement().normalize(); + + NodeList specificConfigurations = doc.getElementsByTagName("specificConfigurations"); + sessionDBUserStore.configure(specificConfigurations.item(0)); + } + + public void testAuthenticate() throws Exception { + assertTrue(sessionDBUserStore.authenticate("1234")); + + } + + public void testAuthenticateFailure() throws Exception { + assertFalse(sessionDBUserStore.authenticate("12345")); + } +} Added: airavata/trunk/modules/airavata-rest-services/src/test/resources/authenticators.xml URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-rest-services/src/test/resources/authenticators.xml?rev=1409413&view=auto ============================================================================== --- airavata/trunk/modules/airavata-rest-services/src/test/resources/authenticators.xml (added) +++ airavata/trunk/modules/airavata-rest-services/src/test/resources/authenticators.xml Wed Nov 14 21:23:10 2012 @@ -0,0 +1,72 @@ + + + + + + + + + jdbc:sql:thin:@//myhost:1521/mysql1 + mysql1 + secret1 + org.myqsql.Driver1 + Session1 + sessioncolumn + comparecolumn + + + + + + + + + jdbc:sql:thin:@//myhost:1521/mysql2 + mysql2 + secret2 + org.myqsql.Driver2 + Session2 + sessioncolumn2 + comparecolumn2 + + + + + + + + jdbc:sql:thin:@//myhost:1521/mysql2 + mysql2 + secret2 + org.myqsql.Driver2 + Session2 + sessioncolumn2 + comparecolumn2 + + + + + + + + jdbc:sql:thin:@//myhost:1521/mysql3 + mysql3 + secret3 + org.myqsql.Driver3 + Session3 + sessioncolumn3 + comparecolumn3 + + + + + \ No newline at end of file Added: airavata/trunk/modules/airavata-rest-services/src/test/resources/disabled-authenticator.xml URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-rest-services/src/test/resources/disabled-authenticator.xml?rev=1409413&view=auto ============================================================================== --- airavata/trunk/modules/airavata-rest-services/src/test/resources/disabled-authenticator.xml (added) +++ airavata/trunk/modules/airavata-rest-services/src/test/resources/disabled-authenticator.xml Wed Nov 14 21:23:10 2012 @@ -0,0 +1,72 @@ + + + + + + + + + jdbc:sql:thin:@//myhost:1521/mysql1 + mysql1 + secret1 + org.myqsql.Driver1 + Session1 + sessioncolumn + comparecolumn + + + + + + + + + jdbc:sql:thin:@//myhost:1521/mysql2 + mysql2 + secret2 + org.myqsql.Driver2 + Session2 + sessioncolumn2 + comparecolumn2 + + + + + + + + jdbc:sql:thin:@//myhost:1521/mysql2 + mysql2 + secret2 + org.myqsql.Driver2 + Session2 + sessioncolumn2 + comparecolumn2 + + + + + + + + jdbc:sql:thin:@//myhost:1521/mysql3 + mysql3 + secret3 + org.myqsql.Driver3 + Session3 + sessioncolumn3 + comparecolumn3 + + + + + \ No newline at end of file Added: airavata/trunk/modules/airavata-rest-services/src/test/resources/jdbc-authenticator.xml URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-rest-services/src/test/resources/jdbc-authenticator.xml?rev=1409413&view=auto ============================================================================== --- airavata/trunk/modules/airavata-rest-services/src/test/resources/jdbc-authenticator.xml (added) +++ airavata/trunk/modules/airavata-rest-services/src/test/resources/jdbc-authenticator.xml Wed Nov 14 21:23:10 2012 @@ -0,0 +1,39 @@ + + + + + + + jdbc:h2:../../src/test/resources/testdb/test + sa + sa + org.h2.Driver + AIRAVATA_USER + USERID + PASSWORD + + + + Added: airavata/trunk/modules/airavata-rest-services/src/test/resources/ldap-authenticator.xml URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-rest-services/src/test/resources/ldap-authenticator.xml?rev=1409413&view=auto ============================================================================== --- airavata/trunk/modules/airavata-rest-services/src/test/resources/ldap-authenticator.xml (added) +++ airavata/trunk/modules/airavata-rest-services/src/test/resources/ldap-authenticator.xml Wed Nov 14 21:23:10 2012 @@ -0,0 +1,41 @@ + + + + + + + ldap://localhost:10389 + admin + secret + uid={0},ou=system + + + + Added: airavata/trunk/modules/airavata-rest-services/src/test/resources/session-authenticator.xml URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-rest-services/src/test/resources/session-authenticator.xml?rev=1409413&view=auto ============================================================================== --- airavata/trunk/modules/airavata-rest-services/src/test/resources/session-authenticator.xml (added) +++ airavata/trunk/modules/airavata-rest-services/src/test/resources/session-authenticator.xml Wed Nov 14 21:23:10 2012 @@ -0,0 +1,44 @@ + + + + + + + + + jdbc:h2:../../src/test/resources/testdb/test + + + sa + sa + org.h2.Driver + Persons + sessionId + sessionId + + + + + Added: airavata/trunk/modules/airavata-rest-services/src/test/resources/testdb/test.h2.db URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-rest-services/src/test/resources/testdb/test.h2.db?rev=1409413&view=auto ============================================================================== Binary file - no diff available. Propchange: airavata/trunk/modules/airavata-rest-services/src/test/resources/testdb/test.h2.db ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: airavata/trunk/modules/airavata-rest-services/src/test/resources/testdb/test.trace.db URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-rest-services/src/test/resources/testdb/test.trace.db?rev=1409413&view=auto ============================================================================== --- airavata/trunk/modules/airavata-rest-services/src/test/resources/testdb/test.trace.db (added) +++ airavata/trunk/modules/airavata-rest-services/src/test/resources/testdb/test.trace.db Wed Nov 14 21:23:10 2012 @@ -0,0 +1,97 @@ +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] +11-14 16:22:34 jdbc[4]: null +org.h2.message.DbException: The connection was not closed by the application and is garbage collected [90018-168] + at org.h2.message.DbException.get(DbException.java:169) + at org.h2.message.DbException.get(DbException.java:146) + at org.h2.message.DbException.get(DbException.java:135) + at org.h2.jdbc.JdbcConnection.closeOld(JdbcConnection.java:172) + at org.h2.jdbc.JdbcConnection.(JdbcConnection.java:119) + at org.h2.jdbc.JdbcConnection.(JdbcConnection.java:92) + at org.h2.Driver.connect(Driver.java:72) + at java.sql.DriverManager.getConnection(DriverManager.java:582) + at java.sql.DriverManager.getConnection(DriverManager.java:154) + at org.apache.airavata.security.util.DBLookup.getConnection(DBLookup.java:105) + at org.apache.airavata.security.util.DBLookup.getMatchingColumnValue(DBLookup.java:60) + at org.apache.airavata.security.util.DBLookup.getMatchingColumnValue(DBLookup.java:47) + at org.apache.airavata.security.userstore.SessionDBUserStore.authenticate(SessionDBUserStore.java:64) + at org.apache.airavata.security.userstore.SessionDBUserStoreTest.testAuthenticateFailure(SessionDBUserStoreTest.java:58) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:597) + at junit.framework.TestCase.runTest(TestCase.java:168) + at junit.framework.TestCase.runBare(TestCase.java:134) + at junit.framework.TestResult$1.protect(TestResult.java:110) + at junit.framework.TestResult.runProtected(TestResult.java:128) + at junit.framework.TestResult.run(TestResult.java:113) + at junit.framework.TestCase.run(TestCase.java:124) + at junit.framework.TestSuite.runTest(TestSuite.java:232) + at junit.framework.TestSuite.run(TestSuite.java:227) + at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83) + at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:236) + at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:134) + at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:113) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:597) + at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) + at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) + at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) + at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:103) + at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:74) +Caused by: org.h2.jdbc.JdbcSQLException: The connection was not closed by the application and is garbage collected [90018-168] + at org.h2.message.DbException.getJdbcSQLException(DbException.java:329) + ... 39 more Added: airavata/trunk/modules/airavata-rest-services/src/test/resources/testdb/test/test.trace.db URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-rest-services/src/test/resources/testdb/test/test.trace.db?rev=1409413&view=auto ============================================================================== --- airavata/trunk/modules/airavata-rest-services/src/test/resources/testdb/test/test.trace.db (added) +++ airavata/trunk/modules/airavata-rest-services/src/test/resources/testdb/test/test.trace.db Wed Nov 14 21:23:10 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]