incubator-ftpserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n..@apache.org
Subject svn commit: r508224 [2/2] - in /incubator/ftpserver/trunk: core/src/java/org/apache/ftpserver/ core/src/java/org/apache/ftpserver/command/ core/src/java/org/apache/ftpserver/ftplet/ core/src/java/org/apache/ftpserver/interfaces/ core/src/java/org/apach...
Date Thu, 15 Feb 2007 22:55:09 GMT
Propchange: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/AbstractListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/Connection.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/Connection.java?view=diff&rev=508224&r1=508223&r2=508224
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/Connection.java
(original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/Connection.java
Thu Feb 15 14:55:05 2007
@@ -21,6 +21,7 @@
 
 import org.apache.ftpserver.ftplet.FtpSession;
 import org.apache.ftpserver.interfaces.FtpServerContext;
+import org.apache.ftpserver.interfaces.FtpServerSession;
 
 /**
  * This is the connection request handler interface.
@@ -54,8 +55,8 @@
      * @param type The type of security to use, i.e. SSL or TLS
      * @throws Exception
      */
-    void beforeSecureControlChannel(String type) throws Exception;
+    void beforeSecureControlChannel(FtpServerSession session, String type) throws Exception;
 
-    void afterSecureControlChannel(String type) throws Exception;
+    void afterSecureControlChannel(FtpServerSession session, String type) throws Exception;
 }
  

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/ConnectionManager.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/ConnectionManager.java?view=diff&rev=508224&r1=508223&r2=508224
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/ConnectionManager.java
(original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/ConnectionManager.java
Thu Feb 15 14:55:05 2007
@@ -21,8 +21,6 @@
 
 import java.util.List;
 
-import org.apache.ftpserver.ftplet.Component;
-
 /**
  * It manages all the ftp connections.
  */

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/FtpProtocolHandler.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/FtpProtocolHandler.java?view=diff&rev=508224&r1=508223&r2=508224
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/FtpProtocolHandler.java
(original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/FtpProtocolHandler.java
Thu Feb 15 14:55:05 2007
@@ -27,8 +27,8 @@
 import org.apache.ftpserver.FtpWriter;
 import org.apache.ftpserver.ftplet.FileSystemView;
 import org.apache.ftpserver.ftplet.FtpException;
-import org.apache.ftpserver.ftplet.FtpRequest;
 import org.apache.ftpserver.ftplet.FtpReply;
+import org.apache.ftpserver.ftplet.FtpRequest;
 import org.apache.ftpserver.ftplet.FtpSession;
 import org.apache.ftpserver.ftplet.Ftplet;
 import org.apache.ftpserver.ftplet.FtpletEnum;

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/Listener.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/Listener.java?view=diff&rev=508224&r1=508223&r2=508224
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/Listener.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/Listener.java Thu
Feb 15 14:55:05 2007
@@ -19,6 +19,9 @@
 
 package org.apache.ftpserver.listener;
 
+import org.apache.ftpserver.interfaces.FtpServerContext;
+import org.apache.ftpserver.interfaces.Ssl;
+
 
 /**
  * Interface for the component responsible for waiting for incoming
@@ -27,6 +30,8 @@
  */
 public interface Listener {
     
+    Ssl getSsl();
+    
     /**
      * Start the listener, will initiate the listener waiting
      * on the socket.
@@ -35,7 +40,7 @@
      * 
      * @throws Exception On error during start up
      */
-    void start() throws Exception;
+    void start(FtpServerContext serverContext) throws Exception;
 
     /**
      * Stop the listener, it should no longer except socket requests.

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/io/IOConnection.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/io/IOConnection.java?view=diff&rev=508224&r1=508223&r2=508224
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/io/IOConnection.java
(original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/io/IOConnection.java
Thu Feb 15 14:55:05 2007
@@ -35,6 +35,7 @@
 import org.apache.ftpserver.FtpWriter;
 import org.apache.ftpserver.ftplet.FtpException;
 import org.apache.ftpserver.interfaces.FtpServerContext;
+import org.apache.ftpserver.interfaces.FtpServerSession;
 import org.apache.ftpserver.interfaces.Ssl;
 import org.apache.ftpserver.listener.AbstractConnection;
 import org.apache.ftpserver.listener.ConnectionObserver;
@@ -59,7 +60,7 @@
     /**
      * Constructor - set the control socket.
      */
-    public IOConnection(FtpServerContext serverContext, Socket controlSocket) throws IOException
{
+    public IOConnection(FtpServerContext serverContext, Socket controlSocket, IOListener
listener) throws IOException {
         super(serverContext);
         
         this.controlSocket = controlSocket;
@@ -73,6 +74,8 @@
         ftpSession = new FtpSessionImpl(serverContext);
         ftpSession.setClientAddress(this.controlSocket.getInetAddress());
         ftpSession.setServerAddress(this.controlSocket.getLocalAddress());
+        ftpSession.setServerPort(this.controlSocket.getLocalPort());
+        ftpSession.setListener(listener);
 
         FtpDataConnectionFactory dataCon = new FtpDataConnectionFactory(this.serverContext,
ftpSession);
         dataCon.setServerControlAddress(controlSocket.getLocalAddress());
@@ -148,7 +151,7 @@
         } catch(SSLException ex) {
             log.warn("The client did not initiate the SSL connection correctly", ex);
         } catch(Exception ex) {
-            log.warn("RequestHandler.run()", ex);
+            log.warn("Client error, closing session", ex);
         }
         finally {
             // close all resources if not done already
@@ -196,10 +199,10 @@
     /**
      * Create secure socket.
      */
-    public void afterSecureControlChannel(String protocol) throws Exception {
+    public void afterSecureControlChannel(FtpServerSession ftpSession, String protocol) throws
Exception {
 
         // change socket to SSL socket
-        Ssl ssl = serverContext.getSocketFactory().getSSL();
+        Ssl ssl = ftpSession.getListener().getSsl();
         if(ssl == null) {
             throw new FtpException("Socket factory SSL not configured");
         }
@@ -213,7 +216,7 @@
         controlSocket = ssoc;
     }
 
-    public void beforeSecureControlChannel(String type) throws Exception {
+    public void beforeSecureControlChannel(FtpServerSession ftpSession, String type) throws
Exception {
         // do nothing
         
     }

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/io/IOListener.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/io/IOListener.java?view=diff&rev=508224&r1=508223&r2=508224
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/io/IOListener.java
(original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/io/IOListener.java
Thu Feb 15 14:55:05 2007
@@ -26,6 +26,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.ftpserver.interfaces.FtpServerContext;
+import org.apache.ftpserver.listener.AbstractListener;
 import org.apache.ftpserver.listener.Connection;
 import org.apache.ftpserver.listener.ConnectionManager;
 import org.apache.ftpserver.listener.Listener;
@@ -34,10 +35,10 @@
  * The default {@link Listener} implementation.
  *
  */
-public class IOListener implements Listener, Runnable {
+public class IOListener extends AbstractListener implements Runnable {
 
     private Log log;
-    
+
     private FtpServerContext serverContext;
 
     private ServerSocket serverSocket;
@@ -47,26 +48,38 @@
     private boolean suspended = false;
 
     /**
-     * Constructs a listener based on the configuration object
-     * 
-     * @param serverContext Configuration for the listener
+     * @see Listener#start(FtpServerContext)
      */
-    public IOListener(FtpServerContext serverContext) {
+    public void start(FtpServerContext serverContext) throws Exception {
         this.serverContext = serverContext;
         
         log = serverContext.getLogFactory().getInstance(getClass());
-    }
 
-    /**
-     * @see Listener#start()
-     */
-    public void start() throws Exception {
-        serverSocket = serverContext.getSocketFactory().createServerSocket();
+        serverSocket = createServerSocket();
 
         listenerThread = new Thread(this);
         listenerThread.start();
 
     }
+    
+    /**
+     * Create server socket.
+     */
+    private ServerSocket createServerSocket() throws Exception { 
+        ServerSocket ssocket = null;
+        
+        if(isImplicitSsl()) {
+            ssocket = getSsl().createServerSocket(null, getServerAddress(), getPort());
+        } else  {
+            if(getServerAddress() == null) {
+                ssocket = new ServerSocket(getPort(), 100);
+            } else {
+                ssocket = new ServerSocket(getPort(), 100, getServerAddress());
+            }
+        }
+        
+        return ssocket;
+    }
 
     /**
      * The main thread method for the listener
@@ -106,7 +119,7 @@
                     continue;
                 }
 
-                Connection connection = new IOConnection(serverContext, soc);
+                Connection connection = new IOConnection(serverContext, soc, this);
                 conManager.newConnection(connection);
             } catch (SocketException ex) {
                 return;

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/mina/MinaConnection.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/mina/MinaConnection.java?view=diff&rev=508224&r1=508223&r2=508224
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/mina/MinaConnection.java
(original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/mina/MinaConnection.java
Thu Feb 15 14:55:05 2007
@@ -29,6 +29,7 @@
 import org.apache.ftpserver.FtpSessionImpl;
 import org.apache.ftpserver.ftplet.FtpException;
 import org.apache.ftpserver.interfaces.FtpServerContext;
+import org.apache.ftpserver.interfaces.FtpServerSession;
 import org.apache.ftpserver.interfaces.Ssl;
 import org.apache.ftpserver.listener.AbstractConnection;
 import org.apache.ftpserver.listener.ConnectionObserver;
@@ -42,7 +43,7 @@
 
     private IoSession session;
     
-    public MinaConnection(FtpServerContext serverContext, IoSession session) throws IOException
{
+    public MinaConnection(FtpServerContext serverContext, IoSession session, MinaListener
listener) throws IOException {
         super(serverContext);
         
         this.session = session;
@@ -53,6 +54,8 @@
         ftpSession = new FtpSessionImpl(serverContext);
         ftpSession.setClientAddress(((InetSocketAddress)session.getRemoteAddress()).getAddress());
         ftpSession.setServerAddress(((InetSocketAddress)session.getLocalAddress()).getAddress());
+        ftpSession.setServerPort(((InetSocketAddress)session.getLocalAddress()).getPort());
+        ftpSession.setListener(listener);
 
         FtpDataConnectionFactory dataCon = new FtpDataConnectionFactory(this.serverContext,
ftpSession);
         dataCon.setServerControlAddress(((InetSocketAddress)session.getLocalAddress()).getAddress());
@@ -86,8 +89,8 @@
         
     }
 
-    public void beforeSecureControlChannel(String type) throws Exception {
-        Ssl ssl = serverContext.getSocketFactory().getSSL();
+    public void beforeSecureControlChannel(FtpServerSession ftpSession, String type) throws
Exception {
+        Ssl ssl = ftpSession.getListener().getSsl();
         
         if(ssl != null) {
             session.setAttribute(SSLFilter.DISABLE_ENCRYPTION_ONCE);
@@ -102,7 +105,7 @@
         
     }
 
-    public void afterSecureControlChannel(String type) throws Exception {
+    public void afterSecureControlChannel(FtpServerSession ftpSession, String type) throws
Exception {
         // do nothing
     }
 }

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/mina/MinaFtpProtocolHandler.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/mina/MinaFtpProtocolHandler.java?view=diff&rev=508224&r1=508223&r2=508224
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/mina/MinaFtpProtocolHandler.java
(original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/mina/MinaFtpProtocolHandler.java
Thu Feb 15 14:55:05 2007
@@ -43,17 +43,20 @@
     
     private FtpServerContext serverContext;
     private FtpProtocolHandler protocolHandler;
+    private MinaListener listener;
     
-    public MinaFtpProtocolHandler(FtpServerContext serverContext, FtpProtocolHandler protocolHandler)
throws IOException {
+    public MinaFtpProtocolHandler(FtpServerContext serverContext, FtpProtocolHandler protocolHandler,
MinaListener listener) throws IOException {
         this.serverContext = serverContext;
         this.protocolHandler = protocolHandler;
+        this.listener = listener;
+         
     }
 
     /* (non-Javadoc)
      * @see org.apache.mina.common.IoHandlerAdapter#sessionCreated(org.apache.mina.common.IoSession)
      */
     public void sessionCreated(IoSession session) throws Exception {
-        MinaConnection connection = new MinaConnection(serverContext, session);
+        MinaConnection connection = new MinaConnection(serverContext, session, listener);
         session.setAttribute(CONNECTION_KEY, connection);
         
         MinaFtpResponseOutput output = new MinaFtpResponseOutput(session);

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/mina/MinaListener.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/mina/MinaListener.java?view=diff&rev=508224&r1=508223&r2=508224
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/mina/MinaListener.java
(original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/listener/mina/MinaListener.java
Thu Feb 15 14:55:05 2007
@@ -20,16 +20,14 @@
 package org.apache.ftpserver.listener.mina;
 
 import java.io.IOException;
-import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.security.GeneralSecurityException;
 
 import org.apache.commons.logging.Log;
 import org.apache.ftpserver.interfaces.FtpServerContext;
-import org.apache.ftpserver.interfaces.Ssl;
+import org.apache.ftpserver.listener.AbstractListener;
 import org.apache.ftpserver.listener.FtpProtocolHandler;
 import org.apache.ftpserver.listener.Listener;
-import org.apache.ftpserver.socketfactory.SSLFtpSocketFactory;
 import org.apache.mina.common.IoAcceptor;
 import org.apache.mina.filter.LoggingFilter;
 import org.apache.mina.filter.SSLFilter;
@@ -42,11 +40,9 @@
  * The default {@link Listener} implementation.
  *
  */
-public class MinaListener implements Listener {
+public class MinaListener extends AbstractListener {
 
     private Log log;
-    
-    private FtpServerContext serverContext;
 
     private IoAcceptor acceptor = new SocketAcceptor();
     
@@ -57,27 +53,18 @@
     private SocketAcceptorConfig cfg;
     
     boolean suspended = false;
- 
 
     /**
-     * Constructs a listener based on the configuration object
-     * 
-     * @param serverContext Configuration for the listener
-     * @throws Exception 
+     * @see Listener#start(FtpServerContext)
      */
-    public MinaListener(FtpServerContext serverContext) throws Exception {
-        this.serverContext = serverContext;
+    public void start(FtpServerContext serverContext) throws Exception {
         
         log = serverContext.getLogFactory().getInstance(getClass());
         
-        
-        int port = serverContext.getSocketFactory().getPort();
-        InetAddress serverAddress = serverContext.getSocketFactory().getServerAddress();
-        
-        if(serverAddress != null) {
-            address = new InetSocketAddress(serverAddress, port );
+        if(getServerAddress() != null) {
+            address = new InetSocketAddress(getServerAddress(), getPort() );
         } else {
-            address = new InetSocketAddress( port );
+            address = new InetSocketAddress( getPort() );
         }
         
         cfg = new SocketAcceptorConfig();
@@ -91,10 +78,9 @@
         // Decrease the default receiver buffer size
         ((SocketSessionConfig) acceptor.getDefaultConfig().getSessionConfig()).setReceiveBufferSize(512);

         
-        if(serverContext.getSocketFactory() instanceof SSLFtpSocketFactory) {
-            Ssl ssl = serverContext.getSocketFactory().getSSL();
+        if(isImplicitSsl()) {
             try {
-                SSLFilter sslFilter = new SSLFilter( ssl.getSSLContext() );
+                SSLFilter sslFilter = new SSLFilter( getSsl().getSSLContext() );
                 cfg.getFilterChain().addFirst("sslFilter", sslFilter);
 
             } catch (GeneralSecurityException e) {
@@ -102,14 +88,9 @@
             }
             
         }
-    }
-
-    /**
-     * @see Listener#start()
-     */
-    public void start() throws Exception {
         
-        protocolHandler = new MinaFtpProtocolHandler(serverContext, new FtpProtocolHandler(serverContext));
+        
+        protocolHandler = new MinaFtpProtocolHandler(serverContext, new FtpProtocolHandler(serverContext),
this);
 
         acceptor.bind(address, protocolHandler, cfg );
     }

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/socketfactory/FtpSocketFactory.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/socketfactory/FtpSocketFactory.java?view=diff&rev=508224&r1=508223&r2=508224
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/socketfactory/FtpSocketFactory.java
(original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/socketfactory/FtpSocketFactory.java
Thu Feb 15 14:55:05 2007
@@ -77,13 +77,13 @@
             Configuration sslConf = conf.subset("ssl");
             if(!sslConf.isEmpty()) {
                 ssl = (Ssl)Class.forName("org.apache.ftpserver.ssl.DefaultSsl").newInstance();
-                ssl.setLogFactory(logFactory);
-                ssl.configure(sslConf);
+                //ssl.setLogFactory(logFactory);
+                //ssl.configure(sslConf);
             }
         }
-        catch(FtpException ex) {
+        /*catch(FtpException ex) {
             throw ex;
-        }
+        }*/
         catch(Exception ex) {
             log.fatal("FtpSocketFactory.configure()", ex);
             throw new FtpException("FtpSocketFactory.configure()", ex);

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/ssl/DefaultSsl.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/ssl/DefaultSsl.java?view=diff&rev=508224&r1=508223&r2=508224
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/ssl/DefaultSsl.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/ssl/DefaultSsl.java Thu Feb
15 14:55:05 2007
@@ -19,6 +19,7 @@
 
 package org.apache.ftpserver.ssl;
 
+import java.io.File;
 import java.io.FileInputStream;
 import java.net.InetAddress;
 import java.net.ServerSocket;
@@ -37,9 +38,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.ftpserver.ftplet.Component;
-import org.apache.ftpserver.ftplet.Configuration;
-import org.apache.ftpserver.ftplet.FtpException;
+import org.apache.ftpserver.FtpServerConfigurationException;
 import org.apache.ftpserver.interfaces.Ssl;
 import org.apache.ftpserver.util.IoUtils;
 
@@ -48,18 +47,18 @@
  * Ssl implementation. This class encapsulates all 
  * the SSL functionalities.
  */
-public class DefaultSsl implements Ssl, Component {
+public class DefaultSsl implements Ssl {
     
-    private Log log;
+    private Log log = LogFactory.getLog(DefaultSsl.class);
     
-    private String keystoreFile;
-    private String keystorePass;
-    private String keystoreType;
-    private String keystoreAlgorithm;
-    
-    private String sslProtocol;
-    private boolean clientAuthReqd;
-    private String keyPass;
+    private File keystoreFile = new File("./res/.keystore");
+    private String keystorePass = "password";   // TODO should we really default this value?
+    private String keystoreType = "JKS";
+    private String keystoreAlgorithm = "SunX509";
+    
+    private String sslProtocol = "TLS";
+    private boolean clientAuthReqd = false;
+    private String keyPass = "password";   // TODO should we really default this value?
 
     private KeyStore keyStore;
     private KeyManagerFactory keyManagerFactory;
@@ -67,30 +66,41 @@
     
     private HashMap sslContextMap;
     
+    public void setKeystoreFile(File keyStoreFile) {
+        this.keystoreFile = keyStoreFile;
+    }
     
-    /**
-     * Set the log actory.
-     */
-    public void setLogFactory(LogFactory factory) {
-        log = factory.getInstance(getClass());
+    public void setKeystorePassword(String keystorePass) {
+        this.keystorePass = keystorePass;
+    }
+    
+    public void setKeystoreType(String keystoreType) {
+        this.keystoreType = keystoreType;
+    }
+    
+    public void setKeystoreAlgorithm(String keystoreAlgorithm) {
+        this.keystoreAlgorithm = keystoreAlgorithm;
+    }
+    
+    public void setSslProtocol(String sslProtocol) {
+        this.sslProtocol = sslProtocol;
     }
     
+    public void setClientAuthentication(boolean clientAuthReqd) {
+        this.clientAuthReqd = clientAuthReqd;
+    }
+    
+    public void setKeyPassword(String keyPass) {
+        this.keyPass = keyPass;
+    }
+    
+    
     /**
      * Configure secure server related properties. 
      */
-    public void configure(Configuration conf) throws FtpException {
+    public synchronized void init() {
         
         try {
-            
-            // get configuration parameters
-            keystoreFile      = conf.getString("keystore-file", "./res/.keystore");
-            keystorePass      = conf.getString("keystore-password", "password");
-            keystoreType      = conf.getString("keystore-type", "JKS");
-            keystoreAlgorithm = conf.getString("keystore-algorithm", "SunX509");
-            sslProtocol       = conf.getString("ssl-protocol", "TLS");
-            clientAuthReqd    = conf.getBoolean("client-authentication", false);
-            keyPass           = conf.getString("key-password", "password");
-            
             // initialize keystore
             FileInputStream fin = null;
             try {
@@ -116,7 +126,13 @@
         }
         catch(Exception ex) {
             log.fatal("DefaultSsl.configure()", ex);
-            throw new FtpException("DefaultSsl.configure()", ex);
+            throw new FtpServerConfigurationException("DefaultSsl.configure()", ex);
+        }
+    }
+    
+    private void lazyInit() {
+        if(keyManagerFactory == null) {
+            init();
         }
     }
     
@@ -124,6 +140,7 @@
      * Get SSL Context.
      */
     public synchronized SSLContext getSSLContext(String protocol) throws GeneralSecurityException
{
+        lazyInit();
         
         // null value check
         if(protocol == null) {
@@ -153,7 +170,8 @@
     public ServerSocket createServerSocket(String protocol,
                                            InetAddress addr, 
                                            int port) throws Exception {
-
+        lazyInit();
+        
         // get server socket factory
         SSLContext ctx = getSSLContext(protocol);
         SSLServerSocketFactory ssocketFactory = ctx.getServerSocketFactory();
@@ -180,6 +198,7 @@
     public Socket createSocket(String protocol,
                                Socket soc, 
                                boolean clientMode) throws Exception {
+        lazyInit();
         
         // already wrapped - no need to do anything
         if(soc instanceof SSLSocket) {
@@ -211,7 +230,8 @@
                                InetAddress addr, 
                                int port,
                                boolean clientMode) throws Exception {
-
+        lazyInit();
+        
         // get socket factory
         SSLContext ctx = getSSLContext(protocol);
         SSLSocketFactory socFactory = ctx.getSocketFactory();
@@ -235,6 +255,7 @@
                                InetAddress localhost,
                                int localport,
                                boolean clientMode) throws Exception {
+        lazyInit();
         
         // get socket factory
         SSLContext ctx = getSSLContext(protocol);

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/util/ClassUtils.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/util/ClassUtils.java?view=diff&rev=508224&r1=508223&r2=508224
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/util/ClassUtils.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/util/ClassUtils.java Thu
Feb 15 14:55:05 2007
@@ -43,6 +43,7 @@
 import java.util.Map;
 import java.util.StringTokenizer;
 
+import org.apache.ftpserver.FtpServerConfigurationException;
 import org.apache.ftpserver.ftplet.Configuration;
 
 
@@ -58,6 +59,10 @@
     public static void setProperty(Object target, String propertyName, Object propertyValue)
{
         PropertyDescriptor setter = getDescriptor(target.getClass(), propertyName);
         
+        if(setter == null) {
+            return;
+        }
+        
         setProperty(target, setter, propertyValue);
     }
     
@@ -156,8 +161,10 @@
                 
                 while (mapKeys.hasNext()) {
                     String mapKey = (String) mapKeys.next();
+                    String mapValue = config.getString(mapKey, null);
+                    Configuration mapConfig = config.subset(mapKey);
                     
-                    map.put(mapKey, config.getString(mapKey, null));
+                    map.put(mapKey, createObject(String.class, mapConfig, mapValue));
                 }
                 
                 value = map;
@@ -237,6 +244,11 @@
         return keyList.iterator();
     }
     
+    public static Map createMap(Configuration config) {
+        return (Map) createObject(Map.class, config, null);
+        
+    }
+    
     public static Object createBean(Configuration config, String defaultClass) {
         String className = config.getString("class", defaultClass);
         
@@ -264,6 +276,10 @@
             String propValue = config.getString(key, null);
             
             PropertyDescriptor descriptor = getDescriptor(clazz, key);
+            
+            if(descriptor == null) {
+                throw new FtpServerConfigurationException("Unknown property \"" + key + "\"
on class " + className);
+            }
 
             Object value = createObject(descriptor.getPropertyType(), subConfig, propValue);
 

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/util/FtpReplyUtil.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/util/FtpReplyUtil.java?view=diff&rev=508224&r1=508223&r2=508224
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/util/FtpReplyUtil.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/util/FtpReplyUtil.java Thu
Feb 15 14:55:05 2007
@@ -23,8 +23,8 @@
 
 import org.apache.ftpserver.DefaultFtpReply;
 import org.apache.ftpserver.ftplet.FileSystemView;
-import org.apache.ftpserver.ftplet.FtpRequest;
 import org.apache.ftpserver.ftplet.FtpReply;
+import org.apache.ftpserver.ftplet.FtpRequest;
 import org.apache.ftpserver.ftplet.FtpStatistics;
 import org.apache.ftpserver.interfaces.FtpServerSession;
 import org.apache.ftpserver.interfaces.MessageResource;
@@ -283,7 +283,7 @@
         
         // server port
         else if(varName.equals(SERVER_PORT)) {
-            varVal = String.valueOf(session.getServerContext().getServerPort());
+            varVal = String.valueOf(session.getServerPort());
         }
         
         return varVal;

Modified: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/AbstractFtpServerTestTemplate.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/AbstractFtpServerTestTemplate.java?view=diff&rev=508224&r1=508223&r2=508224
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/AbstractFtpServerTestTemplate.java
(original)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/AbstractFtpServerTestTemplate.java
Thu Feb 15 14:55:05 2007
@@ -54,7 +54,7 @@
 
     protected Properties createConfig() {
         Properties configProps = new Properties();
-        configProps.setProperty("config.socket-factory.port", Integer
+        configProps.setProperty("config.listeners.default.port", Integer
                 .toString(serverPort));
 
         return configProps;

Modified: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/ComponentBeanTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/ComponentBeanTest.java?view=diff&rev=508224&r1=508223&r2=508224
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/ComponentBeanTest.java (original)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/ComponentBeanTest.java Thu
Feb 15 14:55:05 2007
@@ -21,13 +21,13 @@
 
 import java.util.Properties;
 
+import junit.framework.TestCase;
+
 import org.apache.commons.logging.LogFactory;
 import org.apache.ftpserver.config.PropertiesConfiguration;
 import org.apache.ftpserver.ftplet.Component;
 import org.apache.ftpserver.ftplet.Configuration;
 import org.apache.ftpserver.ftplet.FtpException;
-
-import junit.framework.TestCase;
 
 
 public class ComponentBeanTest extends TestCase {

Added: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/ConfigurableFtpServerContextTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/ConfigurableFtpServerContextTest.java?view=auto&rev=508224
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/ConfigurableFtpServerContextTest.java
(added)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/ConfigurableFtpServerContextTest.java
Thu Feb 15 14:55:05 2007
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */  
+
+package org.apache.ftpserver;
+
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.apache.ftpserver.config.PropertiesConfiguration;
+import org.apache.ftpserver.ftplet.Configuration;
+import org.apache.ftpserver.listener.Listener;
+import org.apache.ftpserver.listener.io.IOListener;
+import org.apache.ftpserver.listener.mina.MinaListener;
+
+
+public class ConfigurableFtpServerContextTest extends TestCase {
+
+    public void testConfigListeners() throws Exception {
+        Properties props = new Properties();
+        props.setProperty("config.listeners.foo1.class", IOListener.class.getName());
+        props.setProperty("config.listeners.foo2.class", MinaListener.class.getName());
+        
+        Configuration config = new PropertiesConfiguration(props);
+        
+        ConfigurableFtpServerContext ctx = new ConfigurableFtpServerContext(config);
+        
+        assertNotNull(ctx.getListener("foo1"));
+        assertTrue(ctx.getListener("foo1") instanceof IOListener);
+        
+        assertNotNull(ctx.getListener("foo2"));
+        assertTrue(ctx.getListener("foo2") instanceof MinaListener);
+        
+        Listener[] listeners = ctx.getListeners();
+        
+        assertEquals(2, listeners.length);
+        assertTrue(listeners[0] instanceof Listener);
+        assertTrue(listeners[1] instanceof Listener);
+        
+    }
+    
+}

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

Modified: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/PassivePortsTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/PassivePortsTest.java?view=diff&rev=508224&r1=508223&r2=508224
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/PassivePortsTest.java (original)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/PassivePortsTest.java Thu
Feb 15 14:55:05 2007
@@ -32,7 +32,6 @@
     }
 
     public void testParseMaxValue() {
-        System.out.println(Short.MAX_VALUE);
         PassivePorts ports = PassivePorts.parse("65535");
         
         assertEquals(65535, ports.reserveNextPort());

Modified: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/ClientTestTemplate.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/ClientTestTemplate.java?view=diff&rev=508224&r1=508223&r2=508224
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/ClientTestTemplate.java
(original)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/ClientTestTemplate.java
Thu Feb 15 14:55:05 2007
@@ -33,6 +33,7 @@
 import org.apache.ftpserver.FtpServer;
 import org.apache.ftpserver.config.PropertiesConfiguration;
 import org.apache.ftpserver.interfaces.FtpServerContext;
+import org.apache.ftpserver.listener.mina.MinaListener;
 import org.apache.ftpserver.test.TestUtil;
 import org.apache.ftpserver.util.IoUtils;
 import org.apache.log4j.Logger;
@@ -70,7 +71,8 @@
         assertTrue(USERS_FILE.getAbsolutePath() + " must exist", USERS_FILE.exists());
 
         Properties configProps = new Properties();
-        configProps.setProperty("config.socket-factory.port", Integer
+        configProps.setProperty("config.listeners.default.class", MinaListener.class.getName());
+        configProps.setProperty("config.listeners.default.port", Integer
                 .toString(port));
         configProps.setProperty("config.user-manager.class",
                 "org.apache.ftpserver.usermanager.PropertiesUserManager");

Modified: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/interfaces/ServerFtpStatisticsTestTemplate.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/interfaces/ServerFtpStatisticsTestTemplate.java?view=diff&rev=508224&r1=508223&r2=508224
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/interfaces/ServerFtpStatisticsTestTemplate.java
(original)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/interfaces/ServerFtpStatisticsTestTemplate.java
Thu Feb 15 14:55:05 2007
@@ -49,7 +49,7 @@
         public void run() {            
         }
 
-        public void beforeSecureControlChannel(String type) throws Exception {
+        public void beforeSecureControlChannel(FtpServerSession session, String type) throws
Exception {
             
         }
 
@@ -65,7 +65,7 @@
             return 0;
         }
 
-        public void afterSecureControlChannel(String type) throws Exception {
+        public void afterSecureControlChannel(FtpServerSession session, String type) throws
Exception {
             
         }
         

Modified: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/util/ClassUtilsTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/util/ClassUtilsTest.java?view=diff&rev=508224&r1=508223&r2=508224
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/util/ClassUtilsTest.java
(original)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/util/ClassUtilsTest.java
Thu Feb 15 14:55:05 2007
@@ -278,6 +278,28 @@
         assertEquals("bar3", map.get("foo3"));
         assertEquals("bar4", map.get("foo4"));
     }
+    
+    public void testCreateMap() {
+        Properties props = new Properties();
+        props.setProperty("config.foo1.class", MyBean.class.getName());
+        props.setProperty("config.foo1.foo", "bar1");
+        props.setProperty("config.foo2.class", MyBean.class.getName());
+        props.setProperty("config.foo2.foo", "bar2");
+        props.setProperty("config.foo3.class", MyBean.class.getName());
+        props.setProperty("config.foo3.foo", "bar3");
+        props.setProperty("config.foo4.class", MyBean.class.getName());
+        props.setProperty("config.foo4.foo", "bar4");
+        
+        Configuration config = new PropertiesConfiguration(props);
+        
+        Map map = ClassUtils.createMap(config);
+        
+        for(int i = 1; i<5; i++) {
+            MyBean bean = (MyBean) map.get("foo" + i);
+            assertEquals("bar" + i, bean.getFoo());
+            
+        }
+    }
  
     public static class MyCollectionBean {
         private List list;

Modified: incubator/ftpserver/trunk/ftplet-api/src/java/org/apache/ftpserver/ftplet/FtpSession.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/ftplet-api/src/java/org/apache/ftpserver/ftplet/FtpSession.java?view=diff&rev=508224&r1=508223&r2=508224
==============================================================================
--- incubator/ftpserver/trunk/ftplet-api/src/java/org/apache/ftpserver/ftplet/FtpSession.java
(original)
+++ incubator/ftpserver/trunk/ftplet-api/src/java/org/apache/ftpserver/ftplet/FtpSession.java
Thu Feb 15 14:55:05 2007
@@ -48,6 +48,8 @@
     
     InetAddress getServerAddress();
     
+    int getServerPort();
+    
     Certificate[] getClientCertificates();
     
     /**

Modified: incubator/ftpserver/trunk/ftplet-api/src/java/org/apache/ftpserver/ftplet/FtpletContext.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/ftplet-api/src/java/org/apache/ftpserver/ftplet/FtpletContext.java?view=diff&rev=508224&r1=508223&r2=508224
==============================================================================
--- incubator/ftpserver/trunk/ftplet-api/src/java/org/apache/ftpserver/ftplet/FtpletContext.java
(original)
+++ incubator/ftpserver/trunk/ftplet-api/src/java/org/apache/ftpserver/ftplet/FtpletContext.java
Thu Feb 15 14:55:05 2007
@@ -19,8 +19,6 @@
 
 package org.apache.ftpserver.ftplet;
 
-import java.net.InetAddress;
-
 import org.apache.commons.logging.LogFactory;
 
 /**
@@ -55,14 +53,4 @@
      * Get Ftplet.
      */
     Ftplet getFtplet(String name);
-    
-    /**
-     * Get server address.
-     */
-    InetAddress getServerAddress();
-        
-    /**
-     * Get server port.
-     */ 
-    int getServerPort();
 }

Modified: incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/ImplicitClientAuthTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/ImplicitClientAuthTest.java?view=diff&rev=508224&r1=508223&r2=508224
==============================================================================
--- incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/ImplicitClientAuthTest.java
(original)
+++ incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/ImplicitClientAuthTest.java
Thu Feb 15 14:55:05 2007
@@ -26,8 +26,8 @@
 
     protected Properties createConfig() {
         Properties config = super.createConfig();
-        config.setProperty("config.socket-factory.class",
-                "org.apache.ftpserver.socketfactory.SSLFtpSocketFactory");
+        config.setProperty("config.listeners.default.implicitSsl",
+                "true");
 
         return config;
     }

Modified: incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/ImplicitSecurityTestTemplate.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/ImplicitSecurityTestTemplate.java?view=diff&rev=508224&r1=508223&r2=508224
==============================================================================
--- incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/ImplicitSecurityTestTemplate.java
(original)
+++ incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/ImplicitSecurityTestTemplate.java
Thu Feb 15 14:55:05 2007
@@ -32,8 +32,8 @@
      */
     protected Properties createConfig() {
         Properties config = super.createConfig();
-        config.setProperty("config.socket-factory.class",
-                "org.apache.ftpserver.socketfactory.SSLFtpSocketFactory");
+        config.setProperty("config.listeners.default.implicitSsl",
+                "true");
 
         return config;
     }

Modified: incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/SSLTestTemplate.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/SSLTestTemplate.java?view=diff&rev=508224&r1=508223&r2=508224
==============================================================================
--- incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/SSLTestTemplate.java
(original)
+++ incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/SSLTestTemplate.java
Thu Feb 15 14:55:05 2007
@@ -38,6 +38,7 @@
 import org.apache.ftpserver.FtpServer;
 import org.apache.ftpserver.config.PropertiesConfiguration;
 import org.apache.ftpserver.interfaces.FtpServerContext;
+import org.apache.ftpserver.listener.io.IOListener;
 import org.apache.ftpserver.util.IoUtils;
 
 public abstract class SSLTestTemplate extends TestCase {
@@ -82,8 +83,24 @@
         assertTrue(FTPSERVER_KEYSTORE.exists());
         
         Properties configProps = new Properties();
-        configProps.setProperty("config.socket-factory.port", Integer
+        configProps.setProperty("config.listeners.default.class", IOListener.class.getName());
+        configProps.setProperty("config.listeners.default.port", Integer
                 .toString(port));
+        configProps.setProperty("config.listeners.default.ssl.class",
+                DefaultSsl.class.getName());
+        configProps.setProperty("config.listeners.default.ssl.keystore-file",
+                FTPSERVER_KEYSTORE.getAbsolutePath());
+        configProps.setProperty("config.listeners.default.ssl.keystore-password",
+                "password");
+        configProps
+                .setProperty("config.listeners.default.ssl.ssl-protocol", getAuthValue());
+        configProps.setProperty(
+                "config.listeners.default.ssl.client-authentication", getClientAuth());
+        configProps.setProperty("config.listeners.default.ssl.key-password",
+                "password");
+
+        //configProps.setProperty("config.socket-factory.port", Integer
+        //        .toString(port));
         configProps.setProperty("config.user-manager.class",
                 "org.apache.ftpserver.usermanager.PropertiesUserManager");
         configProps.setProperty("config.user-manager.admin", "admin");
@@ -93,19 +110,21 @@
                 USERS_FILE.getAbsolutePath());
         configProps.setProperty("config.create-default-user", "false");
 
-        configProps.setProperty("config.socket-factory.class",
-                "org.apache.ftpserver.socketfactory.FtpSocketFactory");
-        configProps.setProperty("config.socket-factory.ssl.keystore-file",
-                FTPSERVER_KEYSTORE.getAbsolutePath());
-        configProps.setProperty("config.socket-factory.ssl.keystore-password",
-                "password");
-        configProps
-                .setProperty("config.socket-factory.ssl.ssl-protocol", getAuthValue());
-        configProps.setProperty(
-                "config.socket-factory.ssl.client-authentication", getClientAuth());
-        configProps.setProperty("config.socket-factory.ssl.key-password",
-                "password");
-
+        //configProps.setProperty("config.socket-factory.class",
+        //        "org.apache.ftpserver.socketfactory.FtpSocketFactory");
+//        configProps.setProperty("config.socket-factory.ssl.keystore-file",
+//                FTPSERVER_KEYSTORE.getAbsolutePath());
+//        configProps.setProperty("config.socket-factory.ssl.keystore-password",
+//                "password");
+//        configProps
+//                .setProperty("config.socket-factory.ssl.ssl-protocol", getAuthValue());
+//        configProps.setProperty(
+//                "config.socket-factory.ssl.client-authentication", getClientAuth());
+//        configProps.setProperty("config.socket-factory.ssl.key-password",
+//                "password");
+//
+        configProps.setProperty("config.data-connection.ssl.class",
+                DefaultSsl.class.getName());
         configProps.setProperty("config.data-connection.ssl.keystore-file",
                 FTPSERVER_KEYSTORE.getAbsolutePath());
         configProps.setProperty("config.data-connection.ssl.keystore-password",



Mime
View raw message