camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1196954 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/impl/ main/java/org/apache/camel/util/ test/java/org/apache/camel/util/
Date Thu, 03 Nov 2011 06:10:32 GMT
Author: ningjiang
Date: Thu Nov  3 06:10:32 2011
New Revision: 1196954

URL: http://svn.apache.org/viewvc?rev=1196954&view=rev
Log:
CAMEL-4600  Improve URISupport.sanitizeUri and apply it in additional places with thanks to
João

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultConsumer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceManager.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/URISupport.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java?rev=1196954&r1=1196953&r2=1196954&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java Thu Nov
 3 06:10:32 2011
@@ -86,7 +86,7 @@ public abstract class DefaultComponent e
         validateURI(encodedUri, path, parameters);
 
         if (LOG.isDebugEnabled()) {
-            LOG.debug("Creating endpoint uri=[{}], path=[{}], parameters=[{}]", new Object[]{encodedUri,
path, parameters});
+            LOG.debug("Creating endpoint uri=[{}], path=[{}], parameters=[{}]", new Object[]{URISupport.sanitizeUri(encodedUri),
path, parameters});
         }
         Endpoint endpoint = createEndpoint(encodedUri, path, parameters);
         if (endpoint == null) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultConsumer.java?rev=1196954&r1=1196953&r2=1196954&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultConsumer.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultConsumer.java Thu Nov
 3 06:10:32 2011
@@ -24,6 +24,7 @@ import org.apache.camel.spi.ExceptionHan
 import org.apache.camel.support.ServiceSupport;
 import org.apache.camel.util.AsyncProcessorConverterHelper;
 import org.apache.camel.util.ServiceHelper;
+import org.apache.camel.util.URISupport;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -46,7 +47,7 @@ public class DefaultConsumer extends Ser
 
     @Override
     public String toString() {
-        return "Consumer[" + endpoint.getEndpointUri() + "]";
+        return "Consumer[" + URISupport.sanitizeUri(endpoint.getEndpointUri()) + "]";
     }
 
     public Endpoint getEndpoint() {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceManager.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceManager.java?rev=1196954&r1=1196953&r2=1196954&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceManager.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceManager.java
Thu Nov  3 06:10:32 2011
@@ -40,6 +40,7 @@ import org.apache.camel.spi.ThreadPoolFa
 import org.apache.camel.spi.ThreadPoolProfile;
 import org.apache.camel.support.ServiceSupport;
 import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.URISupport;
 import org.apache.camel.util.concurrent.CamelThreadFactory;
 import org.apache.camel.util.concurrent.ThreadHelper;
 import org.slf4j.Logger;
@@ -153,16 +154,17 @@ public class DefaultExecutorServiceManag
 
     @Override
     public ExecutorService newThreadPool(Object source, String name, ThreadPoolProfile profile)
{
+        String sanitizedName = URISupport.sanitizeUri(name);
         ObjectHelper.notNull(profile, "ThreadPoolProfile");
 
         ThreadPoolProfile defaultProfile = getDefaultThreadPoolProfile();
         profile.addDefaults(defaultProfile);
 
-        ThreadFactory threadFactory = createThreadFactory(name, true);
+        ThreadFactory threadFactory = createThreadFactory(sanitizedName, true);
         ExecutorService executorService = threadPoolFactory.newThreadPool(profile, threadFactory);
         onThreadPoolCreated(executorService, source, profile.getId());
         if (LOG.isDebugEnabled()) {
-            LOG.debug("Created new ThreadPool for source: {} with name: {}. -> {}", new
Object[]{source, name, executorService});
+            LOG.debug("Created new ThreadPool for source: {} with name: {}. -> {}", new
Object[]{source, sanitizedName, executorService});
         }
 
         return executorService;
@@ -183,11 +185,12 @@ public class DefaultExecutorServiceManag
 
     @Override
     public ExecutorService newCachedThreadPool(Object source, String name) {
-        ExecutorService answer = threadPoolFactory.newCachedThreadPool(createThreadFactory(name,
true));
+        String sanitizedName = URISupport.sanitizeUri(name);
+        ExecutorService answer = threadPoolFactory.newCachedThreadPool(createThreadFactory(sanitizedName,
true));
         onThreadPoolCreated(answer, source, null);
 
         if (LOG.isDebugEnabled()) {
-            LOG.debug("Created new CachedThreadPool for source: {} with name: {}. -> {}",
new Object[]{source, name, answer});
+            LOG.debug("Created new CachedThreadPool for source: {} with name: {}. -> {}",
new Object[]{source, sanitizedName, answer});
         }
         return answer;
     }
@@ -208,12 +211,13 @@ public class DefaultExecutorServiceManag
     
     @Override
     public ScheduledExecutorService newScheduledThreadPool(Object source, String name, ThreadPoolProfile
profile) {
+        String sanitizedName = URISupport.sanitizeUri(name);
         profile.addDefaults(getDefaultThreadPoolProfile());
-        ScheduledExecutorService answer = threadPoolFactory.newScheduledThreadPool(profile,
createThreadFactory(name, true));
+        ScheduledExecutorService answer = threadPoolFactory.newScheduledThreadPool(profile,
createThreadFactory(sanitizedName, true));
         onThreadPoolCreated(answer, source, null);
 
         if (LOG.isDebugEnabled()) {
-            LOG.debug("Created new ScheduledThreadPool for source: {} with name: {}. ->
{}", new Object[]{source, name, answer});
+            LOG.debug("Created new ScheduledThreadPool for source: {} with name: {}. ->
{}", new Object[]{source, sanitizedName, answer});
         }
         return answer;
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/URISupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/URISupport.java?rev=1196954&r1=1196953&r2=1196954&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/URISupport.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/URISupport.java Thu Nov  3
06:10:32 2011
@@ -41,6 +41,11 @@ public final class URISupport {
     // First capture group is the key, second is the value.
     private static final Pattern SECRETS = Pattern.compile("([?&][^=]*(?:passphrase|password|secretKey)[^=]*)=([^&]*)",
             Pattern.CASE_INSENSITIVE);
+    
+    // Match the user password in the URI as second capture group
+    // (applies to URI with authority component and userinfo token in the form "user:password").
+    private static final Pattern USERINFO_PASSWORD = Pattern.compile("(.*://.*:)(.*)(@)");
+    
     private static final String CHARSET = "UTF-8";
 
     private URISupport() {
@@ -55,7 +60,12 @@ public final class URISupport {
      * @return Returns null if the uri is null, otherwise the URI with the passphrase, password
or secretKey sanitized.
      */
     public static String sanitizeUri(String uri) {
-        return uri == null ? null : SECRETS.matcher(uri).replaceAll("$1=******");
+        String sanitized = uri;
+        if (uri != null) {
+            sanitized = SECRETS.matcher(sanitized).replaceAll("$1=******");
+            sanitized = USERINFO_PASSWORD.matcher(sanitized).replaceFirst("$1******$3");
+        }
+        return sanitized;
     }
 
     public static Map<String, Object> parseQuery(String uri) throws URISyntaxException
{

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java?rev=1196954&r1=1196953&r2=1196954&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java Thu Nov
 3 06:10:32 2011
@@ -150,5 +150,11 @@ public class URISupportTest extends Cont
         String out2 = URISupport.normalizeUri("smtp://localhost?to=foo&to=bar&from=me&from=you");
         assertEquals("smtp://localhost?from=me&from=you&to=foo&to=bar", out2);
     }
+    
+    public void testSanitizeUriWithUserInfo() {
+    	String uri      = "jt400://GEORGE:HARRISON@LIVERPOOL/QSYS.LIB/BEATLES.LIB/PENNYLANE.DTAQ";
+    	String expected = "jt400://GEORGE:******@LIVERPOOL/QSYS.LIB/BEATLES.LIB/PENNYLANE.DTAQ";
+    	assertEquals(expected, URISupport.sanitizeUri(uri));
+    }
 
 }



Mime
View raw message