You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ftpserver-commits@incubator.apache.org by ng...@apache.org on 2007/02/12 16:21:41 UTC

svn commit: r506520 - in /incubator/ftpserver/trunk/core: ./ src/java/org/apache/ftpserver/ src/java/org/apache/ftpserver/usermanager/ src/test/ src/test/org/apache/ftpserver/usermanager/

Author: ngn
Date: Mon Feb 12 08:21:40 2007
New Revision: 506520

URL: http://svn.apache.org/viewvc?view=rev&rev=506520
Log:
Converted DbUserManager into a POJO with an insertable data source
Added test cases for DbUserManager
Added configuration exception for use during startup

Added:
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpServerConfigurationException.java   (with props)
    incubator/ftpserver/trunk/core/src/test/dbusermanagertest-hsql.sql   (with props)
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/usermanager/DbUserManagerTest.java   (with props)
Modified:
    incubator/ftpserver/trunk/core/pom.xml
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/usermanager/AbstractUserManager.java
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/usermanager/DbUserManager.java
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/usermanager/PropertiesUserManager.java
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/usermanager/PropertiesUserManagerTest.java

Modified: incubator/ftpserver/trunk/core/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/pom.xml?view=diff&rev=506520&r1=506519&r2=506520
==============================================================================
--- incubator/ftpserver/trunk/core/pom.xml (original)
+++ incubator/ftpserver/trunk/core/pom.xml Mon Feb 12 08:21:40 2007
@@ -172,5 +172,11 @@
             <version>2.0.8</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+    		<groupId>hsqldb</groupId>
+    		<artifactId>hsqldb</artifactId>
+    		<version>1.8.0.7</version>
+    		<scope>test</scope>
+		</dependency>
     </dependencies>
 </project>

Added: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpServerConfigurationException.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpServerConfigurationException.java?view=auto&rev=506520
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpServerConfigurationException.java (added)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpServerConfigurationException.java Mon Feb 12 08:21:40 2007
@@ -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.ftpserver;
+
+
+/**
+ * Exception used during startup to indicate that the configuration is 
+ * not correct.
+ */
+public 
+class FtpServerConfigurationException extends RuntimeException {
+
+    private static final long serialVersionUID = -1328432839915898987L;
+    
+    /**
+     * {@link RuntimeException#RuntimeException()}
+     */
+    public FtpServerConfigurationException() {
+        super();
+    }
+
+    /**
+     * {@link RuntimeException#RuntimeException(String, Throwable)}
+     */
+    public FtpServerConfigurationException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    /**
+     * {@link RuntimeException#RuntimeException(String)}
+     */
+    public FtpServerConfigurationException(String message) {
+        super(message);
+    }
+
+    /**
+     * {@link RuntimeException#RuntimeException(Throwable)}
+     */
+    public FtpServerConfigurationException(Throwable cause) {
+        super(cause);
+    }
+
+}

Propchange: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpServerConfigurationException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/usermanager/AbstractUserManager.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/usermanager/AbstractUserManager.java?view=diff&rev=506520&r1=506519&r2=506520
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/usermanager/AbstractUserManager.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/usermanager/AbstractUserManager.java Mon Feb 12 08:21:40 2007
@@ -19,6 +19,7 @@
 
 package org.apache.ftpserver.usermanager;
 
+import org.apache.ftpserver.ftplet.FtpException;
 import org.apache.ftpserver.ftplet.UserManager;
 
 
@@ -39,5 +40,41 @@
     public static final String ATTR_MAX_LOGIN_NUMBER = "maxloginnumber";
     public static final String ATTR_MAX_LOGIN_PER_IP = "maxloginperip";
 
+    private String         adminName = "admin";
+    
+
+    /**
+     * Get the admin name.
+     */
+    public String getAdminName() {
+        return adminName;
+    }
+    
+    /**
+     * Set the name to use as the administrator of the server.
+     * The default value is "admin".
+     * @param adminName The administrator user name
+     */
+    public void setAdminName(String adminName) {
+        this.adminName = adminName;
+    }
+
+    /**
+     * Set the name to use as the administrator of the server
+     * @param adminName The administrator user name
+     * @deprecated Use {@link #setAdminName(String)} instead
+     */
+    public void setAdmin(String adminName) {
+        this.adminName = adminName;
+    }
+    
+
+    
+    /**
+     * @return true if user with this login is administrator
+     */
+    public boolean isAdmin(String login) throws FtpException {
+        return adminName.equals(login);
+    }
 }
 

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/usermanager/DbUserManager.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/usermanager/DbUserManager.java?view=diff&rev=506520&r1=506519&r2=506520
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/usermanager/DbUserManager.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/usermanager/DbUserManager.java Mon Feb 12 08:21:40 2007
@@ -20,7 +20,6 @@
 package org.apache.ftpserver.usermanager;
 
 import java.sql.Connection;
-import java.sql.DriverManager;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
@@ -28,13 +27,14 @@
 import java.util.HashMap;
 import java.util.List;
 
+import javax.sql.DataSource;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.ftpserver.FtpServerConfigurationException;
 import org.apache.ftpserver.ftplet.Authentication;
 import org.apache.ftpserver.ftplet.AuthenticationFailedException;
 import org.apache.ftpserver.ftplet.Authority;
-import org.apache.ftpserver.ftplet.Component;
-import org.apache.ftpserver.ftplet.Configuration;
 import org.apache.ftpserver.ftplet.FtpException;
 import org.apache.ftpserver.ftplet.User;
 import org.apache.ftpserver.util.StringUtils;
@@ -48,13 +48,10 @@
  * your database schema. Then you need to modify the SQLs in the configuration
  * file.
  */
-public
-class DbUserManager extends AbstractUserManager implements Component {
+public class DbUserManager extends AbstractUserManager {
     
     private Log log;
     
-    private Connection connection;
-    
     private String insertUserStmt;
     private String updateUserStmt;
     private String deleteUserStmt;
@@ -62,12 +59,9 @@
     private String selectAllStmt;
     private String isAdminStmt;
     private String authenticateStmt;
-    
-    private String jdbcUrl;
-    private String dbUser;
-    private String dbPassword;
-    
-    private String adminName;
+
+    private DataSource dataSource;
+    private Connection cachedConnection;
     
     
     /**
@@ -78,45 +72,176 @@
     }
     
     /**
+     * Retrive the data source used by the user manager
+     * @return The current data source
+     */
+    public DataSource getDataSource() {
+        return dataSource;
+    }
+    
+    /**
+     * Set the data source to be used by the user manager
+     * @param dataSource The data source to use
+     */
+    public void setDataSource(DataSource dataSource) {
+        this.dataSource = dataSource;
+    }
+    
+    /**
+     * Get the SQL INSERT statement used to add a new user.
+     * @return The SQL statement
+     */
+    public String getSqlUserInsert() {
+        return insertUserStmt;
+    }
+    
+    /**
+     * Set the SQL INSERT statement used to add a new user. All the dynamic values will be replaced during runtime.
+     * @param sql The SQL statement
+     */
+    public void setSqlUserInsert(String sql) {
+        insertUserStmt = sql;
+    }
+    
+    /**
+     * Get the SQL DELETE statement used to delete an existing user.
+     * @return The SQL statement
+     */
+    public String getSqlUserDelete() {
+        return insertUserStmt;
+    }
+    
+    /**
+     * Set the SQL DELETE statement used to delete an existing user. All the dynamic values will be replaced during runtime.
+     * @param sql The SQL statement
+     */
+    public void setSqlUserDelete(String sql) {
+        deleteUserStmt = sql;
+    }
+    
+    /**
+     * Get the SQL UPDATE statement used to update an existing user.
+     * @return The SQL statement
+     */
+    public String getSqlUserUpdate() {
+        return updateUserStmt;
+    }
+    
+    /**
+     * Set the SQL UPDATE statement used to update an existing user. All the dynamic values will be replaced during runtime.
+     * @param sql The SQL statement
+     */
+    public void setSqlUserUpdate(String sql) {
+        updateUserStmt = sql;
+    }
+    
+    /**
+     * Get the SQL SELECT statement used to select an existing user.
+     * @return The SQL statement
+     */
+    public String getSqlUserSelect() {
+        return selectUserStmt;
+    }
+    
+    /**
+     * Set the SQL SELECT statement used to select an existing user. All the dynamic values will be replaced during runtime.
+     * @param sql The SQL statement
+     */
+    public void setSqlUserSelect(String sql) {
+        selectUserStmt = sql;
+    }
+    
+    /**
+     * Get the SQL SELECT statement used to select all user ids.
+     * @return The SQL statement
+     */
+    public String getSqlUserSelectAll() {
+        return selectAllStmt;
+    }
+    
+    /**
+     * Set the SQL SELECT statement used to select all user ids. All the dynamic values will be replaced during runtime.
+     * @param sql The SQL statement
+     */
+    public void setSqlUserSelectAll(String sql) {
+        selectAllStmt = sql;
+    }
+    
+    /**
+     * Get the SQL SELECT statement used to authenticate user.
+     * @return The SQL statement
+     */
+    public String getSqlUserAuthenticate() {
+        return selectAllStmt;
+    }
+    
+    /**
+     * Set the SQL SELECT statement used to authenticate user. All the dynamic values will be replaced during runtime.
+     * @param sql The SQL statement
+     */
+    public void setSqlUserAuthenticate(String sql) {
+        authenticateStmt = sql;
+    }
+    
+    /**
+     * Get the SQL SELECT statement used to find whether an user is admin or not.
+     * @return The SQL statement
+     */
+    public String getSqlUserAdmin() {
+        return selectAllStmt;
+    }
+    
+    /**
+     * Set the SQL SELECT statement used to find whether an user is admin or not. All the dynamic values will be replaced during runtime.
+     * @param sql The SQL statement
+     */
+    public void setSqlUserAdmin(String sql) {
+        isAdminStmt = sql;
+    }
+    
+    /**
      * Configure user manager.
      */
-    public void configure(Configuration config) throws FtpException {
+    public void configure() {
+        
+        if(dataSource == null) {
+            throw new FtpServerConfigurationException("Required data source not provided");
+        }
+        if(insertUserStmt == null) {
+            throw new FtpServerConfigurationException("Required insert user SQL statement not provided");
+        }
+        if(updateUserStmt == null) {
+            throw new FtpServerConfigurationException("Required update user SQL statement not provided");
+        }
+        if(deleteUserStmt == null) {
+            throw new FtpServerConfigurationException("Required delete user SQL statement not provided");
+        }
+        if(selectUserStmt == null) {
+            throw new FtpServerConfigurationException("Required select user SQL statement not provided");
+        }
+        if(selectAllStmt == null) {
+            throw new FtpServerConfigurationException("Required select all users SQL statement not provided");
+        }
+        if(isAdminStmt == null) {
+            throw new FtpServerConfigurationException("Required is admin user SQL statement not provided");
+        }
+        if(authenticateStmt == null) {
+            throw new FtpServerConfigurationException("Required authenticate user SQL statement not provided");
+        }        
         
         try {
-            String className = config.getString("jdbc-driver");
-            Class.forName(className);
+            // test the connection
+            createConnection();
             
-            jdbcUrl          = config.getString("jdbc-url");
-            dbUser           = config.getString("jdbc-user", null);
-            dbPassword       = config.getString("jdbc-password", null);
-            
-            insertUserStmt   = config.getString("sql-user-insert");
-            deleteUserStmt   = config.getString("sql-user-delete");
-            updateUserStmt   = config.getString("sql-user-update");
-            selectUserStmt   = config.getString("sql-user-select");
-            selectAllStmt    = config.getString("sql-user-select-all");
-            authenticateStmt = config.getString("sql-user-authenticate");
-            isAdminStmt      = config.getString("sql-user-admin");
-            
-            openConnection();
-            
-            adminName = config.getString("admin", "admin");
             log.info("Database connection opened.");
         }
-        catch(Exception ex) {
+        catch(SQLException ex) {
             log.fatal("DbUserManager.configure()", ex);
-            throw new FtpException("DbUserManager.configure()", ex);
+            throw new FtpServerConfigurationException("DbUserManager.configure()", ex);
         }
     }
     
     /**
-     * Get the admin name.
-     */
-    public String getAdminName() {
-        return adminName;
-    }
-    
-    /**
      * @return true if user with this login is administrator
      */
     public boolean isAdmin(String login) throws FtpException {
@@ -137,8 +262,7 @@
             log.info(sql);
             
             // execute query
-            prepareConnection();
-            stmt = connection.createStatement();
+            stmt = createConnection().createStatement();
             rs = stmt.executeQuery(sql);
             return rs.next();
         }
@@ -169,50 +293,46 @@
     /**
      * Open connection to database.
      */
-    private void openConnection() throws SQLException {
-        connection = DriverManager.getConnection(jdbcUrl, dbUser, dbPassword);
-        connection.setAutoCommit(true);
+    private synchronized Connection createConnection() throws SQLException {
+        boolean isClosed = false;    
+        try {
+            if( (cachedConnection == null) || cachedConnection.isClosed() ) {
+                isClosed = true;
+            }
+        }
+        catch(SQLException ex) {
+            log.error("DbUserManager.prepareConnection()", ex);
+            isClosed = true;
+        }
+        
+        if (isClosed) {
+            closeConnection();
+
+            cachedConnection = dataSource.getConnection();
+            cachedConnection.setAutoCommit(true);
+        }
+        
+        return cachedConnection;
     }
     
     /**
      * Close connection to database.
      */
     private void closeConnection() {
-        if (connection != null) {        
+        if (cachedConnection != null) {        
             try {
-                connection.close(); 
+                cachedConnection.close(); 
             } 
             catch(SQLException ex) {
                 log.error("DbUserManager.closeConnection()", ex);
             }
-            connection = null;
+            cachedConnection = null;
         }
         
         log.info("Database connection closed.");
     }
     
     /**
-     * Prepare connection to database.
-     */
-    private void prepareConnection() throws SQLException {
-        boolean isClosed = false;    
-        try {
-            if( (connection == null) || connection.isClosed() ) {
-                isClosed = true;
-            }
-        }
-        catch(SQLException ex) {
-            log.error("DbUserManager.prepareConnection()", ex);
-            isClosed = true;
-        }
-        
-        if (isClosed) {
-            closeConnection();
-            openConnection();
-        }
-    }
-    
-    /**
      * Delete user. Delete the row from the table.
      */
     public synchronized void delete(String name) throws FtpException {
@@ -226,8 +346,7 @@
         // execute query
         Statement stmt = null;
         try {
-            prepareConnection();
-            stmt = connection.createStatement();
+            stmt = createConnection().createStatement();
             stmt.executeUpdate(sql);
         }
         catch(SQLException ex) {
@@ -263,9 +382,15 @@
             HashMap map = new HashMap();
             map.put( ATTR_LOGIN, escapeString(user.getName()) );
             map.put( ATTR_PASSWORD, escapeString(getPassword(user)) );
-            map.put( ATTR_HOME, escapeString(user.getHomeDirectory()) );
+            
+            String home = user.getHomeDirectory();
+            if(home == null) {
+                home = "/";
+            }
+            map.put( ATTR_HOME, escapeString(home) );
             map.put( ATTR_ENABLE, String.valueOf(user.getEnabled()) );
-            map.put( ATTR_WRITE_PERM, String.valueOf(user.authorize(new WriteRequest())) );
+            
+            map.put( ATTR_WRITE_PERM, String.valueOf(user.authorize(new WriteRequest()) != null) );
             map.put( ATTR_MAX_IDLE_TIME, new Integer(user.getMaxIdleTime()) );
             
             
@@ -306,8 +431,7 @@
             log.info(sql);
             
             // execute query
-            prepareConnection();
-            stmt = connection.createStatement();
+            stmt = createConnection().createStatement();
             stmt.executeUpdate(sql);
         }
         catch(SQLException ex) {
@@ -342,8 +466,7 @@
             log.info(sql);
             
             // execute query
-            prepareConnection();
-            stmt = connection.createStatement();
+            stmt = createConnection().createStatement();
             rs = stmt.executeQuery(sql);
             
             // populate user object
@@ -357,13 +480,12 @@
                 thisUser.setMaxIdleTime(rs.getInt(ATTR_MAX_IDLE_TIME));
                 
                 List authorities = new ArrayList();
-                
                 if(trueStr.equalsIgnoreCase(rs.getString(ATTR_WRITE_PERM))) {
                     authorities.add(new WritePermission());
                 }
                 
                 authorities.add(new ConcurrentLoginPermission(rs.getInt(ATTR_MAX_LOGIN_NUMBER), rs.getInt(ATTR_MAX_LOGIN_PER_IP)));
-                authorities.add(new TransferRatePermission(rs.getInt(ATTR_MAX_UPLOAD_RATE), rs.getInt(ATTR_MAX_DOWNLOAD_RATE)));
+                authorities.add(new TransferRatePermission(rs.getInt(ATTR_MAX_DOWNLOAD_RATE), rs.getInt(ATTR_MAX_UPLOAD_RATE)));
                 
                 thisUser.setAuthorities((Authority[]) authorities.toArray(new Authority[0]));
             }
@@ -408,8 +530,7 @@
             log.info(sql);
             
             // execute query
-            prepareConnection();
-            stmt = connection.createStatement();
+            stmt = createConnection().createStatement();
             rs = stmt.executeQuery(sql);
             return rs.next();
         }
@@ -451,8 +572,7 @@
             log.info(sql);
             
             // execute query
-            prepareConnection();
-            stmt = connection.createStatement();
+            stmt = createConnection().createStatement();
             rs = stmt.executeQuery(sql);
             
             // populate list
@@ -515,8 +635,7 @@
         Statement stmt = null;
         ResultSet rs = null;
         try {
-            prepareConnection();
-            stmt = connection.createStatement();
+            stmt = createConnection().createStatement();
             rs = stmt.executeQuery(sql);
             if (rs.next()) {
                 password = rs.getString(ATTR_PASSWORD);
@@ -577,8 +696,7 @@
                 log.info(sql);
                 
                 // execute query
-                prepareConnection();
-                stmt = connection.createStatement();
+                stmt = createConnection().createStatement();
                 rs = stmt.executeQuery(sql);
                 if(rs.next()) {
                     try {
@@ -639,6 +757,10 @@
      * Escape string to be embedded in SQL statement.
      */
     private String escapeString(String input) {
+        if(input == null) {
+            return input;
+        }
+        
         StringBuffer valBuf = new StringBuffer(input);
         for (int i=0; i<valBuf.length(); i++) {
             char ch = valBuf.charAt(i);

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/usermanager/PropertiesUserManager.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/usermanager/PropertiesUserManager.java?view=diff&rev=506520&r1=506519&r2=506520
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/usermanager/PropertiesUserManager.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/usermanager/PropertiesUserManager.java Mon Feb 12 08:21:40 2007
@@ -30,6 +30,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.ftpserver.FtpServerConfigurationException;
 import org.apache.ftpserver.ftplet.Authentication;
 import org.apache.ftpserver.ftplet.AuthenticationFailedException;
 import org.apache.ftpserver.ftplet.Authority;
@@ -55,7 +56,7 @@
     private BaseProperties userDataProp;
     private File           userDataFile = new File("./res/user.gen");
     private boolean        isPasswordEncrypt = true;
-    private String         adminName = "admin";
+
 
     private boolean isConfigured = false;
     
@@ -115,26 +116,31 @@
     /**
      * Configure user manager.
      */
-    public void configure() throws FtpException {
-        try {
-            isConfigured  = true;
-            File dir = userDataFile.getParentFile();
-            if( (!dir.exists()) && (!dir.mkdirs()) ) {
-                String dirName = dir.getAbsolutePath();
-                throw new IOException("Cannot create directory : " + dirName);
+public void configure() {
+        isConfigured  = true;
+        File dir = userDataFile.getParentFile();
+        if( (!dir.exists()) && (!dir.mkdirs()) ) {
+            String dirName = dir.getAbsolutePath();
+            throw new FtpServerConfigurationException("Cannot create directory for user data file : " + dirName);
+        }
+        
+        if(!userDataFile.exists()) {
+            try {
+                userDataFile.createNewFile();
+            } catch (IOException e) {
+                throw new FtpServerConfigurationException("Cannot user data file : " + userDataFile.getAbsolutePath(), e);
             }
-            userDataFile.createNewFile();
-            userDataProp = new BaseProperties(userDataFile);
-            
-            convertDeprecatedPropertyNames();
         }
-        catch(IOException ex) {
-            log.fatal("PropertiesUserManager.configure()", ex);
-            throw new FtpException("PropertiesUserManager.configure()", ex);
+        try {
+            userDataProp = new BaseProperties(userDataFile);
+        } catch (IOException e) {
+            throw new FtpServerConfigurationException("Error loading user data file : " + userDataFile.getAbsolutePath(), e);
         }
+        
+        convertDeprecatedPropertyNames();
     }
     
-    private void convertDeprecatedPropertyNames() throws FtpException {
+    private void convertDeprecatedPropertyNames() {
         Enumeration keys = userDataProp.propertyNames();
         
         boolean doSave = false;
@@ -152,41 +158,14 @@
         }
         
         if(doSave) {
-            saveUserData();
+            try {
+                saveUserData();
+            } catch (FtpException e) {
+                throw new FtpServerConfigurationException("Failed to save updated user data", e);
+            }
         }
     }
 
-    /**
-     * Get the admin name.
-     */
-    public String getAdminName() {
-        return adminName;
-    }
-    
-    /**
-     * Set the name to use as the administrator of the server.
-     * The default value is "admin".
-     * @param adminName The administrator user name
-     */
-    public void setAdminName(String adminName) {
-        this.adminName = adminName;
-    }
-
-    /**
-     * Set the name to use as the administrator of the server
-     * @param adminName The administrator user name
-     * @deprecated Use {@link #setAdminName(String)} instead
-     */
-    public void setAdmin(String adminName) {
-        this.adminName = adminName;
-    }
-    
-    /**
-     * @return true if user with this login is administrator
-     */
-    public boolean isAdmin(String login) throws FtpException {
-        return adminName.equals(login);
-    }
     
     /**
      * Save user data. Store the properties.

Added: incubator/ftpserver/trunk/core/src/test/dbusermanagertest-hsql.sql
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/dbusermanagertest-hsql.sql?view=auto&rev=506520
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/dbusermanagertest-hsql.sql (added)
+++ incubator/ftpserver/trunk/core/src/test/dbusermanagertest-hsql.sql Mon Feb 12 08:21:40 2007
@@ -0,0 +1,35 @@
+-- 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.
+
+CREATE TABLE FTP_USER (      
+   uid VARCHAR(64) NOT NULL PRIMARY KEY,       
+   userpassword VARCHAR(64),      
+   homedirectory VARCHAR(128) NOT NULL,             
+   enableflag BOOLEAN DEFAULT TRUE,    
+   writepermission BOOLEAN DEFAULT FALSE,       
+   idletime INT DEFAULT 0,             
+   uploadrate INT DEFAULT 0,             
+   downloadrate INT DEFAULT 0,
+   maxloginnumber INT DEFAULT 0,
+   maxloginperip INT DEFAULT 0
+);
+
+INSERT INTO FTP_USER (uid, userpassword, homedirectory) VALUES ('user1', 'pw1', 'home');
+INSERT INTO FTP_USER VALUES ('user2', 'pw2', 'home', false, true, 2, 5, 1, 3, 4);
+INSERT INTO FTP_USER (uid, userpassword, homedirectory) VALUES ('user3', '', 'home');
+INSERT INTO FTP_USER (uid, userpassword, homedirectory) VALUES ('admin', 'admin', 'home');
+

Propchange: incubator/ftpserver/trunk/core/src/test/dbusermanagertest-hsql.sql
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/usermanager/DbUserManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/usermanager/DbUserManagerTest.java?view=auto&rev=506520
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/usermanager/DbUserManagerTest.java (added)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/usermanager/DbUserManagerTest.java Mon Feb 12 08:21:40 2007
@@ -0,0 +1,92 @@
+/*
+ * 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.ftpserver.usermanager;
+
+import java.io.File;
+import java.io.FileReader;
+import java.sql.Connection;
+import java.sql.Statement;
+
+import org.apache.commons.logging.LogFactory;
+import org.apache.ftpserver.ftplet.FtpException;
+import org.apache.ftpserver.ftplet.UserManager;
+import org.apache.ftpserver.test.TestUtil;
+import org.apache.ftpserver.util.IoUtils;
+import org.hsqldb.jdbc.jdbcDataSource;
+
+public class DbUserManagerTest extends UserManagerTestTemplate {
+
+    private static final File INIT_SQL_SCRIPT = new File(TestUtil.getBaseDir(), "src/test/dbusermanagertest-hsql.sql");
+    
+    private jdbcDataSource ds;
+    private Connection conn;
+    
+    private void createDatabase() throws Exception {
+        conn = ds.getConnection();
+        conn.setAutoCommit(true);
+        
+        String ddl = IoUtils.readFully(new FileReader(INIT_SQL_SCRIPT));
+        
+        Statement stm = conn.createStatement();
+        stm.execute(ddl);
+    }
+    
+    protected UserManager createUserManager() throws FtpException {
+        DbUserManager manager = new DbUserManager();
+        
+        manager.setLogFactory(LogFactory.getFactory());
+        
+        manager.setDataSource(ds);
+        manager.setSqlUserInsert("INSERT INTO FTP_USER (uid, userpassword, homedirectory, enableflag, writepermission, idletime, uploadrate, downloadrate, maxloginnumber, maxloginperip) VALUES ('{uid}', '{userpassword}', '{homedirectory}', '{enableflag}', '{writepermission}', {idletime}, {uploadrate}, {downloadrate}, {maxloginnumber}, {maxloginperip})");
+        manager.setSqlUserUpdate("UPDATE FTP_USER SET userpassword='{userpassword}',homedirectory='{homedirectory}',enableflag='{enableflag}',writepermission='{writepermission}',idletime={idletime},uploadrate={uploadrate},downloadrate={downloadrate},maxloginnumber={maxloginnumber}, maxloginperip={maxloginperip} WHERE uid='{uid}'");
+        manager.setSqlUserDelete("DELETE FROM FTP_USER WHERE uid = '{uid}'");
+        manager.setSqlUserSelect("SELECT * FROM FTP_USER WHERE uid = '{uid}'");
+        manager.setSqlUserSelectAll("SELECT uid FROM FTP_USER ORDER BY uid");
+        manager.setSqlUserAuthenticate("SELECT uid FROM FTP_USER WHERE uid='{uid}' AND userpassword='{userpassword}'");
+        manager.setSqlUserAdmin("SELECT uid FROM FTP_USER WHERE uid='{uid}' AND uid='admin'");
+        
+        return manager;
+        
+    }
+    
+    /* (non-Javadoc)
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception {
+        ds = new jdbcDataSource();
+        ds.setDatabase("jdbc:hsqldb:mem:ftpd");
+        ds.setUser("sa");
+        ds.setPassword("");
+        
+        
+        createDatabase();
+        
+        super.setUp();
+    }
+
+
+    protected void tearDown() throws Exception {
+        Statement stm = conn.createStatement();
+        stm.execute("SHUTDOWN");
+        
+        super.tearDown();
+    }
+    
+}

Propchange: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/usermanager/DbUserManagerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/usermanager/PropertiesUserManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/usermanager/PropertiesUserManagerTest.java?view=diff&rev=506520&r1=506519&r2=506520
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/usermanager/PropertiesUserManagerTest.java (original)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/usermanager/PropertiesUserManagerTest.java Mon Feb 12 08:21:40 2007
@@ -62,7 +62,7 @@
     protected UserManager createUserManager() throws FtpException {
         PropertiesUserManager um = new PropertiesUserManager();
         um.setPropFile(USERS_FILE);
-        um.setPropPasswordEncrypt(false);
+        um.setEncryptPasswords(false);
         um.configure();
         
         return um;