You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by jo...@apache.org on 2013/02/21 10:25:37 UTC

svn commit: r1448560 - in /commons/proper/vfs/trunk: core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java src/changes/changes.xml

Author: joehni
Date: Thu Feb 21 09:25:37 2013
New Revision: 1448560

URL: http://svn.apache.org/r1448560
Log:
Sent FTP/FTPS commands and the received answer is logged at debug level (VFS-459).

Modified:
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java
    commons/proper/vfs/trunk/src/changes/changes.xml

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=1448560&r1=1448559&r2=1448560&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 09:25:37 2013
@@ -17,7 +17,13 @@
 package org.apache.commons.vfs2.provider.ftp;
 
 import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.Writer;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.net.PrintCommandListener;
 import org.apache.commons.net.ftp.FTPClient;
 import org.apache.commons.net.ftp.FTPClientConfig;
 import org.apache.commons.net.ftp.FTPReply;
@@ -72,6 +78,7 @@ public final class FtpClientFactory
         private static final char[] ANON_CHAR_ARRAY = "anonymous".toCharArray();
     	private static final int BUFSZ = 40;
 
+    	protected Log log = LogFactory.getLog(getClass());
     	protected B builder;
 
         protected ConnectionFactory(B builder)
@@ -97,6 +104,23 @@ public final class FtpClientFactory
 	        {
 	            final C client = createClient(fileSystemOptions);
 	
+	            if (log.isDebugEnabled()) {
+					final Writer writer = new StringWriter(1024){
+						@Override
+						public void flush()
+						{
+							final StringBuffer buffer = getBuffer();
+							String message = buffer.toString();
+							if (message.toUpperCase().startsWith("PASS ") && message.length() > 5) {
+								message = "PASS ***";
+							}
+							log.debug(message);
+							buffer.setLength(0);
+						}
+	            	};
+	            	client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(writer)));
+	            }
+	            
 	            configureClient(fileSystemOptions, client);
 	
 				final FTPFileEntryParserFactory myFactory =

Modified: commons/proper/vfs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1448560&r1=1448559&r2=1448560&view=diff
==============================================================================
--- commons/proper/vfs/trunk/src/changes/changes.xml (original)
+++ commons/proper/vfs/trunk/src/changes/changes.xml Thu Feb 21 09:25:37 2013
@@ -26,7 +26,10 @@
 <!--       <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-458" dev="jos" type="fix">
+      <action issue="VFS-459" dev="joehni" type="update">
+        Sent FTP/FTPS commands and the received answer is logged at debug level.
+      </action>
+      <action issue="VFS-458" dev="joehni" type="fix">
         FTPS provider missed functionality and bug fixes already available for the FTP provider.
       </action>
       <action issue="VFS-452" dev="ggregory" type="fix" due-to="Jean-Marc Borer">



Re: svn commit: r1448560 - in /commons/proper/vfs/trunk: core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java src/changes/changes.xml

Posted by Jörg Schaible <Jo...@scalaris.com>.
Hi Sebb,

sebb wrote:

> On 21 February 2013 09:25,  <jo...@apache.org> wrote:
>> Author: joehni
>> Date: Thu Feb 21 09:25:37 2013
>> New Revision: 1448560
>>
>> URL: http://svn.apache.org/r1448560
>> Log:
>> Sent FTP/FTPS commands and the received answer is logged at debug level
>> (VFS-459).

[snip]

>> @@ -97,6 +104,23 @@ public final class FtpClientFactory
>>                 {
>>                     final C client = createClient(fileSystemOptions);
>>
>> +                   if (log.isDebugEnabled()) {
>> +                                       final Writer writer = new
>> StringWriter(1024){
>> +                                               @Override
>> +                                               public void flush()
>> +                                               {
>> +                                                       final
>> StringBuffer buffer = getBuffer();
>> +                                                       String message =
>> buffer.toString();
>> +                                                       if
>> (message.toUpperCase().startsWith("PASS ") && message.length() > 5) {
>> +                                                               message =
>> "PASS ***";
>> +                                                       }
>> +                                                      
>> log.debug(message);
>> +                                                      
>> buffer.setLength(0);
>> +                                               }
>> +                       };
>> +                       client.addProtocolCommandListener(new
>> PrintCommandListener(new PrintWriter(writer)));
> 
> Why not use the built-in login suppression facility?
> 
> client.addProtocolCommandListener(new PrintCommandListener(new
> PrintWriter(writer), true));

Because the built-in login suppression hides password AND user.

> Also, AFAICT the obfuscation only applies to messages which happen to
> have the PASS command at the start of a buffer when flush is called.

Yes, but that's the case. The PrintWriter flushes for each line and the 
implementation above clears the buffer after each line.

Cheers,
Jörg


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1448560 - in /commons/proper/vfs/trunk: core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java src/changes/changes.xml

Posted by sebb <se...@gmail.com>.
On 21 February 2013 09:25,  <jo...@apache.org> wrote:
> Author: joehni
> Date: Thu Feb 21 09:25:37 2013
> New Revision: 1448560
>
> URL: http://svn.apache.org/r1448560
> Log:
> Sent FTP/FTPS commands and the received answer is logged at debug level (VFS-459).
>
> Modified:
>     commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java
>     commons/proper/vfs/trunk/src/changes/changes.xml
>
> 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=1448560&r1=1448559&r2=1448560&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 09:25:37 2013
> @@ -17,7 +17,13 @@
>  package org.apache.commons.vfs2.provider.ftp;
>
>  import java.io.IOException;
> +import java.io.PrintWriter;
> +import java.io.StringWriter;
> +import java.io.Writer;
>
> +import org.apache.commons.logging.Log;
> +import org.apache.commons.logging.LogFactory;
> +import org.apache.commons.net.PrintCommandListener;
>  import org.apache.commons.net.ftp.FTPClient;
>  import org.apache.commons.net.ftp.FTPClientConfig;
>  import org.apache.commons.net.ftp.FTPReply;
> @@ -72,6 +78,7 @@ public final class FtpClientFactory
>          private static final char[] ANON_CHAR_ARRAY = "anonymous".toCharArray();
>         private static final int BUFSZ = 40;
>
> +       protected Log log = LogFactory.getLog(getClass());
>         protected B builder;
>
>          protected ConnectionFactory(B builder)
> @@ -97,6 +104,23 @@ public final class FtpClientFactory
>                 {
>                     final C client = createClient(fileSystemOptions);
>
> +                   if (log.isDebugEnabled()) {
> +                                       final Writer writer = new StringWriter(1024){
> +                                               @Override
> +                                               public void flush()
> +                                               {
> +                                                       final StringBuffer buffer = getBuffer();
> +                                                       String message = buffer.toString();
> +                                                       if (message.toUpperCase().startsWith("PASS ") && message.length() > 5) {
> +                                                               message = "PASS ***";
> +                                                       }
> +                                                       log.debug(message);
> +                                                       buffer.setLength(0);
> +                                               }
> +                       };
> +                       client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(writer)));

Why not use the built-in login suppression facility?

client.addProtocolCommandListener(new PrintCommandListener(new
PrintWriter(writer), true));

Also, AFAICT the obfuscation only applies to messages which happen to
have the PASS command at the start of a buffer when flush is called.

> +                   }
> +
>                     configureClient(fileSystemOptions, client);
>
>                                 final FTPFileEntryParserFactory myFactory =
>
> Modified: commons/proper/vfs/trunk/src/changes/changes.xml
> URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1448560&r1=1448559&r2=1448560&view=diff
> ==============================================================================
> --- commons/proper/vfs/trunk/src/changes/changes.xml (original)
> +++ commons/proper/vfs/trunk/src/changes/changes.xml Thu Feb 21 09:25:37 2013
> @@ -26,7 +26,10 @@
>  <!--       <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-458" dev="jos" type="fix">
> +      <action issue="VFS-459" dev="joehni" type="update">
> +        Sent FTP/FTPS commands and the received answer is logged at debug level.
> +      </action>
> +      <action issue="VFS-458" dev="joehni" type="fix">
>          FTPS provider missed functionality and bug fixes already available for the FTP provider.
>        </action>
>        <action issue="VFS-452" dev="ggregory" type="fix" due-to="Jean-Marc Borer">
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org