incubator-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ran...@apache.org
Subject cvs commit: incubator-ftpserver/src/java/org/apache/ftpserver/usermanager DbUserManager.java LdapUserManager.java PropertiesUserManager.java
Date Thu, 06 Oct 2005 06:01:28 GMT
rana_b      2005/10/05 23:01:28

  Modified:    src/java/org/apache/ftpserver/usermanager DbUserManager.java
                        LdapUserManager.java PropertiesUserManager.java
  Log:
  commons-logging used
  
  Revision  Changes    Path
  1.9       +84 -37    incubator-ftpserver/src/java/org/apache/ftpserver/usermanager/DbUserManager.java
  
  Index: DbUserManager.java
  ===================================================================
  RCS file: /home/cvs/incubator-ftpserver/src/java/org/apache/ftpserver/usermanager/DbUserManager.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DbUserManager.java	24 Sep 2005 05:23:36 -0000	1.8
  +++ DbUserManager.java	6 Oct 2005 06:01:28 -0000	1.9
  @@ -25,9 +25,10 @@
   import java.util.Collection;
   import java.util.HashMap;
   
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
   import org.apache.ftpserver.ftplet.Configuration;
   import org.apache.ftpserver.ftplet.FtpException;
  -import org.apache.ftpserver.ftplet.Logger;
   import org.apache.ftpserver.ftplet.User;
   import org.apache.ftpserver.ftplet.UserManager;
   import org.apache.ftpserver.util.StringUtils;
  @@ -46,6 +47,8 @@
   public
   class DbUserManager implements UserManager {
       
  +    private Log m_log;
  +    
       private Connection m_connection;
       
       private String m_insertUserStmt;
  @@ -53,6 +56,7 @@
       private String m_deleteUserStmt;
       private String m_selectUserStmt;
       private String m_selectAllStmt;
  +    private String m_isAdminStmt;
       private String m_authenticateStmt;
       
       private String m_jdbcUrl;
  @@ -61,13 +65,12 @@
       
       private String m_adminName;
       
  -    private Logger m_logger;
       
       /**
  -     * Set logger.
  +     * Set the log factory.
        */
  -    public void setLogger(Logger logger) {
  -        m_logger = logger;
  +    public void setLogFactory(LogFactory factory) {
  +        m_log = factory.getInstance(getClass());
       }
       
       /**
  @@ -89,14 +92,15 @@
               m_selectUserStmt   = config.getString("sql-user-select");
               m_selectAllStmt    = config.getString("sql-user-select-all");
               m_authenticateStmt = config.getString("sql-user-authenticate");
  +            m_isAdminStmt      = config.getString("sql-user-admin");
               
               openConnection();
               
               m_adminName = config.getString("admin", "admin");
  -            m_logger.info("Database connection opened.");
  +            m_log.info("Database connection opened.");
           }
           catch(Exception ex) {
  -            m_logger.error("DbUserManager.configure()", ex);
  +            m_log.fatal("DbUserManager.configure()", ex);
               throw new FtpException("DbUserManager.configure()", ex);
           }
       }
  @@ -112,7 +116,50 @@
        * @return true if user with this login is administrator
        */
       public boolean isAdmin(String login) throws FtpException {
  -        return m_adminName.equals(login);
  +        
  +        // check input
  +        if(login == null) {
  +            return false;
  +        }
  +        
  +        Statement stmt = null;
  +        ResultSet rs = null;
  +        try {
  +            
  +            // create the sql query
  +            HashMap map = new HashMap();
  +            map.put( BaseUser.ATTR_LOGIN, escapeString(login) );
  +            String sql = StringUtils.replaceString(m_isAdminStmt, map);
  +            m_log.info(sql);
  +            
  +            // execute query
  +            prepareConnection();
  +            stmt = m_connection.createStatement();
  +            rs = stmt.executeQuery(sql);
  +            return rs.next();
  +        }
  +        catch(SQLException ex) {
  +            m_log.error("DbUserManager.isAdmin()", ex);
  +            throw new FtpException("DbUserManager.isAdmin()", ex);
  +        }
  +        finally {
  +            if(rs != null) {
  +                try { 
  +                    rs.close(); 
  +                } 
  +                catch(Exception ex) {
  +                    m_log.error("DbUserManager.isAdmin()", ex);
  +                }
  +            }
  +            if(stmt != null) {
  +                try { 
  +                    stmt.close(); 
  +                } 
  +                catch(Exception ex) {
  +                    m_log.error("DbUserManager.isAdmin()", ex);
  +                }
  +            }
  +        }
       }
       
       /**
  @@ -132,12 +179,12 @@
                   m_connection.close(); 
               } 
               catch(SQLException ex) {
  -                m_logger.error("DbUserManager.closeConnection()", ex);
  +                m_log.error("DbUserManager.closeConnection()", ex);
               }
               m_connection = null;
           }
           
  -        m_logger.info("Database connection closed.");
  +        m_log.info("Database connection closed.");
       }
       
       /**
  @@ -151,7 +198,7 @@
               }
           }
           catch(SQLException ex) {
  -            m_logger.error("DbUserManager.prepareConnection()", ex);
  +            m_log.error("DbUserManager.prepareConnection()", ex);
               isClosed = true;
           }
           
  @@ -170,7 +217,7 @@
           HashMap map = new HashMap();
           map.put( BaseUser.ATTR_LOGIN, escapeString(name) );
           String sql = StringUtils.replaceString(m_deleteUserStmt, map);
  -        m_logger.info(sql);
  +        m_log.info(sql);
           
           // execute query
           Statement stmt = null;
  @@ -180,7 +227,7 @@
               stmt.executeUpdate(sql);
           }
           catch(SQLException ex) {
  -            m_logger.error("DbUserManager.delete()", ex);
  +            m_log.error("DbUserManager.delete()", ex);
               throw new FtpException("DbUserManager.delete()", ex);
           }
           finally {
  @@ -189,7 +236,7 @@
                       stmt.close(); 
                   } 
                   catch(Exception ex) {
  -                    m_logger.error("DbUserManager.delete()", ex);
  +                    m_log.error("DbUserManager.delete()", ex);
                   }
               }
           }
  @@ -226,7 +273,7 @@
               else {
                   sql = StringUtils.replaceString(m_updateUserStmt, map);
               }
  -            m_logger.info(sql);
  +            m_log.info(sql);
               
               // execute query
               prepareConnection();
  @@ -234,7 +281,7 @@
               stmt.executeUpdate(sql);
           }
           catch(SQLException ex) {
  -            m_logger.error("DbUserManager.save()", ex);
  +            m_log.error("DbUserManager.save()", ex);
               throw new FtpException("DbUserManager.save()", ex);
           }
           finally {
  @@ -243,7 +290,7 @@
                       stmt.close(); 
                   } 
                   catch(Exception ex) {
  -                    m_logger.error("DbUsermanager.error()", ex);
  +                    m_log.error("DbUsermanager.error()", ex);
                   }
               }
           }
  @@ -262,7 +309,7 @@
               HashMap map = new HashMap();
               map.put( BaseUser.ATTR_LOGIN, escapeString(name) );
               String sql = StringUtils.replaceString(m_selectUserStmt, map);
  -            m_logger.info(sql);
  +            m_log.info(sql);
               
               // execute query
               prepareConnection();
  @@ -285,7 +332,7 @@
               return thisUser;
           }
           catch(SQLException ex) {
  -            m_logger.error("DbUserManager.getUserByName()", ex);
  +            m_log.error("DbUserManager.getUserByName()", ex);
               throw new FtpException("DbUserManager.getUserByName()", ex);
           }
           finally {
  @@ -294,7 +341,7 @@
                       rs.close(); 
                   } 
                   catch(Exception ex) {
  -                    m_logger.error("DbUserManager.getUserByName()", ex);
  +                    m_log.error("DbUserManager.getUserByName()", ex);
                   }
               }
               if(stmt != null) {
  @@ -302,7 +349,7 @@
                       stmt.close(); 
                   } 
                   catch(Exception ex) {
  -                    m_logger.error("DbUserManager.getUserByName()", ex);
  +                    m_log.error("DbUserManager.getUserByName()", ex);
                   }
               }
           }
  @@ -320,7 +367,7 @@
               HashMap map = new HashMap();
               map.put( BaseUser.ATTR_LOGIN, escapeString(name) );
               String sql = StringUtils.replaceString(m_selectUserStmt, map);
  -            m_logger.info(sql);
  +            m_log.info(sql);
               
               // execute query
               prepareConnection();
  @@ -329,7 +376,7 @@
               return rs.next();
           }
           catch(SQLException ex) {
  -            m_logger.error("DbUserManager.doesExist()", ex);
  +            m_log.error("DbUserManager.doesExist()", ex);
               throw new FtpException("DbUserManager.doesExist()", ex);
           }
           finally {
  @@ -338,7 +385,7 @@
                       rs.close(); 
                   } 
                   catch(Exception ex) {
  -                    m_logger.error("DbUserManager.doesExist()", ex);
  +                    m_log.error("DbUserManager.doesExist()", ex);
                   }
               }
               if(stmt != null) {
  @@ -346,7 +393,7 @@
                       stmt.close(); 
                   } 
                   catch(Exception ex) {
  -                    m_logger.error("DbUserManager.doesExist()", ex);
  +                    m_log.error("DbUserManager.doesExist()", ex);
                   }
               }
           }
  @@ -363,7 +410,7 @@
               
               // create sql query
               String sql = m_selectAllStmt;
  -            m_logger.info(sql);
  +            m_log.info(sql);
               
               // execute query
               prepareConnection();
  @@ -378,7 +425,7 @@
               return names;
           }
           catch(SQLException ex) {
  -            m_logger.error("DbUserManager.getAllUserNames()", ex);
  +            m_log.error("DbUserManager.getAllUserNames()", ex);
               throw new FtpException("DbUserManager.getAllUserNames()", ex);
           }
           finally {
  @@ -387,7 +434,7 @@
                       rs.close(); 
                   } 
                   catch(Exception ex) {
  -                    m_logger.error("DbUserManager.getAllUserNames()", ex);
  +                    m_log.error("DbUserManager.getAllUserNames()", ex);
                   }
               }
               if(stmt != null) {
  @@ -395,7 +442,7 @@
                       stmt.close(); 
                   } 
                   catch(Exception ex) {
  -                    m_logger.error("DbUserManager.getAllUserNames()", ex);
  +                    m_log.error("DbUserManager.getAllUserNames()", ex);
                   }
               }
           }
  @@ -424,7 +471,7 @@
           HashMap map = new HashMap();
           map.put( BaseUser.ATTR_LOGIN, escapeString(user.getName()) );
           String sql = StringUtils.replaceString(m_selectUserStmt, map);
  -        m_logger.info(sql);
  +        m_log.info(sql);
           
           // execute query
           Statement stmt = null;
  @@ -443,7 +490,7 @@
                       rs.close(); 
                   } 
                   catch(Exception ex) {
  -                    m_logger.error("DbUserManager.getPassword()", ex);
  +                    m_log.error("DbUserManager.getPassword()", ex);
                   }
               }
               if(stmt != null) {
  @@ -451,7 +498,7 @@
                       stmt.close(); 
                   } 
                   catch(Exception ex) {
  -                    m_logger.error("DbUserManager.getPassword()", ex);
  +                    m_log.error("DbUserManager.getPassword()", ex);
                   }
               }
           }
  @@ -482,7 +529,7 @@
               map.put( BaseUser.ATTR_LOGIN, escapeString(user) );
               map.put( BaseUser.ATTR_PASSWORD, escapeString(password) );
               String sql = StringUtils.replaceString(m_authenticateStmt, map);
  -            m_logger.info(sql);
  +            m_log.info(sql);
               
               // execute query
               prepareConnection();
  @@ -491,7 +538,7 @@
               return rs.next();
           }
           catch(SQLException ex) {
  -            m_logger.error("DbUserManager.authenticate()", ex);
  +            m_log.error("DbUserManager.authenticate()", ex);
               throw new FtpException("DbUserManager.authenticate()", ex);
           }
           finally {
  @@ -500,7 +547,7 @@
                       rs.close(); 
                   } 
                   catch(Exception ex) {
  -                    m_logger.error("DbUserManager.authenticate()", ex);
  +                    m_log.error("DbUserManager.authenticate()", ex);
                   }
               }
               if(stmt != null) {
  @@ -508,7 +555,7 @@
                       stmt.close(); 
                   } 
                   catch(Exception ex) {
  -                    m_logger.error("DbUserManager.authenticate()", ex);
  +                    m_log.error("DbUserManager.authenticate()", ex);
                   }
               }
           }
  
  
  
  1.9       +17 -15    incubator-ftpserver/src/java/org/apache/ftpserver/usermanager/LdapUserManager.java
  
  Index: LdapUserManager.java
  ===================================================================
  RCS file: /home/cvs/incubator-ftpserver/src/java/org/apache/ftpserver/usermanager/LdapUserManager.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- LdapUserManager.java	24 Sep 2005 05:23:36 -0000	1.8
  +++ LdapUserManager.java	6 Oct 2005 06:01:28 -0000	1.9
  @@ -32,9 +32,10 @@
   import javax.naming.directory.InitialDirContext;
   import javax.naming.directory.SearchResult;
   
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
   import org.apache.ftpserver.ftplet.Configuration;
   import org.apache.ftpserver.ftplet.FtpException;
  -import org.apache.ftpserver.ftplet.Logger;
   import org.apache.ftpserver.ftplet.User;
   import org.apache.ftpserver.ftplet.UserManager;
   
  @@ -57,18 +58,19 @@
           CN
       };
       
  +    private Log m_log;
  +    
       private String m_adminName;
       private DirContext m_adminContext;
       private String m_userBaseDn;
       private Attribute m_objClassAttr;
  -    private Logger m_logger;
       
       
       /**
  -     * Set logger.
  +     * Set the log factory.
        */
  -    public void setLogger(Logger logger) {
  -        m_logger = logger;
  +    public void setLogFactory(LogFactory factory) {
  +        m_log = factory.getInstance(getClass());
       }
       
       /**
  @@ -103,13 +105,13 @@
               m_objClassAttr.add("javaObject");
               m_objClassAttr.add("top");
               
  -            m_logger.info("LDAP user manager opened.");
  +            m_log.info("LDAP user manager opened.");
           }
           catch(FtpException ex) {
               throw ex;
           }
           catch(Exception ex) {
  -            m_logger.error("LdapUserManager.configure()", ex);
  +            m_log.fatal("LdapUserManager.configure()", ex);
               throw new FtpException("LdapUserManager.configure()", ex);
           }
       }
  @@ -139,7 +141,7 @@
               matchAttrs.put(m_objClassAttr);
               matchAttrs.put( new BasicAttribute(CLASS_NAME, BaseUser.class.getName()) );
               NamingEnumeration answers = m_adminContext.search(m_userBaseDn, matchAttrs,
CN_ATTRS);
  -            m_logger.info("Getting all users under " + m_userBaseDn);
  +            m_log.info("Getting all users under " + m_userBaseDn);
               
               // populate list
               ArrayList allUsers = new ArrayList();
  @@ -152,7 +154,7 @@
               return allUsers;
           }
           catch(NamingException ex) {
  -            m_logger.error("LdapUserManager.getAllUserNames()", ex);
  +            m_log.error("LdapUserManager.getAllUserNames()", ex);
               throw new FtpException("LdapUserManager.getAllUserNames()", ex);
           }
       } 
  @@ -165,7 +167,7 @@
           User user = null;
           try {
               String dn = getDN(name);
  -            m_logger.info("Getting user object for " + dn);
  +            m_log.info("Getting user object for " + dn);
               user = (User)m_adminContext.lookup(dn);
           }
           catch(NamingException ex) {
  @@ -209,11 +211,11 @@
               attrs.put(new BasicAttribute(CLASS_NAME, BaseUser.class.getName()));
               
               // bind object
  -            m_logger.info("Rebinding user " + dn);
  +            m_log.info("Rebinding user " + dn);
               m_adminContext.rebind(dn, newUser, attrs);
           }
           catch(NamingException ex) {
  -            m_logger.error("LdapUserManager.save()", ex);
  +            m_log.error("LdapUserManager.save()", ex);
               throw new FtpException("LdapUserManager.save()", ex);
           }
       }
  @@ -231,11 +233,11 @@
       public synchronized void delete(String userName) throws FtpException {
           try {
               String dn = getDN(userName);
  -            m_logger.info("Unbinding " + dn);
  +            m_log.info("Unbinding " + dn);
               m_adminContext.unbind(dn);
           }
           catch(NamingException ex) {
  -            m_logger.error("LdapUserManager.delete()", ex);
  +            m_log.error("LdapUserManager.delete()", ex);
               throw new FtpException("LdapUserManager.delete()", ex);
           }
       }
  
  
  
  1.10      +20 -18    incubator-ftpserver/src/java/org/apache/ftpserver/usermanager/PropertiesUserManager.java
  
  Index: PropertiesUserManager.java
  ===================================================================
  RCS file: /home/cvs/incubator-ftpserver/src/java/org/apache/ftpserver/usermanager/PropertiesUserManager.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- PropertiesUserManager.java	24 Sep 2005 05:23:36 -0000	1.9
  +++ PropertiesUserManager.java	6 Oct 2005 06:01:28 -0000	1.10
  @@ -16,15 +16,6 @@
    */
   package org.apache.ftpserver.usermanager;
   
  -import org.apache.ftpserver.ftplet.Configuration;
  -import org.apache.ftpserver.ftplet.FtpException;
  -import org.apache.ftpserver.ftplet.Logger;
  -import org.apache.ftpserver.ftplet.User;
  -import org.apache.ftpserver.ftplet.UserManager;
  -import org.apache.ftpserver.util.BaseProperties;
  -import org.apache.ftpserver.util.EncryptUtils;
  -import org.apache.ftpserver.util.IoUtils;
  -
   import java.io.File;
   import java.io.FileOutputStream;
   import java.io.IOException;
  @@ -34,6 +25,16 @@
   import java.util.Enumeration;
   import java.util.Iterator;
   
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
  +import org.apache.ftpserver.ftplet.Configuration;
  +import org.apache.ftpserver.ftplet.FtpException;
  +import org.apache.ftpserver.ftplet.User;
  +import org.apache.ftpserver.ftplet.UserManager;
  +import org.apache.ftpserver.util.BaseProperties;
  +import org.apache.ftpserver.util.EncryptUtils;
  +import org.apache.ftpserver.util.IoUtils;
  +
   
   /**
    * Properties file based <code>UserManager</code> implementation. 
  @@ -46,19 +47,20 @@
   
       private final static String PREFIX    = "FtpServer.user.";
   
  +    private Log m_log;
  +    
       private BaseProperties m_userDataProp;
       private File           m_userDataFile;
       private boolean        m_isPasswordEncrypt;
       private String         m_adminName;
       
  -    private Logger m_logger;
       
       /**
  -     * Set logger.
  +     * Set the log factory.
        */
  -    public void setLogger(Logger logger) {
  -        m_logger = logger;
  -    }
  +    public void setLogFactory(LogFactory factory) {
  +        m_log = factory.getInstance(getClass());
  +    } 
       
       /**
        * Configure user manager.
  @@ -78,7 +80,7 @@
               m_adminName = config.getString("admin", "admin");
           }
           catch(IOException ex) {
  -            m_logger.error("PropertiesUserManager.configure()", ex);
  +            m_log.fatal("PropertiesUserManager.configure()", ex);
               throw new FtpException("PropertiesUserManager.configure()", ex);
           }
       }
  @@ -124,7 +126,7 @@
              m_userDataProp.store(fos, "Generated file - don't edit (please)");
          }
          catch(IOException ex) {
  -           m_logger.error("PropertiesUserManager.save()", ex);
  +           m_log.error("PropertiesUserManager.save()", ex);
              throw new FtpException("PropertiesUserManager.save()", ex);
          }
          finally {
  @@ -160,7 +162,7 @@
               m_userDataProp.store(fos, "Generated file - don't edit (please)");
           }
           catch(IOException ex) {
  -            m_logger.error("PropertiesUserManager.delete()", ex);
  +            m_log.error("PropertiesUserManager.delete()", ex);
               throw new FtpException("PropertiesUserManager.delete()", ex);
           }
           finally {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@incubator.apache.org
For additional commands, e-mail: cvs-help@incubator.apache.org


Mime
View raw message