commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joe...@apache.org
Subject svn commit: r1448606 - in /commons/proper/vfs/trunk: ./ core/src/main/java/org/apache/commons/vfs2/ core/src/main/java/org/apache/commons/vfs2/provider/ftp/ core/src/main/java/org/apache/commons/vfs2/provider/ftps/ core/src/test/java/org/apache/commons...
Date Thu, 21 Feb 2013 11:45:46 GMT
Author: joehni
Date: Thu Feb 21 11:45:46 2013
New Revision: 1448606

URL: http://svn.apache.org/r1448606
Log:
Add support for FTPS command to set the DataChannelProtectionLevel (VFS-412).

Added:
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsDataChannelProtectionLevel.java
  (with props)
Modified:
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/Resources.properties
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsClientFactory.java
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsFileSystemConfigBuilder.java
    commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/AbstractFtpsProviderTestCase.java
    commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderExplicitTestCase.java
    commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderImplicitTestCase_Disabled.java
    commons/proper/vfs/trunk/pom.xml
    commons/proper/vfs/trunk/src/changes/changes.xml

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/Resources.properties
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/Resources.properties?rev=1448606&r1=1448605&r2=1448606&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/Resources.properties
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/Resources.properties
Thu Feb 21 11:45:46 2013
@@ -234,6 +234,9 @@ vfs.provider.ftp/output-error.debug=Cant
 vfs.provider.ftp/rename-file.error=Could not rename FTP file "{0}" to "{1}".
 vfs.provider.ftp/set-file-type.error=Could not set the file type to "{0}".
 
+# FTPS Provider
+vfs.provider.ftps/data-channel.level=Failed to setup secure data channel level "{0}".
+
 # SFTP Provider
 vfs.provider.sftp/change-work-directory-back.error=Could not change back to work directory
"{0}".
 vfs.provider.sftp/change-work-directory.error=Could not change to work directory "{0}".

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java?rev=1448606&r1=1448605&r2=1448606&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java
Thu Feb 21 11:45:46 2013
@@ -72,6 +72,12 @@ public final class FtpClientFactory
 		{
 			return new FTPClient();
 		}
+
+		@Override
+		protected void setupOpenConnection(final FTPClient client, final FileSystemOptions fileSystemOptions)
+		{
+			// nothing to do for FTP
+		}
     }
     
     public static abstract class ConnectionFactory<C extends FTPClient, B extends FtpFileSystemConfigBuilder>
{
@@ -204,7 +210,8 @@ public final class FtpClientFactory
 	                {
 	                    client.enterLocalPassiveMode();
 	                }
-	
+	                
+	                setupOpenConnection(client, fileSystemOptions);
 	            }
 	            catch (final IOException e)
 	            {
@@ -223,7 +230,8 @@ public final class FtpClientFactory
 	        }
 	    }
 
-		protected abstract C createClient(final FileSystemOptions fileSystemOptions) throws FileSystemException;
+		protected abstract C createClient(FileSystemOptions fileSystemOptions) throws FileSystemException;
+		protected abstract void setupOpenConnection(C client, FileSystemOptions fileSystemOptions)
throws IOException;
 	
 	    private void configureClient(final FileSystemOptions fileSystemOptions, final C client)
 	    {

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsClientFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsClientFactory.java?rev=1448606&r1=1448605&r2=1448606&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsClientFactory.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsClientFactory.java
Thu Feb 21 11:45:46 2013
@@ -17,6 +17,9 @@
 package org.apache.commons.vfs2.provider.ftps;
 
 
+import java.io.IOException;
+
+import javax.net.ssl.SSLException;
 import javax.net.ssl.TrustManager;
 
 import org.apache.commons.net.ftp.FTPSClient;
@@ -84,5 +87,21 @@ public final class FtpsClientFactory
 			client.setTrustManager(trustManager);
 	        return client;
 		}
+
+		@Override
+		protected void setupOpenConnection(final FTPSClient client, final FileSystemOptions fileSystemOptions)
+			throws IOException
+		{
+			final FtpsDataChannelProtectionLevel level = builder.getDataChannelProtectionLevel(fileSystemOptions);
+			if (level != null) {
+				// '0' means streaming, that's what we do!
+				try {
+					client.execPBSZ(0);
+					client.execPROT(level.name());
+				} catch (final SSLException e) {
+					throw new FileSystemException("vfs.provider.ftps/data-channel.level", e, level.toString());
+				}
+			}
+		}
     }
 }

Added: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsDataChannelProtectionLevel.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsDataChannelProtectionLevel.java?rev=1448606&view=auto
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsDataChannelProtectionLevel.java
(added)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsDataChannelProtectionLevel.java
Thu Feb 21 11:45:46 2013
@@ -0,0 +1,27 @@
+/*
+ * 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.commons.vfs2.provider.ftps;
+
+/**
+ * Protection level of the data channel in a FTPS communication.
+ *
+ * @see <a href="http://tools.ietf.org/html/rfc2228#section-3">RFC 2228, section 3</a>
+ * @since 2.1
+ */
+public enum FtpsDataChannelProtectionLevel {
+	C, S, E, P
+}

Propchange: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsDataChannelProtectionLevel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsDataChannelProtectionLevel.java
------------------------------------------------------------------------------
    svn:keywords = Author Id HeadURL Revision

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsFileSystemConfigBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsFileSystemConfigBuilder.java?rev=1448606&r1=1448605&r2=1448606&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsFileSystemConfigBuilder.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftps/FtpsFileSystemConfigBuilder.java
Thu Feb 21 11:45:46 2013
@@ -32,6 +32,7 @@ public final class FtpsFileSystemConfigB
         new FtpsFileSystemConfigBuilder();
 
     private static final String FTPS_TYPE = _PREFIX + ".FTPS_TYPE";
+    private static final String PROT = _PREFIX + ".PROT";
 
     /**
      * FTPS implicit file type.
@@ -43,10 +44,6 @@ public final class FtpsFileSystemConfigB
      */
     public static final String FTPS_TYPE_EXPLICIT = "explicit";
 
-    // For VFS-412
-    // private static final String PROT =
-    // FtpsFileSystemConfigBuilder.class.getName() + ".PROT";
-
     private FtpsFileSystemConfigBuilder()
     {
         super("ftps.");
@@ -90,31 +87,29 @@ public final class FtpsFileSystemConfigB
         return getString(opts, FTPS_TYPE, FtpsFileSystemConfigBuilder.FTPS_TYPE_EXPLICIT);
     }
 
-
-// For VFS-412
-//    /**
-//     * Gets the data channel protection level (PROT).
-//     *
-//     * @param opts The FileSystemOptions.
-//     * @return The PROT value.
-//     * @see org.apache.commons.net.ftp.FTPSClient#execPROT(String)
-//     * @since 2.1
-//     */
-//    public String getDataChannelProtectionLevel(FileSystemOptions opts)
-//    {
-//        return (String) getParam(opts, PROT);
-//    }
-//
-//    /**
-//     * Sets the data channel protection level (PROT).
-//     *
-//     * @param opts  The FileSystemOptions.
-//     * @param prot The PROT value, {@code null} has no effect.
-//     * @see org.apache.commons.net.ftp.FTPSClient#execPROT(String)
-//     * @since 2.1
-//     */
-//    public void setDataChannelProtectionLevel(FileSystemOptions opts, String prot)
-//    {
-//        setParam(opts, PROT, prot);
-//    }
+	/**
+	 * Gets the data channel protection level (PROT).
+	 * 
+	 * @param opts The FileSystemOptions.
+	 * @return The PROT value.
+	 * @see org.apache.commons.net.ftp.FTPSClient#execPROT(String)
+	 * @since 2.1
+	 */
+	public FtpsDataChannelProtectionLevel getDataChannelProtectionLevel(final FileSystemOptions
opts)
+	{
+		return (FtpsDataChannelProtectionLevel)getParam(opts, PROT);
+	}
+
+	/**
+	 * Sets the data channel protection level (PROT).
+	 * 
+	 * @param opts The FileSystemOptions.
+	 * @param prot The PROT value, {@code null} has no effect.
+	 * @see org.apache.commons.net.ftp.FTPSClient#execPROT(String)
+	 * @since 2.1
+	 */
+	public void setDataChannelProtectionLevel(final FileSystemOptions opts, final FtpsDataChannelProtectionLevel
prot)
+	{
+		setParam(opts, PROT, prot);
+	}
 }

Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/AbstractFtpsProviderTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/AbstractFtpsProviderTestCase.java?rev=1448606&r1=1448605&r2=1448606&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/AbstractFtpsProviderTestCase.java
(original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/AbstractFtpsProviderTestCase.java
Thu Feb 21 11:45:46 2013
@@ -196,16 +196,17 @@ abstract class AbstractFtpsProviderTestC
         if (fileSystemOptions == null)
         {
             fileSystemOptions = new FileSystemOptions();
-            final FtpsFileSystemConfigBuilder builder = FtpsFileSystemConfigBuilder.getInstance();
-            builder.setConnectTimeout(fileSystemOptions, Integer.valueOf(1000));
-            builder.setDataTimeout(fileSystemOptions, Integer.valueOf(2000));
-            builder.setFtpsType(fileSystemOptions, isImplicit() 
-            	? FtpsFileSystemConfigBuilder.FTPS_TYPE_IMPLICIT 
-            	: FtpsFileSystemConfigBuilder.FTPS_TYPE_EXPLICIT);
+            setupOptions(FtpsFileSystemConfigBuilder.getInstance());
         }
         return fileSystemOptions;
     }
 
+	protected void setupOptions(final FtpsFileSystemConfigBuilder builder)
+	{
+		builder.setConnectTimeout(fileSystemOptions, Integer.valueOf(1000));
+		builder.setDataTimeout(fileSystemOptions, Integer.valueOf(2000));
+	}
+
     /**
      * Prepares the file system manager.
      */

Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderExplicitTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderExplicitTestCase.java?rev=1448606&r1=1448605&r2=1448606&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderExplicitTestCase.java
(original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderExplicitTestCase.java
Thu Feb 21 11:45:46 2013
@@ -16,6 +16,9 @@
  */
 package org.apache.commons.vfs2.provider.ftps.test;
 
+import org.apache.commons.vfs2.provider.ftps.FtpsDataChannelProtectionLevel;
+import org.apache.commons.vfs2.provider.ftps.FtpsFileSystemConfigBuilder;
+
 import junit.framework.Test;
 
 /**
@@ -29,6 +32,14 @@ public class FtpsProviderExplicitTestCas
 		return false;
 	}
 
+	@Override
+	protected void setupOptions(final FtpsFileSystemConfigBuilder builder)
+	{
+		super.setupOptions(builder);
+		builder.setDataChannelProtectionLevel(fileSystemOptions, FtpsDataChannelProtectionLevel.P);
+		builder.setFtpsType(fileSystemOptions, FtpsFileSystemConfigBuilder.FTPS_TYPE_EXPLICIT);
+	}
+
 	/**
      * Creates the test suite for the ftps file system.
      */

Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderImplicitTestCase_Disabled.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderImplicitTestCase_Disabled.java?rev=1448606&r1=1448605&r2=1448606&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderImplicitTestCase_Disabled.java
(original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftps/test/FtpsProviderImplicitTestCase_Disabled.java
Thu Feb 21 11:45:46 2013
@@ -16,6 +16,8 @@
  */
 package org.apache.commons.vfs2.provider.ftps.test;
 
+import org.apache.commons.vfs2.provider.ftps.FtpsFileSystemConfigBuilder;
+
 import junit.framework.Test;
 
 /**
@@ -33,6 +35,13 @@ public class FtpsProviderImplicitTestCas
 		return true;
 	}
 
+	@Override
+	protected void setupOptions(final FtpsFileSystemConfigBuilder builder)
+	{
+		super.setupOptions(builder);
+		builder.setFtpsType(fileSystemOptions, FtpsFileSystemConfigBuilder.FTPS_TYPE_IMPLICIT);
+	}
+
 	/**
      * Creates the test suite for the ftps file system.
      */

Modified: commons/proper/vfs/trunk/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/pom.xml?rev=1448606&r1=1448605&r2=1448606&view=diff
==============================================================================
--- commons/proper/vfs/trunk/pom.xml (original)
+++ commons/proper/vfs/trunk/pom.xml Thu Feb 21 11:45:46 2013
@@ -121,6 +121,10 @@
       <name>Dave Marion</name>
       <email>dlmarion -at- apache.org</email>
     </contributor>    
+    <contributor>
+      <name>Jose Juan Montiel</name>
+      <email>josejuan.montiel -at- gmail.com</email>
+    </contributor>    
   </contributors>
 
   <properties>

Modified: commons/proper/vfs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1448606&r1=1448605&r2=1448606&view=diff
==============================================================================
--- commons/proper/vfs/trunk/src/changes/changes.xml (original)
+++ commons/proper/vfs/trunk/src/changes/changes.xml Thu Feb 21 11:45:46 2013
@@ -26,6 +26,9 @@
 <!--       <action issue="VFS-443" dev="ggregory" type="update" due-to="nickallen">
-->
 <!--     	[Local] Need an easy way to convert from a FileObject to a File. -->
 <!--       </action> -->
+      <action issue="VFS-412" dev="joehni" type="add" due-to="Jose Juan Montiel">
+        Add support for FTPS command to set the DataChannelProtectionLevel.
+      </action>
       <action issue="VFS-459" dev="joehni" type="update">
         Sent FTP/FTPS commands and the received answer is logged at debug level.
       </action>



Mime
View raw message