You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by ng...@apache.org on 2008/08/17 21:52:49 UTC

svn commit: r686637 [9/16] - in /mina/ftpserver/trunk: core/src/main/java/org/apache/ftpserver/ core/src/main/java/org/apache/ftpserver/command/ core/src/main/java/org/apache/ftpserver/config/spring/ core/src/main/java/org/apache/ftpserver/filesystem/ ...

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/AbstractUserManager.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/AbstractUserManager.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/AbstractUserManager.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/AbstractUserManager.java Sun Aug 17 12:52:42 2008
@@ -15,33 +15,42 @@
  * 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 org.apache.ftpserver.ftplet.FtpException;
 import org.apache.ftpserver.ftplet.UserManager;
 
-
 /**
  * Abstract common base type for {@link UserManager} implementations
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
  */
-public abstract 
-class AbstractUserManager implements UserManager {
+public abstract class AbstractUserManager implements UserManager {
+
+    public static final String ATTR_LOGIN = "userid";
+
+    public static final String ATTR_PASSWORD = "userpassword";
+
+    public static final String ATTR_HOME = "homedirectory";
+
+    public static final String ATTR_WRITE_PERM = "writepermission";
+
+    public static final String ATTR_ENABLE = "enableflag";
+
+    public static final String ATTR_MAX_IDLE_TIME = "idletime";
+
+    public static final String ATTR_MAX_UPLOAD_RATE = "uploadrate";
 
-    public static final String ATTR_LOGIN             = "userid";
-    public static final String ATTR_PASSWORD          = "userpassword";
-    public static final String ATTR_HOME              = "homedirectory";
-    public static final String ATTR_WRITE_PERM        = "writepermission";
-    public static final String ATTR_ENABLE            = "enableflag";
-    public static final String ATTR_MAX_IDLE_TIME     = "idletime";
-    public static final String ATTR_MAX_UPLOAD_RATE   = "uploadrate";
     public static final String ATTR_MAX_DOWNLOAD_RATE = "downloadrate";
-    public static final String ATTR_MAX_LOGIN_NUMBER  = "maxloginnumber";
-    public static final String ATTR_MAX_LOGIN_PER_IP  = "maxloginperip";
 
-    private String         adminName = "admin";
-    
+    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.
@@ -49,11 +58,13 @@
     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
+     * 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;
@@ -61,15 +72,15 @@
 
     /**
      * Set the name to use as the administrator of the server
-     * @param adminName The administrator user name
+     * 
+     * @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
      */
@@ -77,4 +88,3 @@
         return adminName.equals(login);
     }
 }
-

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/AnonymousAuthentication.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/AnonymousAuthentication.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/AnonymousAuthentication.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/AnonymousAuthentication.java Sun Aug 17 12:52:42 2008
@@ -15,7 +15,7 @@
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
- */  
+ */
 
 package org.apache.ftpserver.usermanager;
 
@@ -23,9 +23,12 @@
 
 /**
  * Class representing an anonymous authentication attempt
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
  */
 public class AnonymousAuthentication implements Authentication {
-   
+
     private UserMetadata userMetadata;
 
     /**
@@ -34,23 +37,24 @@
     public AnonymousAuthentication() {
         // empty
     }
-    
-    
+
     /**
      * Constructor with an additional user metadata parameter
-     * @param userMetadata User metadata
+     * 
+     * @param userMetadata
+     *            User metadata
      */
     public AnonymousAuthentication(UserMetadata userMetadata) {
         this.userMetadata = userMetadata;
     }
 
-
     /**
      * Retrive the user metadata
+     * 
      * @return The user metadata
      */
     public UserMetadata getUserMetadata() {
         return userMetadata;
     }
-    
+
 }

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/BaseUser.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/BaseUser.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/BaseUser.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/BaseUser.java Sun Aug 17 12:52:42 2008
@@ -15,7 +15,7 @@
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
- */  
+ */
 
 package org.apache.ftpserver.usermanager;
 
@@ -28,41 +28,44 @@
 import org.apache.ftpserver.ftplet.User;
 
 /**
- * Generic user class. 
- * The user attributes are:
+ * Generic user class. The user attributes are:
  * <ul>
- *   <li>userid</li>
- *   <li>userpassword</li>
- *   <li>enableflag</li>
- *   <li>homedirectory</li>
- *   <li>writepermission</li>
- *   <li>idletime</li>
- *   <li>uploadrate</li>
- *   <li>downloadrate</li>
+ * <li>userid</li>
+ * <li>userpassword</li>
+ * <li>enableflag</li>
+ * <li>homedirectory</li>
+ * <li>writepermission</li>
+ * <li>idletime</li>
+ * <li>uploadrate</li>
+ * <li>downloadrate</li>
  * </ul>
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
  */
 
-public
-class BaseUser implements User, Serializable {
-    
+public class BaseUser implements User, Serializable {
+
     private static final long serialVersionUID = -47371353779731294L;
-    
-    private String name        = null;
-    private String password    = null;
 
-    private int maxIdleTimeSec  = 0; // no limit
+    private String name = null;
+
+    private String password = null;
+
+    private int maxIdleTimeSec = 0; // no limit
+
+    private String homeDir = null;
 
-    private String homeDir    = null;
     private boolean isEnabled = true;
 
     private Authority[] authorities = new Authority[0];
-    
+
     /**
      * Default constructor.
      */
     public BaseUser() {
     }
-    
+
     /**
      * Copy constructor.
      */
@@ -74,28 +77,28 @@
         homeDir = user.getHomeDirectory();
         isEnabled = user.getEnabled();
     }
-    
+
     /**
      * Get the user name.
      */
     public String getName() {
         return name;
     }
-        
+
     /**
      * Set user name.
      */
     public void setName(String name) {
         this.name = name;
     }
-    
+
     /**
      * Get the user password.
      */
     public String getPassword() {
         return password;
     }
-    
+
     /**
      * Set user password.
      */
@@ -104,7 +107,7 @@
     }
 
     public Authority[] getAuthorities() {
-        if(authorities != null) {
+        if (authorities != null) {
             return authorities.clone();
         } else {
             return null;
@@ -112,13 +115,13 @@
     }
 
     public void setAuthorities(Authority[] authorities) {
-        if(authorities != null) {
+        if (authorities != null) {
             this.authorities = authorities.clone();
         } else {
             this.authorities = null;
         }
     }
-    
+
     /**
      * Get the maximum idle time in second.
      */
@@ -131,7 +134,7 @@
      */
     public void setMaxIdleTime(int idleSec) {
         maxIdleTimeSec = idleSec;
-        if(maxIdleTimeSec < 0) {
+        if (maxIdleTimeSec < 0) {
             maxIdleTimeSec = 0;
         }
     }
@@ -142,14 +145,14 @@
     public boolean getEnabled() {
         return isEnabled;
     }
-    
+
     /**
      * Set the user enable status.
      */
     public void setEnabled(boolean enb) {
         isEnabled = enb;
     }
-    
+
     /**
      * Get the user home directory.
      */
@@ -164,38 +167,37 @@
         homeDir = home;
     }
 
-
-    /** 
+    /**
      * String representation.
      */
     public String toString() {
         return name;
-    }  
-    
+    }
+
     /**
      * {@inheritDoc}
      */
     public AuthorizationRequest authorize(AuthorizationRequest request) {
         Authority[] authorities = getAuthorities();
-        
+
         boolean someoneCouldAuthorize = false;
         for (int i = 0; i < authorities.length; i++) {
             Authority authority = authorities[i];
-            
-            if(authority.canAuthorize(request)) {
+
+            if (authority.canAuthorize(request)) {
                 someoneCouldAuthorize = true;
-                
+
                 request = authority.authorize(request);
-                
+
                 // authorization failed, return null
-                if(request == null) {
+                if (request == null) {
                     return null;
                 }
             }
-            
+
         }
-        
-        if(someoneCouldAuthorize) {
+
+        if (someoneCouldAuthorize) {
             return request;
         } else {
             return null;
@@ -207,13 +209,13 @@
      */
     public Authority[] getAuthorities(Class<? extends Authority> clazz) {
         List<Authority> selected = new ArrayList<Authority>();
-        
+
         for (int i = 0; i < authorities.length; i++) {
-            if(authorities[i].getClass().equals(clazz)) {
+            if (authorities[i].getClass().equals(clazz)) {
                 selected.add(authorities[i]);
             }
         }
-        
+
         return selected.toArray(new Authority[0]);
     }
 }

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/ConcurrentLoginPermission.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/ConcurrentLoginPermission.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/ConcurrentLoginPermission.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/ConcurrentLoginPermission.java Sun Aug 17 12:52:42 2008
@@ -15,7 +15,7 @@
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
- */  
+ */
 
 package org.apache.ftpserver.usermanager;
 
@@ -24,33 +24,43 @@
 
 /**
  * The max upload rate permission
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
  */
 public class ConcurrentLoginPermission implements Authority {
 
     private int maxConcurrentLogins;
+
     private int maxConcurrentLoginsPerIP;
 
-    public ConcurrentLoginPermission(int maxConcurrentLogins, int maxConcurrentLoginsPerIP) {
+    public ConcurrentLoginPermission(int maxConcurrentLogins,
+            int maxConcurrentLoginsPerIP) {
         this.maxConcurrentLogins = maxConcurrentLogins;
         this.maxConcurrentLoginsPerIP = maxConcurrentLoginsPerIP;
     }
-    
+
     /**
      * @see Authority#authorize(AuthorizationRequest)
      */
     public AuthorizationRequest authorize(AuthorizationRequest request) {
         if (request instanceof ConcurrentLoginRequest) {
             ConcurrentLoginRequest concurrentLoginRequest = (ConcurrentLoginRequest) request;
-            
-            if(maxConcurrentLogins != 0 && maxConcurrentLogins < concurrentLoginRequest.getConcurrentLogins()) {
-                return null; 
-            } else if(maxConcurrentLoginsPerIP != 0 
-                    && maxConcurrentLoginsPerIP < concurrentLoginRequest.getConcurrentLoginsFromThisIP()) {
+
+            if (maxConcurrentLogins != 0
+                    && maxConcurrentLogins < concurrentLoginRequest
+                            .getConcurrentLogins()) {
+                return null;
+            } else if (maxConcurrentLoginsPerIP != 0
+                    && maxConcurrentLoginsPerIP < concurrentLoginRequest
+                            .getConcurrentLoginsFromThisIP()) {
                 return null;
             } else {
-                concurrentLoginRequest.setMaxConcurrentLogins(maxConcurrentLogins);
-                concurrentLoginRequest.setMaxConcurrentLoginsPerIP(maxConcurrentLoginsPerIP);
-                
+                concurrentLoginRequest
+                        .setMaxConcurrentLogins(maxConcurrentLogins);
+                concurrentLoginRequest
+                        .setMaxConcurrentLoginsPerIP(maxConcurrentLoginsPerIP);
+
                 return concurrentLoginRequest;
             }
         } else {

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/ConcurrentLoginRequest.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/ConcurrentLoginRequest.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/ConcurrentLoginRequest.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/ConcurrentLoginRequest.java Sun Aug 17 12:52:42 2008
@@ -15,7 +15,7 @@
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
- */  
+ */
 
 package org.apache.ftpserver.usermanager;
 
@@ -23,71 +23,86 @@
 
 /**
  * Class representing a request to log in a number of concurrent times
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
  */
 public class ConcurrentLoginRequest implements AuthorizationRequest {
-   
+
     private int concurrentLogins;
+
     private int concurrentLoginsFromThisIP;
-    
+
     private int maxConcurrentLogins = 0;
+
     private int maxConcurrentLoginsPerIP = 0;
-    
 
     /**
      * @param concurrentLogins
      * @param concurrentLoginsFromThisIP
      */
-    public ConcurrentLoginRequest(int concurrentLogins, int concurrentLoginsFromThisIP) {
+    public ConcurrentLoginRequest(int concurrentLogins,
+            int concurrentLoginsFromThisIP) {
         super();
         this.concurrentLogins = concurrentLogins;
         this.concurrentLoginsFromThisIP = concurrentLoginsFromThisIP;
     }
+
     /**
      * The number of concurrent logins requested
+     * 
      * @return the concurrentLogins The number of current concurrent logins
      */
     public int getConcurrentLogins() {
         return concurrentLogins;
     }
+
     /**
      * The number of concurrent logins from this IP requested
-     * @return the concurrentLoginsFromThisIP
-     *   The number of current concurrent logins from this IP
+     * 
+     * @return the concurrentLoginsFromThisIP The number of current concurrent
+     *         logins from this IP
      */
     public int getConcurrentLoginsFromThisIP() {
         return concurrentLoginsFromThisIP;
     }
-    
+
     /**
-     * The maximum allowed concurrent logins for this user, or
-     * 0 if no limit is set. This is normally populated by 
-     * {@link ConcurrentLoginPermission}
+     * The maximum allowed concurrent logins for this user, or 0 if no limit is
+     * set. This is normally populated by {@link ConcurrentLoginPermission}
+     * 
      * @return The maximum allowed concurrent logins
      */
     public int getMaxConcurrentLogins() {
         return maxConcurrentLogins;
     }
+
     /**
      * Set the maximum allowed concurrent logins for this user
-     * @param maxConcurrentLogins Set max allowed concurrent connections
+     * 
+     * @param maxConcurrentLogins
+     *            Set max allowed concurrent connections
      */
     void setMaxConcurrentLogins(int maxConcurrentLogins) {
         this.maxConcurrentLogins = maxConcurrentLogins;
     }
-    
+
     /**
-     * The maximum allowed concurrent logins per IP for this user, or
-     * 0 if no limit is set. This is normally populated by 
+     * The maximum allowed concurrent logins per IP for this user, or 0 if no
+     * limit is set. This is normally populated by
      * {@link ConcurrentLoginPermission}
+     * 
      * @return The maximum allowed concurrent logins per IP
      */
     public int getMaxConcurrentLoginsPerIP() {
         return maxConcurrentLoginsPerIP;
     }
+
     /**
      * Set the maximum allowed concurrent logins per IP for this user
-     * @param maxConcurrentLoginsPerIP 
-     *     Set max allowed concurrent connections per IP
+     * 
+     * @param maxConcurrentLoginsPerIP
+     *            Set max allowed concurrent connections per IP
      */
     void setMaxConcurrentLoginsPerIP(int maxConcurrentLoginsPerIP) {
         this.maxConcurrentLoginsPerIP = maxConcurrentLoginsPerIP;

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/DbUserManager.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/DbUserManager.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/DbUserManager.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/DbUserManager.java Sun Aug 17 12:52:42 2008
@@ -15,7 +15,7 @@
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
- */  
+ */
 
 package org.apache.ftpserver.usermanager;
 
@@ -40,587 +40,619 @@
 import org.slf4j.LoggerFactory;
 
 /**
- * This is another database based user manager class. It has been
- * tested in MySQL and Oracle 8i database. The schema file is 
- * </code>res/ftp-db.sql</code>
+ * This is another database based user manager class. It has been tested in
+ * MySQL and Oracle 8i database. The schema file is </code>res/ftp-db.sql</code>
+ * 
+ * All the user attributes are replaced during run-time. So we can use your
+ * database schema. Then you need to modify the SQLs in the configuration file.
  *
- * All the user attributes are replaced during run-time. So we can use
- * your database schema. Then you need to modify the SQLs in the configuration
- * file.
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
  */
 public class DbUserManager extends AbstractUserManager {
-    
+
     private final Logger LOG = LoggerFactory.getLogger(DbUserManager.class);
-    
+
     private String insertUserStmt;
+
     private String updateUserStmt;
+
     private String deleteUserStmt;
+
     private String selectUserStmt;
+
     private String selectAllStmt;
+
     private String isAdminStmt;
+
     private String authenticateStmt;
 
     private DataSource dataSource;
+
     private Connection cachedConnection;
 
-    // Set to true when the user manager has been configured, 
+    // Set to true when the user manager has been configured,
     // used for lazy init.
     private boolean configured = false;
-    
+
     /**
      * 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
+     * 
+     * @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
+     * 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 deleteUserStmt;
     }
-    
+
     /**
-     * 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
+     * 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
+     * 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
+     * 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
+     * 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 authenticateStmt;
     }
-    
+
     /**
-     * Set the SQL SELECT statement used to authenticate user. All the dynamic values will be replaced during runtime.
-     * @param sql The SQL statement
+     * 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.
+     * Get the SQL SELECT statement used to find whether an user is admin or
+     * not.
+     * 
      * @return The SQL statement
      */
     public String getSqlUserAdmin() {
         return isAdminStmt;
     }
-    
+
     /**
-     * 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
+     * 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;
     }
-    
+
     /**
      * Lazy init the user manager
      */
     private void lazyInit() {
-        if(!configured) {
+        if (!configured) {
             configure();
         }
     }
-    
+
     /**
      * Configure user manager.
      */
     public void configure() {
         configured = true;
-        
-        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 (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");
         }
-        if(authenticateStmt == null) {
-            throw new FtpServerConfigurationException("Required authenticate user SQL statement not provided");
-        }        
-        
+
         try {
             // test the connection
             createConnection();
-            
+
             LOG.info("Database connection opened.");
-        }
-        catch(SQLException ex) {
+        } catch (SQLException ex) {
             LOG.error("DbUserManager.configure()", ex);
-            throw new FtpServerConfigurationException("DbUserManager.configure()", ex);
+            throw new FtpServerConfigurationException(
+                    "DbUserManager.configure()", ex);
         }
     }
-    
+
     /**
      * @return true if user with this login is administrator
      */
     public boolean isAdmin(String login) throws FtpException {
-        
+
         // check input
-        if(login == null) {
+        if (login == null) {
             return false;
         }
-        
+
         Statement stmt = null;
         ResultSet rs = null;
         try {
-            
+
             // create the sql query
             HashMap<String, Object> map = new HashMap<String, Object>();
-            map.put( ATTR_LOGIN, escapeString(login) );
+            map.put(ATTR_LOGIN, escapeString(login));
             String sql = StringUtils.replaceString(isAdminStmt, map);
             LOG.info(sql);
-            
+
             // execute query
             stmt = createConnection().createStatement();
             rs = stmt.executeQuery(sql);
             return rs.next();
-        }
-        catch(SQLException ex) {
+        } catch (SQLException ex) {
             LOG.error("DbUserManager.isAdmin()", ex);
             throw new FtpException("DbUserManager.isAdmin()", ex);
-        }
-        finally {
-            if(rs != null) {
-                try { 
-                    rs.close(); 
-                } 
-                catch(Exception ex) {
+        } finally {
+            if (rs != null) {
+                try {
+                    rs.close();
+                } catch (Exception ex) {
                     LOG.error("DbUserManager.isAdmin()", ex);
                 }
             }
-            if(stmt != null) {
-                try { 
-                    stmt.close(); 
-                } 
-                catch(Exception ex) {
+            if (stmt != null) {
+                try {
+                    stmt.close();
+                } catch (Exception ex) {
                     LOG.error("DbUserManager.isAdmin()", ex);
                 }
             }
         }
     }
-    
+
     /**
      * Open connection to database.
      */
     private synchronized Connection createConnection() throws SQLException {
-        boolean isClosed = false;    
+        boolean isClosed = false;
         try {
-            if( (cachedConnection == null) || cachedConnection.isClosed() ) {
+            if ((cachedConnection == null) || cachedConnection.isClosed()) {
                 isClosed = true;
             }
-        }
-        catch(SQLException ex) {
+        } 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 (cachedConnection != null) {        
+        if (cachedConnection != null) {
             try {
-                cachedConnection.close(); 
-            } 
-            catch(SQLException ex) {
+                cachedConnection.close();
+            } catch (SQLException ex) {
                 LOG.error("DbUserManager.closeConnection()", ex);
             }
             cachedConnection = null;
         }
-        
+
         LOG.info("Database connection closed.");
     }
-    
+
     /**
      * Delete user. Delete the row from the table.
      */
     public synchronized void delete(String name) throws FtpException {
         lazyInit();
-        
+
         // create sql query
         HashMap<String, Object> map = new HashMap<String, Object>();
-        map.put( ATTR_LOGIN, escapeString(name) );
+        map.put(ATTR_LOGIN, escapeString(name));
         String sql = StringUtils.replaceString(deleteUserStmt, map);
         LOG.info(sql);
-        
+
         // execute query
         Statement stmt = null;
         try {
             stmt = createConnection().createStatement();
             stmt.executeUpdate(sql);
-        }
-        catch(SQLException ex) {
+        } catch (SQLException ex) {
             LOG.error("DbUserManager.delete()", ex);
             throw new FtpException("DbUserManager.delete()", ex);
-        }
-        finally {
-            if(stmt != null) {
-                try { 
-                    stmt.close(); 
-                } 
-                catch(Exception ex) {
+        } finally {
+            if (stmt != null) {
+                try {
+                    stmt.close();
+                } catch (Exception ex) {
                     LOG.error("DbUserManager.delete()", ex);
                 }
             }
         }
     }
-    
+
     /**
      * Save user. If new insert a new row, else update the existing row.
      */
     public synchronized void save(User user) throws FtpException {
         lazyInit();
-        
+
         // null value check
-        if(user.getName() == null) {
+        if (user.getName() == null) {
             throw new NullPointerException("User name is null.");
-        } 
-        
+        }
+
         Statement stmt = null;
         try {
-            
+
             // create sql query
             HashMap<String, Object> map = new HashMap<String, Object>();
-            map.put( ATTR_LOGIN, escapeString(user.getName()) );
-            map.put( ATTR_PASSWORD, escapeString(getPassword(user)) );
-            
+            map.put(ATTR_LOGIN, escapeString(user.getName()));
+            map.put(ATTR_PASSWORD, escapeString(getPassword(user)));
+
             String home = user.getHomeDirectory();
-            if(home == null) {
+            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()) != null) );
-            map.put( ATTR_MAX_IDLE_TIME, user.getMaxIdleTime() );
-            
-            
+            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()) != null));
+            map.put(ATTR_MAX_IDLE_TIME, user.getMaxIdleTime());
+
             TransferRateRequest transferRateRequest = new TransferRateRequest();
-            transferRateRequest = (TransferRateRequest) user.authorize(transferRateRequest);
-            
-            if(transferRateRequest != null) {
-                map.put( ATTR_MAX_UPLOAD_RATE, transferRateRequest.getMaxUploadRate() );
-                map.put( ATTR_MAX_DOWNLOAD_RATE, transferRateRequest.getMaxDownloadRate() ); 
+            transferRateRequest = (TransferRateRequest) user
+                    .authorize(transferRateRequest);
+
+            if (transferRateRequest != null) {
+                map.put(ATTR_MAX_UPLOAD_RATE, transferRateRequest
+                        .getMaxUploadRate());
+                map.put(ATTR_MAX_DOWNLOAD_RATE, transferRateRequest
+                        .getMaxDownloadRate());
             } else {
-                map.put( ATTR_MAX_UPLOAD_RATE, 0);
-                map.put( ATTR_MAX_DOWNLOAD_RATE, 0 ); 
+                map.put(ATTR_MAX_UPLOAD_RATE, 0);
+                map.put(ATTR_MAX_DOWNLOAD_RATE, 0);
             }
 
             // request that always will succeed
-            ConcurrentLoginRequest concurrentLoginRequest = new ConcurrentLoginRequest(0, 0);
-            concurrentLoginRequest = (ConcurrentLoginRequest) user.authorize(concurrentLoginRequest);
-            
-            if(concurrentLoginRequest != null) {
-                map.put( ATTR_MAX_LOGIN_NUMBER, 
-                        concurrentLoginRequest.getMaxConcurrentLogins());
-                map.put( ATTR_MAX_LOGIN_PER_IP, 
-                        concurrentLoginRequest.getMaxConcurrentLoginsPerIP());
+            ConcurrentLoginRequest concurrentLoginRequest = new ConcurrentLoginRequest(
+                    0, 0);
+            concurrentLoginRequest = (ConcurrentLoginRequest) user
+                    .authorize(concurrentLoginRequest);
+
+            if (concurrentLoginRequest != null) {
+                map.put(ATTR_MAX_LOGIN_NUMBER, concurrentLoginRequest
+                        .getMaxConcurrentLogins());
+                map.put(ATTR_MAX_LOGIN_PER_IP, concurrentLoginRequest
+                        .getMaxConcurrentLoginsPerIP());
             } else {
-                map.put( ATTR_MAX_LOGIN_NUMBER, 0);
-                map.put( ATTR_MAX_LOGIN_PER_IP, 0);
+                map.put(ATTR_MAX_LOGIN_NUMBER, 0);
+                map.put(ATTR_MAX_LOGIN_PER_IP, 0);
             }
-            
 
-            
-            String sql = null;      
-            if( !doesExist(user.getName()) ) {
+            String sql = null;
+            if (!doesExist(user.getName())) {
                 sql = StringUtils.replaceString(insertUserStmt, map);
-            }
-            else {
+            } else {
                 sql = StringUtils.replaceString(updateUserStmt, map);
             }
             LOG.info(sql);
-            
+
             // execute query
             stmt = createConnection().createStatement();
             stmt.executeUpdate(sql);
-        }
-        catch(SQLException ex) {
+        } catch (SQLException ex) {
             LOG.error("DbUserManager.save()", ex);
             throw new FtpException("DbUserManager.save()", ex);
-        }
-        finally {
-            if(stmt != null) {
-                try { 
-                    stmt.close(); 
-                } 
-                catch(Exception ex) {
+        } finally {
+            if (stmt != null) {
+                try {
+                    stmt.close();
+                } catch (Exception ex) {
                     LOG.error("DbUsermanager.error()", ex);
                 }
             }
         }
     }
-    
+
     /**
      * Get the user object. Fetch the row from the table.
      */
     public synchronized User getUserByName(String name) throws FtpException {
         lazyInit();
-        
+
         Statement stmt = null;
         ResultSet rs = null;
         try {
-            
+
             // create sql query
             HashMap<String, Object> map = new HashMap<String, Object>();
-            map.put( ATTR_LOGIN, escapeString(name) );
+            map.put(ATTR_LOGIN, escapeString(name));
             String sql = StringUtils.replaceString(selectUserStmt, map);
             LOG.info(sql);
-            
+
             // execute query
             stmt = createConnection().createStatement();
             rs = stmt.executeQuery(sql);
-            
+
             // populate user object
             BaseUser thisUser = null;
             String trueStr = Boolean.TRUE.toString();
-            if(rs.next()) {
+            if (rs.next()) {
                 thisUser = new BaseUser();
                 thisUser.setName(rs.getString(ATTR_LOGIN));
                 thisUser.setHomeDirectory(rs.getString(ATTR_HOME));
-                thisUser.setEnabled(trueStr.equalsIgnoreCase(rs.getString(ATTR_ENABLE)));
+                thisUser.setEnabled(trueStr.equalsIgnoreCase(rs
+                        .getString(ATTR_ENABLE)));
                 thisUser.setMaxIdleTime(rs.getInt(ATTR_MAX_IDLE_TIME));
-                
+
                 List<Authority> authorities = new ArrayList<Authority>();
-                if(trueStr.equalsIgnoreCase(rs.getString(ATTR_WRITE_PERM))) {
+                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_DOWNLOAD_RATE), rs.getInt(ATTR_MAX_UPLOAD_RATE)));
-                
+
+                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_DOWNLOAD_RATE), rs
+                        .getInt(ATTR_MAX_UPLOAD_RATE)));
+
                 thisUser.setAuthorities(authorities.toArray(new Authority[0]));
             }
             return thisUser;
-        }
-        catch(SQLException ex) {
+        } catch (SQLException ex) {
             LOG.error("DbUserManager.getUserByName()", ex);
             throw new FtpException("DbUserManager.getUserByName()", ex);
-        }
-        finally {
-            if(rs != null) {
-                try { 
-                    rs.close(); 
-                } 
-                catch(Exception ex) {
+        } finally {
+            if (rs != null) {
+                try {
+                    rs.close();
+                } catch (Exception ex) {
                     LOG.error("DbUserManager.getUserByName()", ex);
                 }
             }
-            if(stmt != null) {
-                try { 
-                    stmt.close(); 
-                } 
-                catch(Exception ex) {
+            if (stmt != null) {
+                try {
+                    stmt.close();
+                } catch (Exception ex) {
                     LOG.error("DbUserManager.getUserByName()", ex);
                 }
             }
         }
     }
-    
+
     /**
      * User existance check.
      */
     public synchronized boolean doesExist(String name) throws FtpException {
         lazyInit();
-        
+
         Statement stmt = null;
         ResultSet rs = null;
         try {
-            
+
             // create the sql
             HashMap<String, Object> map = new HashMap<String, Object>();
-            map.put( ATTR_LOGIN, escapeString(name) );
+            map.put(ATTR_LOGIN, escapeString(name));
             String sql = StringUtils.replaceString(selectUserStmt, map);
             LOG.info(sql);
-            
+
             // execute query
             stmt = createConnection().createStatement();
             rs = stmt.executeQuery(sql);
             return rs.next();
-        }
-        catch(SQLException ex) {
+        } catch (SQLException ex) {
             LOG.error("DbUserManager.doesExist()", ex);
             throw new FtpException("DbUserManager.doesExist()", ex);
-        }
-        finally {
-            if(rs != null) {
-                try { 
-                    rs.close(); 
-                } 
-                catch(Exception ex) {
+        } finally {
+            if (rs != null) {
+                try {
+                    rs.close();
+                } catch (Exception ex) {
                     LOG.error("DbUserManager.doesExist()", ex);
                 }
             }
-            if(stmt != null) {
-                try { 
-                    stmt.close(); 
-                } 
-                catch(Exception ex) {
+            if (stmt != null) {
+                try {
+                    stmt.close();
+                } catch (Exception ex) {
                     LOG.error("DbUserManager.doesExist()", ex);
                 }
             }
         }
     }
-    
+
     /**
      * Get all user names from the database.
      */
     public synchronized String[] getAllUserNames() throws FtpException {
-        
+
         lazyInit();
-        
+
         Statement stmt = null;
         ResultSet rs = null;
         try {
-            
+
             // create sql query
             String sql = selectAllStmt;
             LOG.info(sql);
-            
+
             // execute query
             stmt = createConnection().createStatement();
             rs = stmt.executeQuery(sql);
-            
+
             // populate list
             ArrayList<String> names = new ArrayList<String>();
-            while(rs.next()) {
+            while (rs.next()) {
                 names.add(rs.getString(ATTR_LOGIN));
             }
             return names.toArray(new String[0]);
-        }
-        catch(SQLException ex) {
+        } catch (SQLException ex) {
             LOG.error("DbUserManager.getAllUserNames()", ex);
             throw new FtpException("DbUserManager.getAllUserNames()", ex);
-        }
-        finally {
-            if(rs != null) {
-                try { 
-                    rs.close(); 
-                } 
-                catch(Exception ex) {
+        } finally {
+            if (rs != null) {
+                try {
+                    rs.close();
+                } catch (Exception ex) {
                     LOG.error("DbUserManager.getAllUserNames()", ex);
                 }
             }
-            if(stmt != null) {
-                try { 
-                    stmt.close(); 
-                } 
-                catch(Exception ex) {
+            if (stmt != null) {
+                try {
+                    stmt.close();
+                } catch (Exception ex) {
                     LOG.error("DbUserManager.getAllUserNames()", ex);
                 }
             }
         }
     }
-    
+
     /**
      * Get user password.
+     * 
      * <pre>
      * If the password value is not null
      *    password = new password 
@@ -628,11 +660,11 @@
      *   if user does exist
      *     password = old password
      *   else 
-     *     password = ""
+     *     password = &quot;&quot;
      * </pre>
      */
     private synchronized String getPassword(User user) throws SQLException {
-        
+
         String password = user.getPassword();
         if (password != null) {
             return password;
@@ -640,10 +672,10 @@
 
         // create sql query
         HashMap<String, Object> map = new HashMap<String, Object>();
-        map.put( ATTR_LOGIN, escapeString(user.getName()) );
+        map.put(ATTR_LOGIN, escapeString(user.getName()));
         String sql = StringUtils.replaceString(selectUserStmt, map);
         LOG.info(sql);
-        
+
         // execute query
         Statement stmt = null;
         ResultSet rs = null;
@@ -653,145 +685,140 @@
             if (rs.next()) {
                 password = rs.getString(ATTR_PASSWORD);
             }
-        }
-        finally {
-            if(rs != null) {
-                try { 
-                    rs.close(); 
-                } 
-                catch(Exception ex) {
+        } finally {
+            if (rs != null) {
+                try {
+                    rs.close();
+                } catch (Exception ex) {
                     LOG.error("DbUserManager.getPassword()", ex);
                 }
             }
-            if(stmt != null) {
-                try { 
-                    stmt.close(); 
-                } 
-                catch(Exception ex) {
+            if (stmt != null) {
+                try {
+                    stmt.close();
+                } catch (Exception ex) {
                     LOG.error("DbUserManager.getPassword()", ex);
                 }
             }
         }
-        
+
         if (password == null) {
             password = "";
         }
         return password;
     }
-    
+
     /**
      * User authentication.
      */
-    public synchronized User authenticate(Authentication authentication) throws AuthenticationFailedException {
+    public synchronized User authenticate(Authentication authentication)
+            throws AuthenticationFailedException {
         lazyInit();
-        
-        if(authentication instanceof UsernamePasswordAuthentication) {
+
+        if (authentication instanceof UsernamePasswordAuthentication) {
             UsernamePasswordAuthentication upauth = (UsernamePasswordAuthentication) authentication;
-            
-            String user = upauth.getUsername(); 
-            String password = upauth.getPassword(); 
-        
-            if(user == null) {
+
+            String user = upauth.getUsername();
+            String password = upauth.getPassword();
+
+            if (user == null) {
                 throw new AuthenticationFailedException("Authentication failed");
             }
-            
-            if(password == null) {
+
+            if (password == null) {
                 password = "";
             }
-            
+
             Statement stmt = null;
             ResultSet rs = null;
             try {
-                
+
                 // create the sql query
                 HashMap<String, Object> map = new HashMap<String, Object>();
-                map.put( ATTR_LOGIN, escapeString(user) );
-                map.put( ATTR_PASSWORD, escapeString(password) );
+                map.put(ATTR_LOGIN, escapeString(user));
+                map.put(ATTR_PASSWORD, escapeString(password));
                 String sql = StringUtils.replaceString(authenticateStmt, map);
                 LOG.info(sql);
-                
+
                 // execute query
                 stmt = createConnection().createStatement();
                 rs = stmt.executeQuery(sql);
-                if(rs.next()) {
+                if (rs.next()) {
                     try {
                         return getUserByName(user);
-                    } catch(FtpException e) {
-                        throw new AuthenticationFailedException("Authentication failed", e);
+                    } catch (FtpException e) {
+                        throw new AuthenticationFailedException(
+                                "Authentication failed", e);
                     }
                 } else {
-                    throw new AuthenticationFailedException("Authentication failed");
+                    throw new AuthenticationFailedException(
+                            "Authentication failed");
                 }
-            } catch(SQLException ex) {
+            } catch (SQLException ex) {
                 LOG.error("DbUserManager.authenticate()", ex);
-                throw new AuthenticationFailedException("Authentication failed", ex);
-            }
-            finally {
-                if(rs != null) {
-                    try { 
-                        rs.close(); 
-                    } 
-                    catch(Exception ex) {
+                throw new AuthenticationFailedException(
+                        "Authentication failed", ex);
+            } finally {
+                if (rs != null) {
+                    try {
+                        rs.close();
+                    } catch (Exception ex) {
                         LOG.error("DbUserManager.authenticate()", ex);
                     }
                 }
-                if(stmt != null) {
-                    try { 
-                        stmt.close(); 
-                    } 
-                    catch(Exception ex) {
+                if (stmt != null) {
+                    try {
+                        stmt.close();
+                    } catch (Exception ex) {
                         LOG.error("DbUserManager.authenticate()", ex);
                     }
                 }
             }
-        } else if(authentication instanceof AnonymousAuthentication) {
+        } else if (authentication instanceof AnonymousAuthentication) {
             try {
-                if(doesExist("anonymous")) {
+                if (doesExist("anonymous")) {
                     return getUserByName("anonymous");
                 } else {
-                    throw new AuthenticationFailedException("Authentication failed");
+                    throw new AuthenticationFailedException(
+                            "Authentication failed");
                 }
-            } catch(AuthenticationFailedException e) {
+            } catch (AuthenticationFailedException e) {
                 throw e;
-            } catch(FtpException e) {
-                throw new AuthenticationFailedException("Authentication failed", e);
+            } catch (FtpException e) {
+                throw new AuthenticationFailedException(
+                        "Authentication failed", e);
             }
         } else {
-            throw new IllegalArgumentException("Authentication not supported by this user manager");
+            throw new IllegalArgumentException(
+                    "Authentication not supported by this user manager");
         }
     }
-    
+
     /**
      * Close this user manager. Close the database statements and connection.
      */
     public synchronized void dispose() {
         closeConnection();
     }
-    
+
     /**
      * Escape string to be embedded in SQL statement.
      */
     private String escapeString(String input) {
-        if(input == null) {
+        if (input == null) {
             return input;
         }
-        
+
         StringBuffer valBuf = new StringBuffer(input);
-        for (int i=0; i<valBuf.length(); i++) {
+        for (int i = 0; i < valBuf.length(); i++) {
             char ch = valBuf.charAt(i);
-            if (ch == '\'' || 
-                ch == '\\' || 
-                ch == '$'  || 
-                ch == '^'  || 
-                ch == '['  || 
-                ch == ']'  || 
-                ch == '{'  || 
-                ch == '}') {
-                 
-                valBuf.insert(i, '\\'); 
+            if (ch == '\'' || ch == '\\' || ch == '$' || ch == '^' || ch == '['
+                    || ch == ']' || ch == '{' || ch == '}') {
+
+                valBuf.insert(i, '\\');
                 i++;
-             }
-         }
-         return valBuf.toString();
+            }
+        }
+        return valBuf.toString();
     }
 }
\ No newline at end of file

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/LdapUserManager.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/LdapUserManager.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/LdapUserManager.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/LdapUserManager.java Sun Aug 17 12:52:42 2008
@@ -45,170 +45,186 @@
  * Ldap based user manager class where the object class is ftpusers. This has
  * been tested with OpenLDAP. The BaseUser object will be serialized in LDAP.
  * Here the assumption is that the java object schema is available (RFC 2713).
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
  */
 public class LdapUserManager extends AbstractUserManager {
-    
+
     private final Logger LOG = LoggerFactory.getLogger(LdapUserManager.class);
-    
+
     // LDAP attributes
-    private final static String CN         = "cn";
+    private final static String CN = "cn";
+
     private final static String CLASS_NAME = "javaClassName";
-    private final static String OBJ_CLASS  = "objectClass";
-    
-    private final static String[] CN_ATTRS = {
-        CN
-    };
-    
+
+    private final static String OBJ_CLASS = "objectClass";
+
+    private final static String[] CN_ATTRS = { CN };
+
     private String adminName;
+
     private DirContext adminContext;
+
     private String ldapUserBaseDn;
+
     private Attribute objClassAttr;
 
     private String ldapUrl;
+
     private String ldapAdminDn;
+
     private String ldapAdminPassword;
+
     private String ldapAuthentication = "simple";
-    
-    
+
     /**
      * Instantiate LDAP based <code>UserManager</code> implementation.
      */
-    public void configure() throws FtpException { 
-        
+    public void configure() throws FtpException {
+
         try {
-        	if(ldapUrl == null) {
-        		throw new IllegalStateException("LDAP URL not set");
-        	}
-        	
+            if (ldapUrl == null) {
+                throw new IllegalStateException("LDAP URL not set");
+            }
+
             // create connection
             Properties adminEnv = new Properties();
-            adminEnv.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
+            adminEnv.setProperty(Context.INITIAL_CONTEXT_FACTORY,
+                    "com.sun.jndi.ldap.LdapCtxFactory");
             adminEnv.setProperty(Context.PROVIDER_URL, ldapUrl);
-            adminEnv.setProperty(Context.SECURITY_AUTHENTICATION, ldapAuthentication);             
-            adminEnv.setProperty(Context.SECURITY_PRINCIPAL, ldapAdminDn);             
-            adminEnv.setProperty(Context.SECURITY_CREDENTIALS, ldapAdminPassword);                     
+            adminEnv.setProperty(Context.SECURITY_AUTHENTICATION,
+                    ldapAuthentication);
+            adminEnv.setProperty(Context.SECURITY_PRINCIPAL, ldapAdminDn);
+            adminEnv.setProperty(Context.SECURITY_CREDENTIALS,
+                    ldapAdminPassword);
             adminContext = new InitialDirContext(adminEnv);
-            
+
             // create objectClass attribute
             objClassAttr = new BasicAttribute(OBJ_CLASS, false);
             objClassAttr.add("javaObject");
             objClassAttr.add("top");
-            
+
             LOG.info("LDAP user manager opened.");
-    
-        } catch(Exception ex) {
+
+        } catch (Exception ex) {
             LOG.error("LdapUserManager.configure()", ex);
             throw new FtpException("LdapUserManager.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 {
         return adminName.equals(login);
     }
-    
+
     /**
      * Get all user names.
      */
     public synchronized String[] getAllUserNames() throws FtpException {
-        
+
         try {
             // search ldap
             Attributes matchAttrs = new BasicAttributes(true);
             matchAttrs.put(objClassAttr);
-            matchAttrs.put( new BasicAttribute(CLASS_NAME, BaseUser.class.getName()) );
-            NamingEnumeration<SearchResult> answers = adminContext.search(ldapUserBaseDn, matchAttrs, CN_ATTRS);
+            matchAttrs.put(new BasicAttribute(CLASS_NAME, BaseUser.class
+                    .getName()));
+            NamingEnumeration<SearchResult> answers = adminContext.search(
+                    ldapUserBaseDn, matchAttrs, CN_ATTRS);
             LOG.info("Getting all users under " + ldapUserBaseDn);
-            
+
             // populate list
             ArrayList<String> allUsers = new ArrayList<String>();
             while (answers.hasMore()) {
-                SearchResult sr = (SearchResult)answers.next();
+                SearchResult sr = (SearchResult) answers.next();
                 String cn = sr.getAttributes().get(CN).get().toString();
                 allUsers.add(cn);
             }
             Collections.sort(allUsers);
             return allUsers.toArray(new String[0]);
-        }
-        catch(NamingException ex) {
+        } catch (NamingException ex) {
             LOG.error("LdapUserManager.getAllUserNames()", ex);
             throw new FtpException("LdapUserManager.getAllUserNames()", ex);
         }
-    } 
-    
+    }
+
     /**
      * Get user object.
      */
     public synchronized User getUserByName(String name) throws FtpException {
-        
+
         User user = null;
         try {
             String dn = getDN(name);
             LOG.info("Getting user object for " + dn);
-            user = (User)adminContext.lookup(dn);
-        }
-        catch(NamingException ex) {
+            user = (User) adminContext.lookup(dn);
+        } catch (NamingException ex) {
             LOG.debug("Failed to retrive user: " + name, ex);
             user = null;
         }
         return user;
     }
-    
+
     /**
      * User authentication.
      */
-    public User authenticate(Authentication authentication) throws AuthenticationFailedException {
-        if(authentication instanceof UsernamePasswordAuthentication) {
+    public User authenticate(Authentication authentication)
+            throws AuthenticationFailedException {
+        if (authentication instanceof UsernamePasswordAuthentication) {
             UsernamePasswordAuthentication upauth = (UsernamePasswordAuthentication) authentication;
-            
-            String login = upauth.getUsername(); 
-            String password = upauth.getPassword(); 
-            
-            if(login == null) {
+
+            String login = upauth.getUsername();
+            String password = upauth.getPassword();
+
+            if (login == null) {
                 throw new AuthenticationFailedException("Authentication failed");
             }
-            
-            if(password == null) {
+
+            if (password == null) {
                 password = "";
             }
-            
+
             User user;
             try {
                 user = getUserByName(login);
             } catch (FtpException e) {
-                throw new AuthenticationFailedException("Authentication failed", e); 
+                throw new AuthenticationFailedException(
+                        "Authentication failed", e);
             }
-            
-            if(user != null && password.equals(user.getPassword())) {
-                    return user;
+
+            if (user != null && password.equals(user.getPassword())) {
+                return user;
             } else {
-                    throw new AuthenticationFailedException("Authentication failed"); 
+                throw new AuthenticationFailedException("Authentication failed");
             }
-        } else if(authentication instanceof AnonymousAuthentication) {
+        } else if (authentication instanceof AnonymousAuthentication) {
             try {
-                if(doesExist("anonymous")) {
+                if (doesExist("anonymous")) {
                     return getUserByName("anonymous");
                 } else {
-                    throw new AuthenticationFailedException("Authentication failed");
+                    throw new AuthenticationFailedException(
+                            "Authentication failed");
                 }
             } catch (FtpException e) {
-                throw new AuthenticationFailedException("Authentication failed", e);
+                throw new AuthenticationFailedException(
+                        "Authentication failed", e);
             }
         } else {
-            throw new IllegalArgumentException("Authentication not supported by this user manager");
+            throw new IllegalArgumentException(
+                    "Authentication not supported by this user manager");
         }
 
     }
-    
+
     /**
      * Save user.
      */
@@ -217,11 +233,11 @@
             String name = user.getName();
             String dn = getDN(name);
             BaseUser newUser = new BaseUser(user);
-            
+
             // if password is not available,
             // do not change the existing password
             User existUser = getUserByName(name);
-            if( (existUser != null) && (newUser.getPassword() == null) ) {
+            if ((existUser != null) && (newUser.getPassword() == null)) {
                 newUser.setPassword(existUser.getPassword());
             }
 
@@ -229,24 +245,23 @@
             Attributes attrs = new BasicAttributes(true);
             attrs.put(new BasicAttribute(CN, name));
             attrs.put(new BasicAttribute(CLASS_NAME, BaseUser.class.getName()));
-            
+
             // bind object
             LOG.info("Rebinding user " + dn);
             adminContext.rebind(dn, newUser, attrs);
-        }
-        catch(NamingException ex) {
+        } catch (NamingException ex) {
             LOG.error("LdapUserManager.save()", ex);
             throw new FtpException("LdapUserManager.save()", ex);
         }
     }
-    
+
     /**
      * User existance check.
      */
     public synchronized boolean doesExist(String name) throws FtpException {
         return getUserByName(name) != null;
     }
-    
+
     /**
      * Delete user.
      */
@@ -255,13 +270,12 @@
             String dn = getDN(userName);
             LOG.info("Unbinding " + dn);
             adminContext.unbind(dn);
-        }
-        catch(NamingException ex) {
+        } catch (NamingException ex) {
             LOG.error("LdapUserManager.delete()", ex);
             throw new FtpException("LdapUserManager.delete()", ex);
         }
     }
-    
+
     /**
      * Close user manager.
      */
@@ -269,76 +283,70 @@
         if (adminContext != null) {
             try {
                 adminContext.close();
-            }
-            catch(NamingException ex) {
+            } catch (NamingException ex) {
             }
             adminContext = null;
         }
     }
-    
+
     /**
      * Get the distinguished name (DN) for this user name.
      */
     private String getDN(String userName) throws NamingException {
-        
+
         StringBuffer valBuf = new StringBuffer(userName);
-        for (int i=0; i<valBuf.length(); i++) {
+        for (int i = 0; i < valBuf.length(); i++) {
             char ch = valBuf.charAt(i);
-            if (ch == '\\' || 
-                ch == ','  || 
-                ch == '+'  ||
-                ch == '\"' || 
-                ch == '<'  || 
-                ch == '>'  || 
-                ch == ';'  ) {
-                valBuf.insert(i, '\\'); 
+            if (ch == '\\' || ch == ',' || ch == '+' || ch == '\"' || ch == '<'
+                    || ch == '>' || ch == ';') {
+                valBuf.insert(i, '\\');
                 i++;
             }
         }
         return CN + '=' + valBuf.toString() + ',' + ldapUserBaseDn;
     }
 
-	public String getLdapUrl() {
-		return ldapUrl;
-	}
-
-	public void setLdapUrl(String ldapUrl) {
-		this.ldapUrl = ldapUrl;
-	}
-
-	public String getLdapAdminDn() {
-		return ldapAdminDn;
-	}
-
-	public void setLdapAdminDn(String ldapAdminDn) {
-		this.ldapAdminDn = ldapAdminDn;
-	}
-
-	public String getLdapAdminPassword() {
-		return ldapAdminPassword;
-	}
-
-	public void setLdapAdminPassword(String ldapAdminPassword) {
-		this.ldapAdminPassword = ldapAdminPassword;
-	}
-
-	public String getLdapAuthentication() {
-		return ldapAuthentication;
-	}
-
-	public void setLdapAuthentication(String ldapAuthentication) {
-		this.ldapAuthentication = ldapAuthentication;
-	}
-
-	public void setAdminName(String adminName) {
-		this.adminName = adminName;
-	}
-
-	public String getLdapUserBaseDn() {
-		return ldapUserBaseDn;
-	}
-
-	public void setLdapUserBaseDn(String ldapUserBaseDn) {
-		this.ldapUserBaseDn = ldapUserBaseDn;
-	}
-}    
+    public String getLdapUrl() {
+        return ldapUrl;
+    }
+
+    public void setLdapUrl(String ldapUrl) {
+        this.ldapUrl = ldapUrl;
+    }
+
+    public String getLdapAdminDn() {
+        return ldapAdminDn;
+    }
+
+    public void setLdapAdminDn(String ldapAdminDn) {
+        this.ldapAdminDn = ldapAdminDn;
+    }
+
+    public String getLdapAdminPassword() {
+        return ldapAdminPassword;
+    }
+
+    public void setLdapAdminPassword(String ldapAdminPassword) {
+        this.ldapAdminPassword = ldapAdminPassword;
+    }
+
+    public String getLdapAuthentication() {
+        return ldapAuthentication;
+    }
+
+    public void setLdapAuthentication(String ldapAuthentication) {
+        this.ldapAuthentication = ldapAuthentication;
+    }
+
+    public void setAdminName(String adminName) {
+        this.adminName = adminName;
+    }
+
+    public String getLdapUserBaseDn() {
+        return ldapUserBaseDn;
+    }
+
+    public void setLdapUserBaseDn(String ldapUserBaseDn) {
+        this.ldapUserBaseDn = ldapUserBaseDn;
+    }
+}