Author: ngn Date: Mon Dec 15 12:39:06 2008 New Revision: 726795 URL: http://svn.apache.org/viewvc?rev=726795&view=rev Log: Fix bug where we would close the statement before the user was actually loaded from the database (FTPSERVER-242)
Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/impl/DbUserManager.java Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/impl/DbUserManager.java URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/impl/DbUserManager.java?rev=726795&r1=726794&r2=726795&view=diff ============================================================================== --- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/impl/DbUserManager.java (original) +++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/impl/DbUserManager.java Mon Dec 15 12:39:06 2008 @@ -358,11 +358,11 @@ ResultSet rs = null; try { - rs = selectUserByName(user.getName()); + User userWithPassword = selectUserByName(user.getName()); - if(rs.next()) { + if(userWithPassword != null) { // user exists, reuse password - password = rs.getString(ATTR_PASSWORD); + password = userWithPassword.getPassword(); } } finally { closeQuitely(rs); @@ -452,7 +452,7 @@ } - private ResultSet selectUserByName(String name) throws SQLException { + private BaseUser selectUserByName(String name) throws SQLException { // create sql query HashMap<String, Object> map = new HashMap<String, Object>(); map.put(ATTR_LOGIN, escapeString(name)); @@ -460,30 +460,18 @@ LOG.info(sql); Statement stmt = null; + ResultSet rs = null; try { // execute query stmt = createConnection().createStatement(); - return stmt.executeQuery(sql); - } finally { - closeQuitely(stmt); - } - } - - /** - * Get the user object. Fetch the row from the table. - */ - public User getUserByName(String name) throws FtpException { - Statement stmt = null; - ResultSet rs = null; - try { - - rs = selectUserByName(name); + rs = stmt.executeQuery(sql); // populate user object BaseUser thisUser = null; if (rs.next()) { thisUser = new BaseUser(); thisUser.setName(rs.getString(ATTR_LOGIN)); + thisUser.setPassword(rs.getString(ATTR_PASSWORD)); thisUser.setHomeDirectory(rs.getString(ATTR_HOME)); thisUser.setEnabled(rs.getBoolean(ATTR_ENABLE)); thisUser.setMaxIdleTime(rs.getInt(ATTR_MAX_IDLE_TIME)); @@ -503,6 +491,30 @@ thisUser.setAuthorities(authorities); } return thisUser; + + } finally { + closeQuitely(rs); + closeQuitely(stmt); + } + } + + /** + * Get the user object. Fetch the row from the table. + */ + public User getUserByName(String name) throws FtpException { + Statement stmt = null; + ResultSet rs = null; + try { + + BaseUser user = selectUserByName(name); + + if(user != null) { + // reset the password, not to be sent to API users + user.setPassword(null); + } + return user; + + } catch (SQLException ex) { LOG.error("DbUserManager.getUserByName()", ex); throw new FtpException("DbUserManager.getUserByName()", ex);