incubator-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hamm...@apache.org
Subject cvs commit: incubator-ftpserver/src/java/org/apache/ftpserver/interfaces FtpUserManagerMonitor.java
Date Wed, 28 Jul 2004 15:54:19 GMT
hammant     2004/07/28 08:54:19

  Modified:    src/java/org/apache/ftpserver/usermanager
                        AbstractUserManager.java DbUserManager.java
                        LdapUserManager.java ObjStoreUserManager.java
                        PropertiesUserManager.java
  Added:       src/java/org/apache/ftpserver/usermanager
                        AvalonDbUserManager.java
                        AvalonPropertiesUserManager.java
                        AvlalonLdapUserManager.java
               src/java/org/apache/ftpserver
                        AvalonFtpUserManagerMonitor.java
               src/java/org/apache/ftpserver/interfaces
                        FtpUserManagerMonitor.java
  Log:
  more avalon separation
  
  Revision  Changes    Path
  1.4       +5 -61     incubator-ftpserver/src/java/org/apache/ftpserver/usermanager/AbstractUserManager.java
  
  Index: AbstractUserManager.java
  ===================================================================
  RCS file: /home/cvs/incubator-ftpserver/src/java/org/apache/ftpserver/usermanager/AbstractUserManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractUserManager.java	27 Jul 2004 20:16:43 -0000	1.3
  +++ AbstractUserManager.java	28 Jul 2004 15:54:19 -0000	1.4
  @@ -57,21 +57,6 @@
   package org.apache.ftpserver.usermanager;
   
   
  -import org.apache.avalon.framework.logger.AbstractLogEnabled;
  -import org.apache.avalon.framework.activity.Initializable;
  -import org.apache.avalon.framework.activity.Disposable;
  -
  -import org.apache.avalon.framework.configuration.Configurable;
  -import org.apache.avalon.framework.configuration.Configuration;
  -import org.apache.avalon.framework.configuration.ConfigurationException;
  -
  -import org.apache.avalon.framework.service.Serviceable;
  -import org.apache.avalon.framework.service.ServiceManager;
  -import org.apache.avalon.framework.service.ServiceException;
  -
  -import org.apache.avalon.framework.context.Contextualizable;
  -import org.apache.avalon.framework.context.Context;
  -import org.apache.avalon.framework.context.ContextException;
   import org.apache.ftpserver.UserManagerException;
   
   /**
  @@ -80,50 +65,11 @@
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
    */
   public
  -abstract class AbstractUserManager extends AbstractLogEnabled
  -                                   implements UserManagerInterface,
  -                                              Contextualizable,
  -                                              Configurable,
  -                                              Initializable,
  -                                              Disposable {
  +abstract class AbstractUserManager
  +                                   implements UserManagerInterface {
   
  -    protected Configuration mConfig;
  -    protected Context mContext;
       protected String mstAdminName;
   
  -    /**
  -     * Set context object - first step.
  -     */
  -    public void contextualize(Context context) throws ContextException {
  -        mContext = context;
  -    }
  -
  -    /**
  -     * Get application context.
  -     */
  -    public Context getContext() {
  -        return mContext;
  -    }
  -
  -    /**
  -     * Configure user manager - third step.
  -     */
  -    public void configure(Configuration config) throws ConfigurationException {
  -        mConfig = config;
  -
  -        Configuration adminConf = mConfig.getChild("ftp-admin-name", false);
  -        mstAdminName = "admin";
  -        if(adminConf != null) {
  -            mstAdminName = adminConf.getValue(mstAdminName);
  -        }
  -    }
  -
  -    /**
  -     * Get config object.
  -     */
  -    public Configuration getConfig() {
  -        return mConfig;
  -    }
   
   
       /**
  @@ -147,10 +93,8 @@
       }
   
       /**
  -     * Close user manager - dummy implementation.
  +     * Close user manager
        */
  -    public void dispose() {
  -        getLogger().info("Closing user manager...");
  -    }
  +    public abstract void dispose();
   
   }
  
  
  
  1.4       +19 -51    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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DbUserManager.java	27 Jul 2004 20:16:43 -0000	1.3
  +++ DbUserManager.java	28 Jul 2004 15:54:19 -0000	1.4
  @@ -56,6 +56,10 @@
    */
   package org.apache.ftpserver.usermanager;
   
  +import org.apache.ftpserver.UserManagerException;
  +import org.apache.ftpserver.interfaces.FtpUserManagerMonitor;
  +import org.apache.ftpserver.util.StringUtils;
  +
   import java.io.File;
   import java.sql.Connection;
   import java.sql.DriverManager;
  @@ -66,17 +70,10 @@
   import java.util.HashMap;
   import java.util.List;
   
  -import org.apache.avalon.framework.configuration.Configuration;
  -import org.apache.avalon.framework.configuration.ConfigurationException;
  -import org.apache.ftpserver.util.StringUtils;
  -import org.apache.ftpserver.UserManagerException;
  -
   /**
    * This is another database based user manager class. I have
    * tested it using MySQL and Oracle database. The sql file is <code>ftp-db.sql</code>
    *
  - * @phoenix:block
  - * @phoenix:service name="org.apache.ftpserver.usermanager.UserManagerInterface"
    *
    * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
    */
  @@ -85,51 +82,24 @@
   
       private Connection mDbConnection       = null;
   
  -    private String mInsUserStmt = null;
  -    private String mDelUserStmt = null;
  -    private String mSelUserStmt = null;
  -    private String mGetAllStmt  = null;
  -    private String mUpdUserStmt = null;
  +    protected String mInsUserStmt = null;
  +    protected String mDelUserStmt = null;
  +    protected String mSelUserStmt = null;
  +    protected String mGetAllStmt  = null;
  +    protected String mUpdUserStmt = null;
       
  -    private String mUrl      = null;
  -    private String mUser     = null;
  -    private String mPassword = null;
  +    protected String mUrl      = null;
  +    protected String mUser     = null;
  +    protected String mPassword = null;
   
  -
  -    /**
  -     * Set configuration - open database connection
  -     */
  -    public void configure(Configuration conf) throws ConfigurationException {
  -        super.configure(conf);
  -
  -        String className = conf.getChild("driver").getValue();
  -        mUrl          = conf.getChild("url").getValue();
  -        mUser         = conf.getChild("user").getValue();
  -        mPassword     = conf.getChild("password").getValue();
  -        mInsUserStmt  = conf.getChild("sql-insert").getValue();
  -        mDelUserStmt  = conf.getChild("sql-delete").getValue();
  -        mSelUserStmt  = conf.getChild("sql-select").getValue();
  -        mGetAllStmt   = conf.getChild("sql-all").getValue();
  -        mUpdUserStmt  = conf.getChild("sql-update").getValue();
  -
  -        try {
  -            Class.forName(className);
  -
  -            openDbConnection();
  -            getLogger().info("Database user manager opened.");
  -        }
  -        catch(Exception ex) {
  -            throw new ConfigurationException("DbUserManager.configure()", ex);
  -        }
  -    }
  +    private FtpUserManagerMonitor ftpUserManagerMonitor;
   
       /**
        * Open connection to database.
        */
  -    private void openDbConnection() throws SQLException {
  +    protected void openDbConnection() throws SQLException {
           mDbConnection = DriverManager.getConnection(mUrl, mUser, mPassword);
           mDbConnection.setAutoCommit(true);
  -        getLogger().info("Connection opened.");
       }
   
       /**
  @@ -140,8 +110,6 @@
               try {mDbConnection.close(); } catch(SQLException ex) {}
               mDbConnection = null;
           }
  -
  -        getLogger().info("Connection closed.");
       }
   
       /**
  @@ -253,7 +221,7 @@
               return thisUser;
           }
           catch(Exception ex) {
  -            getLogger().error("DbUserManager.getUserByName()", ex);
  +            ftpUserManagerMonitor.generalError("DbUserManager.getUserByName()", ex);
           }
           finally {
               if(rs != null) {
  @@ -290,7 +258,7 @@
           }
           catch(Exception ex) {
               bValid = false;
  -            getLogger().error("DbUserManager.doesExist()", ex);
  +            ftpUserManagerMonitor.generalError("DbUserManager.doesExist()", ex);
           }
           finally {
               if(rs != null) {
  @@ -325,7 +293,7 @@
               }
           }
           catch(Exception ex) {
  -            getLogger().error("DbUserManager.getAllUserNames()", ex);
  +            ftpUserManagerMonitor.generalError("DbUserManager.getAllUserNames()", ex);
           }
           finally {
               if(rs != null) {
  @@ -399,7 +367,7 @@
               stmt.close();
           }
           catch(Exception ex) {
  -            getLogger().error("DbUserManager.authenticate()", ex);
  +            ftpUserManagerMonitor.generalError("DbUserManager.authenticate()", ex);
               return false;
           }
           
  
  
  
  1.4       +24 -76    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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LdapUserManager.java	27 Jul 2004 20:16:43 -0000	1.3
  +++ LdapUserManager.java	28 Jul 2004 15:54:19 -0000	1.4
  @@ -57,27 +57,26 @@
   package org.apache.ftpserver.usermanager;
   
   
  -import java.io.File;
  -import java.util.List;
  -import java.util.ArrayList;
  -import java.util.Properties;
  -import java.util.Collections;
  -import javax.naming.NamingException;
  +import org.apache.ftpserver.UserManagerException;
  +import org.apache.ftpserver.interfaces.FtpUserManagerMonitor;
  +import org.apache.ftpserver.util.StringUtils;
  +
   import javax.naming.Context;
   import javax.naming.NamingEnumeration;
  +import javax.naming.NamingException;
   import javax.naming.directory.Attribute;
  +import javax.naming.directory.Attributes;
   import javax.naming.directory.BasicAttribute;
  +import javax.naming.directory.BasicAttributes;
   import javax.naming.directory.DirContext;
   import javax.naming.directory.InitialDirContext;
  -import javax.naming.directory.Attributes;
  -import javax.naming.directory.BasicAttributes;
  -import javax.naming.directory.SearchResult;
   import javax.naming.directory.ModificationItem;
  -
  -import org.apache.avalon.framework.configuration.Configuration;
  -import org.apache.avalon.framework.configuration.ConfigurationException;
  -import org.apache.ftpserver.util.StringUtils;
  -import org.apache.ftpserver.UserManagerException;
  +import javax.naming.directory.SearchResult;
  +import java.io.File;
  +import java.util.ArrayList;
  +import java.util.Collections;
  +import java.util.List;
  +import java.util.Properties;
   
   /**
    * Ldap based user manager class. Tested using Netscape Directory Server 4.1.
  @@ -116,8 +115,6 @@
    *      ftpUsers
    * </pre>
    *
  - * @phoenix:block
  - * @phoenix:service name="org.apache.ftpserver.usermanager.UserManagerInterface"
    *
    * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
    */
  @@ -129,7 +126,7 @@
       private final static String LOGIN      = "memberuid";
       private final static String CN         = "cn";
       private final static String SN         = "sn";
  -    private final static String OBJ_CLASS  = "objectclass";
  +    protected final static String OBJ_CLASS  = "objectclass";
       
       private final static String[] ALL_ATTRS = {
           User.ATTR_LOGIN,
  @@ -148,62 +145,13 @@
   
       // Currently we are using only one connection.
       // So all the methods are synchronized.
  -    private DirContext mAdminContext;
  -    private Properties mAdminEnv;
  -    private String mstRoot;
  -    private String mstDnPrefix;
  -    private String mstDnSuffix;
  -    private Attribute mObjClassAttr;
  -
  -
  -    /**
  -     * Default constructor
  -     */
  -    public LdapUserManager() {
  -    }
  -
  -
  -    /**
  -     * Instantiate <code>UserManager</code> implementation.
  -     * Open LDAP connection.
  -     */
  -    public void configure(Configuration conf) throws ConfigurationException {
  -        super.configure(conf);
  -
  -        // get ldap parameters
  -        String url      = conf.getChild("url").getValue();
  -        String admin    = conf.getChild("admin").getValue();
  -        String password = conf.getChild("password").getValue();
  -        String auth     = conf.getChild("authentication").getValue();
  -
  -        mstRoot     = conf.getChild("root").getValue();
  -        mstDnPrefix = conf.getChild("prefix").getValue();
  -        mstDnSuffix = conf.getChild("suffix").getValue();
  -
  -        try {
  -            mAdminEnv = new Properties();
  -            mAdminEnv.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
  -            mAdminEnv.setProperty(Context.PROVIDER_URL, url);
  -            mAdminEnv.setProperty(Context.SECURITY_AUTHENTICATION, auth);
  -            mAdminEnv.setProperty(Context.SECURITY_PRINCIPAL, admin);
  -            mAdminEnv.setProperty(Context.SECURITY_CREDENTIALS, password);
  -            mAdminContext = new InitialDirContext(mAdminEnv);
  -
  -
  -            // create objectClass attribute
  -            mObjClassAttr = new BasicAttribute(OBJ_CLASS, false);
  -            mObjClassAttr.add("ftpUsers");
  -            mObjClassAttr.add("inetOrgPerson");
  -            mObjClassAttr.add("organizationalPerson");
  -            mObjClassAttr.add("person");
  -            mObjClassAttr.add("top");
  -
  -            getLogger().info("LDAP user manager opened.");
  -        }
  -        catch(NamingException ex) {
  -            throw new ConfigurationException("LdapUserManager.configure()", ex);
  -        }
  -    }
  +    protected DirContext mAdminContext;
  +    protected Properties mAdminEnv;
  +    protected String mstRoot;
  +    protected String mstDnPrefix;
  +    protected String mstDnSuffix;
  +    protected Attribute mObjClassAttr;
  +    protected FtpUserManagerMonitor ftpUserManagerMonitor;
   
   
       /**
  @@ -223,7 +171,7 @@
               }
           }
           catch(Exception ex) {
  -            getLogger().error("LdapUserManager.getAllUserNames()", ex);
  +            ftpUserManagerMonitor.generalError("LdapUserManager.getAllUserNames()", ex);
           }
   
           Collections.sort(allUsers);
  @@ -251,7 +199,7 @@
               user.setMaxDownloadRate( Integer.parseInt(attrs.get(User.ATTR_MAX_DOWNLOAD_RATE).get().toString())
);
           }
           catch(Exception ex) {
  -            getLogger().error("LdapUserManager.getUserByName()", ex);
  +            ftpUserManagerMonitor.generalError ("LdapUserManager.getUserByName()", ex);
               user = null;
           }
   
  
  
  
  1.2       +28 -18    incubator-ftpserver/src/java/org/apache/ftpserver/usermanager/ObjStoreUserManager.java
  
  Index: ObjStoreUserManager.java
  ===================================================================
  RCS file: /home/cvs/incubator-ftpserver/src/java/org/apache/ftpserver/usermanager/ObjStoreUserManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ObjStoreUserManager.java	31 Mar 2003 06:50:26 -0000	1.1
  +++ ObjStoreUserManager.java	28 Jul 2004 15:54:19 -0000	1.2
  @@ -56,41 +56,56 @@
    */
   package org.apache.ftpserver.usermanager;
   
  -import java.util.List;
  -import java.util.Iterator;
  -import java.util.Collections;
  -import java.util.ArrayList;
  -
   import org.apache.avalon.cornerstone.services.store.ObjectRepository;
   import org.apache.avalon.cornerstone.services.store.Store;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  -import org.apache.avalon.framework.service.ServiceException;
  +import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.service.ServiceManager;
  +import org.apache.avalon.framework.service.ServiceException;
   import org.apache.avalon.framework.service.Serviceable;
   
  +import java.util.ArrayList;
  +import java.util.Collections;
  +import java.util.Iterator;
  +import java.util.List;
  +
   
   /**
  - * File object repository based user manager.
    *
    * @phoenix:block
    * @phoenix:service name="org.apache.ftpserver.usermanager.UserManagerInterface"
    *
  + * File object repository based user manager.
  + *
    * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
    */
   public
  -class ObjStoreUserManager extends AbstractUserManager implements Serviceable {
  +class ObjStoreUserManager extends AbstractUserManager implements Serviceable, Configurable
{
   
       protected Configuration mStoreConfig;
       protected Store mStore;
       protected ObjectRepository mObjectRepository;
   
       /**
  +     * Initialize object repository.
  +     */
  +    public void initialize() throws Exception {
  +        super.initialize();
  +        mObjectRepository = (ObjectRepository) mStore.select(mStoreConfig);
  +    }
  +
  +    /**
        * Configure user manager
        */
       public void configure(Configuration conf) throws ConfigurationException {
  -        super.configure(conf);
           mStoreConfig = conf.getChild("repository");
  +        Configuration adminConf = conf.getChild("ftp-admin-name", false);
  +        mstAdminName = "admin";
  +        if(adminConf != null) {
  +            mstAdminName = adminConf.getValue(mstAdminName);
  +        }
  +
       }
   
       /**
  @@ -103,14 +118,6 @@
       }
   
       /**
  -     * Initialize object repository.
  -     */
  -    public void initialize() throws Exception {
  -        super.initialize();
  -        mObjectRepository = (ObjectRepository) mStore.select(mStoreConfig);
  -    }
  -
  -    /**
        * Save user object.
        */
       public synchronized void save(User usr) {
  @@ -199,4 +206,7 @@
           return password.equals(user.getPassword());
       }
   
  +    public void dispose() {
  +
  +    }
   }
  
  
  
  1.5       +17 -54    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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PropertiesUserManager.java	27 Jul 2004 20:16:43 -0000	1.4
  +++ PropertiesUserManager.java	28 Jul 2004 15:54:19 -0000	1.5
  @@ -56,78 +56,42 @@
    */
   package org.apache.ftpserver.usermanager;
   
  +import org.apache.ftpserver.UserManagerException;
  +import org.apache.ftpserver.interfaces.FtpUserManagerMonitor;
  +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.IOException;
   import java.io.FileInputStream;
   import java.io.FileOutputStream;
  -import java.util.List;
  +import java.io.IOException;
  +import java.util.ArrayList;
   import java.util.Collections;
   import java.util.Enumeration;
  -import java.util.ArrayList;
   import java.util.Iterator;
  -
  -import org.apache.avalon.framework.context.Context;
  -import org.apache.avalon.framework.configuration.Configuration;
  -import org.apache.avalon.framework.configuration.ConfigurationException;
  -import org.apache.avalon.framework.context.ContextException;
  -
  -import org.apache.ftpserver.util.IoUtils;
  -import org.apache.ftpserver.util.BaseProperties;
  -import org.apache.ftpserver.util.EncryptUtils;
  -import org.apache.ftpserver.UserManagerException;
  +import java.util.List;
   
   /**
    * Properties file based <code>UserManager</code>
    * implementation. We use <code>user.properties</code> file
    * to store user data.
    *
  - * @phoenix:block
  - * @phoenix:service name="org.apache.ftpserver.usermanager.UserManagerInterface"
    *
    * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
    */
   public class PropertiesUserManager extends AbstractUserManager {
   
       private static final String PREFIX    = "FtpServer.user.";
  -    private static final String USER_PROP = "user.properties";
  -
  -    private BaseProperties mUserData;
  -    private File       mUserDataFile;
  -    private boolean    mbEncrypt;
  -
  -    private long mlLastModified;
  +    protected static final String USER_PROP = "user.properties";
   
  -    /**
  -     * Set application context
  -     */
  -    public void contextualize(Context context) throws ContextException {
  -        super.contextualize(context);
  -        try {
  -            File appDir = (File)context.get("app.home");
  -            if(!appDir.exists()) {
  -                appDir.mkdirs();
  -            }
  -            mUserDataFile = new File(appDir, USER_PROP);
  +    protected BaseProperties mUserData;
  +    protected File       mUserDataFile;
  +    protected boolean    mbEncrypt;
   
  -            mUserDataFile.createNewFile();
  -            mUserData = new BaseProperties(mUserDataFile);
  -            mlLastModified = mUserDataFile.lastModified();
  -            getLogger().info("Loaded user data file - " + mUserDataFile);
  -        }
  -        catch(IOException ex) {
  -            getLogger().error(ex.getMessage(), ex);
  -            throw new ContextException(ex.getMessage());
  -        }
  -    }
  -
  -    /**
  -     * Set configuration
  -     */
  -    public void configure(Configuration conf) throws ConfigurationException {
  -        super.configure(conf);
  -        mbEncrypt = conf.getChild("encrypt").getValueAsBoolean(false);
  -    }
  +    protected long mlLastModified;
   
  +    protected FtpUserManagerMonitor ftpUserManagerMonitor;
   
       /**
        * Save user data. Store the properties.
  @@ -313,7 +277,7 @@
                   mUserData.load(fis);
                   fis.close();
                   mlLastModified = lastModified;
  -                getLogger().info("File modified - loading " + mUserDataFile.getAbsolutePath());
  +                ftpUserManagerMonitor.info("File modified - loading " + mUserDataFile.getAbsolutePath());
               }
           } catch (IOException e) {
               throw new UserManagerException(e);
  @@ -324,7 +288,6 @@
        * Close the user manager - remove existing entries.
        */
       public void dispose() {
  -        getLogger().info("Closing properties user manager...");
           if (mUserData != null) {
               mUserData.clear();
               mUserData = null;
  
  
  
  1.1                  incubator-ftpserver/src/java/org/apache/ftpserver/usermanager/AvalonDbUserManager.java
  
  Index: AvalonDbUserManager.java
  ===================================================================
  package org.apache.ftpserver.usermanager;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.configuration.Configurable;
  
  /**
   *
   * @phoenix:block
   * @phoenix:service name="org.apache.ftpserver.usermanager.UserManagerInterface"
   *
   *
   * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
   * @author Paul Hammant
   * @version $Revision: 1.1 $
   */
  public class AvalonDbUserManager extends DbUserManager implements Configurable {
      /**
       * Set configuration - open database connection
       */
      public void configure(Configuration conf) throws ConfigurationException {
  
          String className = conf.getChild("driver").getValue();
          mUrl          = conf.getChild("url").getValue();
          mUser         = conf.getChild("user").getValue();
          mPassword     = conf.getChild("password").getValue();
          mInsUserStmt  = conf.getChild("sql-insert").getValue();
          mDelUserStmt  = conf.getChild("sql-delete").getValue();
          mSelUserStmt  = conf.getChild("sql-select").getValue();
          mGetAllStmt   = conf.getChild("sql-all").getValue();
          mUpdUserStmt  = conf.getChild("sql-update").getValue();
  
          try {
              Class.forName(className);
  
              openDbConnection();
          }
          catch(Exception ex) {
              throw new ConfigurationException("DbUserManager.configure()", ex);
          }
          Configuration adminConf = conf.getChild("ftp-admin-name", false);
          mstAdminName = "admin";
          if(adminConf != null) {
              mstAdminName = adminConf.getValue(mstAdminName);
          }
  
  
      }
  
  
  }
  
  
  
  1.1                  incubator-ftpserver/src/java/org/apache/ftpserver/usermanager/AvalonPropertiesUserManager.java
  
  Index: AvalonPropertiesUserManager.java
  ===================================================================
  package org.apache.ftpserver.usermanager;
  
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.ftpserver.util.BaseProperties;
  
  import java.io.File;
  import java.io.IOException;
  
  /**
   *
   * @phoenix:block
   * @phoenix:service name="org.apache.ftpserver.usermanager.UserManagerInterface"
   *
   * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
   * @author Paul Hammant
   * @version $Revision: 1.1 $
   */
  public class AvalonPropertiesUserManager extends PropertiesUserManager implements Configurable,
Contextualizable, LogEnabled {
      private Logger logger;
  
      public void enableLogging(Logger logger) {
          this.logger = logger;
      }
  
      /**
       * Set application context
       */
      public void contextualize(Context context) throws ContextException {
          try {
              File appDir = (File)context.get("app.home");
              if(!appDir.exists()) {
                  appDir.mkdirs();
              }
              mUserDataFile = new File(appDir, USER_PROP);
  
              mUserDataFile.createNewFile();
              mUserData = new BaseProperties(mUserDataFile);
              mlLastModified = mUserDataFile.lastModified();
              logger.info("Loaded user data file - " + mUserDataFile);
          }
          catch(IOException ex) {
              logger.error(ex.getMessage(), ex);
              throw new ContextException(ex.getMessage());
          }
      }
  
      /**
       * Set configuration
       */
      public void configure(Configuration conf) throws ConfigurationException {
          mbEncrypt = conf.getChild("encrypt").getValueAsBoolean(false);
          Configuration adminConf = conf.getChild("ftp-admin-name", false);
          mstAdminName = "admin";
          if(adminConf != null) {
              mstAdminName = adminConf.getValue(mstAdminName);
          }
  
      }
  }
  
  
  
  1.1                  incubator-ftpserver/src/java/org/apache/ftpserver/usermanager/AvlalonLdapUserManager.java
  
  Index: AvlalonLdapUserManager.java
  ===================================================================
  package org.apache.ftpserver.usermanager;
  
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.ftpserver.AvalonFtpUserManagerMonitor;
  
  import javax.naming.NamingException;
  import javax.naming.directory.BasicAttribute;
  import javax.naming.directory.InitialDirContext;
  import java.util.Properties;
  
  /**
   *
   * @phoenix:block
   * @phoenix:service name="org.apache.ftpserver.usermanager.UserManagerInterface"
   *
   * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
   * @author Paul Hammant
   * @version $Revision: 1.1 $
   */
  public class AvlalonLdapUserManager extends LdapUserManager implements Configurable, LogEnabled
{
  
      private Logger logger;
  
      public void enableLogging(Logger logger) {
          this.logger = logger;
          ftpUserManagerMonitor = new AvalonFtpUserManagerMonitor(logger);
      }
  
      /**
       * Instantiate <code>UserManager</code> implementation.
       * Open LDAP connection.
       */
      public void configure(Configuration conf) throws ConfigurationException {
  
          // get ldap parameters
          String url      = conf.getChild("url").getValue();
          String admin    = conf.getChild("admin").getValue();
          String password = conf.getChild("password").getValue();
          String auth     = conf.getChild("authentication").getValue();
  
          mstRoot     = conf.getChild("root").getValue();
          mstDnPrefix = conf.getChild("prefix").getValue();
          mstDnSuffix = conf.getChild("suffix").getValue();
  
          try {
              mAdminEnv = new Properties();
              mAdminEnv.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
              mAdminEnv.setProperty(javax.naming.Context.PROVIDER_URL, url);
              mAdminEnv.setProperty(javax.naming.Context.SECURITY_AUTHENTICATION, auth);
              mAdminEnv.setProperty(javax.naming.Context.SECURITY_PRINCIPAL, admin);
              mAdminEnv.setProperty(javax.naming.Context.SECURITY_CREDENTIALS, password);
              mAdminContext = new InitialDirContext(mAdminEnv);
  
  
              // create objectClass attribute
              mObjClassAttr = new BasicAttribute(OBJ_CLASS, false);
              mObjClassAttr.add("ftpUsers");
              mObjClassAttr.add("inetOrgPerson");
              mObjClassAttr.add("organizationalPerson");
              mObjClassAttr.add("person");
              mObjClassAttr.add("top");
  
              logger.info("LDAP user manager opened.");
          }
          catch(NamingException ex) {
              throw new ConfigurationException("LdapUserManager.configure()", ex);
          }
          Configuration adminConf = conf.getChild("ftp-admin-name", false);
          mstAdminName = "admin";
          if(adminConf != null) {
              mstAdminName = adminConf.getValue(mstAdminName);
          }
  
      }
  
  
  }
  
  
  
  1.1                  incubator-ftpserver/src/java/org/apache/ftpserver/AvalonFtpUserManagerMonitor.java
  
  Index: AvalonFtpUserManagerMonitor.java
  ===================================================================
  package org.apache.ftpserver;
  
  import org.apache.ftpserver.interfaces.FtpUserManagerMonitor;
  import org.apache.avalon.framework.logger.Logger;
  
  /**
   * @author Paul Hammant
   * @version $Revision: 1.1 $
   */
  public class AvalonFtpUserManagerMonitor implements FtpUserManagerMonitor {
  
      Logger logger;
  
      public AvalonFtpUserManagerMonitor(Logger logger) {
          this.logger = logger;
      }
  
      public void generalError(String message, Exception ex) {
          logger.error(message, ex);
      }
  
      public void info(String message) {
          logger.info(message);
      }
  }
  
  
  
  1.1                  incubator-ftpserver/src/java/org/apache/ftpserver/interfaces/FtpUserManagerMonitor.java
  
  Index: FtpUserManagerMonitor.java
  ===================================================================
  package org.apache.ftpserver.interfaces;
  
  /**
   * @author Paul Hammant
   * @version $Revision: 1.1 $
   */
  public interface FtpUserManagerMonitor {
      void generalError(String message, Exception ex);
      void info(String message);
  }
  
  
  

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


Mime
View raw message