You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by dl...@apache.org on 2009/05/30 17:32:15 UTC

svn commit: r780287 - in /mina/ftpserver/trunk/core/src: main/java/org/apache/ftpserver/command/impl/PASV.java test/java/org/apache/ftpserver/clienttests/PasvAddressWithOverridenHostnameGetter.java

Author: dlat
Date: Sat May 30 15:32:14 2009
New Revision: 780287

URL: http://svn.apache.org/viewvc?rev=780287&view=rev
Log:
FTPSERVER-300 added Javadoc & a test fix. 

Added:
    mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/PasvAddressWithOverridenHostnameGetter.java
Modified:
    mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/PASV.java

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/PASV.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/PASV.java?rev=780287&r1=780286&r2=780287&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/PASV.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/PASV.java Sat May 30 15:32:14 2009
@@ -45,6 +45,28 @@
  * its default data port) and to wait for a connection rather than initiate one
  * upon receipt of a transfer command. The response to this command includes the
  * host and port address this server is listening on.
+ * 
+ * FTPServer allows the user to configure an "external address" at the listener 
+ * level which will be the one reported by PASV response. This might solve some of
+ * the issues with NATed addresses ( the reported IP is internal and not accesible by the
+ * client) but not all of them - for example, if the FTPServer host has a dynamic IP
+ * address. The solution for all these cases would be switching to the EPSV command,
+ * which doesn't report any IP address back.
+ * 
+ * In the case that EPSV command isn't available to the client, FTPServer integrators
+ * can implement their own getPassiveExternalAddress to modify how the External IP
+ * is resolved. One common approach would be retrieving this address from a webpage
+ * which prints out the visitor's IP address. Another approach could be returning the
+ * external IP address from  the USER configuration(as when a single server is mapped
+ * into different addresses).
+ * 
+ * Please note that PASV command is an internal classes and thus shouldn't be extended.
+ * Integrators may decide to extend it at their own risk, but they should be aware that
+ * the 'internal API' can be changed at any moment. Besides, in some environments
+ * (OSGI) internal classes are not accesible and thus overriding won't work.   
+ * Still, the getPassiveExternalAddress method is provided for convenience so the
+ * code to overwrite when reimplementing PASV command can be easily located. 
+ * 
  *
  * @author The Apache MINA Project (dev@mina.apache.org)
  * */
@@ -106,7 +128,11 @@
             throw new DataConnectionException(ex.getLocalizedMessage(), ex);
         }
     }
-
+    /*
+     * (non-Javadoc)
+     * Returns the server's IP address which will be reported by the PASV response.
+     * 
+     */
     protected String getPassiveExternalAddress(final FtpIoSession session) {
         return session.getListener().getDataConnectionConfiguration().getPassiveExernalAddress();
 

Added: mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/PasvAddressWithOverridenHostnameGetter.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/PasvAddressWithOverridenHostnameGetter.java?rev=780287&view=auto
==============================================================================
--- mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/PasvAddressWithOverridenHostnameGetter.java (added)
+++ mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/PasvAddressWithOverridenHostnameGetter.java Sat May 30 15:32:14 2009
@@ -0,0 +1,76 @@
+/*
+ * 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.clienttests;
+
+import java.net.InetAddress;
+
+import org.apache.ftpserver.DataConnectionConfigurationFactory;
+import org.apache.ftpserver.FtpServerFactory;
+import org.apache.ftpserver.command.CommandFactory;
+import org.apache.ftpserver.command.CommandFactoryFactory;
+import org.apache.ftpserver.command.impl.PASV;
+import org.apache.ftpserver.impl.DefaultDataConnectionConfiguration;
+import org.apache.ftpserver.impl.FtpIoSession;
+import org.apache.ftpserver.listener.ListenerFactory;
+
+/**
+ * Test for external passive address configured as hostname rather than IP
+ * address.
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
+ *
+ */
+public class PasvAddressWithOverridenHostnameGetter extends ClientTestTemplate {
+
+    class PASVTest extends PASV{
+
+        @Override
+        protected String getPassiveExternalAddress(FtpIoSession session) {
+            return "10.10.10.10";
+        }
+        
+    }
+    protected FtpServerFactory createServer() throws Exception {
+        FtpServerFactory server = super.createServer();
+
+        ListenerFactory listenerFactory = new ListenerFactory(server.getListener("default"));
+        
+        DataConnectionConfigurationFactory dccFactory = new DataConnectionConfigurationFactory();
+
+        dccFactory.setPassiveExternalAddress("127.0.0.1");
+
+        listenerFactory.setDataConnectionConfiguration(dccFactory.createDataConnectionConfiguration());
+
+        server.addListener("default", listenerFactory.createListener());
+        CommandFactoryFactory cmFact = new CommandFactoryFactory();
+        cmFact.setUseDefaultCommands(true);
+        cmFact.addCommand("PASV", new PASVTest());
+        server.setCommandFactory(cmFact.createCommandFactory());
+        return server;
+    }
+
+    public void testPasvAddress() throws Exception {
+        client.login(ADMIN_USERNAME, ADMIN_PASSWORD);
+        client.pasv();
+
+        assertTrue(client.getReplyString().indexOf("(10,10,10,10,") > -1);
+    }
+}