camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r934334 - in /camel/trunk/components: camel-http/src/main/java/org/apache/camel/component/http/ camel-http/src/test/java/org/apache/camel/component/http/ camel-jetty/src/test/java/org/apache/camel/component/jetty/
Date Thu, 15 Apr 2010 09:04:00 GMT
Author: davsclaus
Date: Thu Apr 15 09:04:00 2010
New Revision: 934334

URL: http://svn.apache.org/viewvc?rev=934334&view=rev
Log:
CAMEL-2645: Added authMethodPriority option to camel-http.

Added:
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/NTLMAuthenticationHttpClientConfigurer.java
  (contents, props changed)
      - copied, changed from r934296, camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/NTMLAuthenticationHttpClientConfigurer.java
    camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpAuthMethodPriorityTest.java
      - copied, changed from r934296, camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyAuthBasicTest.java
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpAuthMethodPriorityTest.java
      - copied, changed from r934296, camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBasicAuthTest.java
Removed:
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/NTMLAuthenticationHttpClientConfigurer.java
Modified:
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/AuthMethod.java
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConfiguration.java
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
    camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyAuthNTLMTest.java

Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/AuthMethod.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/AuthMethod.java?rev=934334&r1=934333&r2=934334&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/AuthMethod.java
(original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/AuthMethod.java
Thu Apr 15 09:04:00 2010
@@ -1,3 +1,19 @@
+/**
+ * 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.camel.component.http;
 
 /**
@@ -7,5 +23,5 @@ package org.apache.camel.component.http;
  */
 public enum AuthMethod {
 
-    Basic, Digest, NTML;
+    Basic, Digest, NTLM;
 }

Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java?rev=934334&r1=934333&r2=934334&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
(original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
Thu Apr 15 09:04:00 2010
@@ -133,11 +133,11 @@ public class HttpComponent extends Heade
         if (authMethod == AuthMethod.Basic || authMethod == AuthMethod.Digest) {
             return CompositeHttpConfigurer.combineConfigurers(configurer,
                     new BasicAuthenticationHttpClientConfigurer(false, username, password));
-        } else if (authMethod == AuthMethod.NTML) {
+        } else if (authMethod == AuthMethod.NTLM) {
             // domain is mandatory for NTML
             ObjectHelper.notNull(domain, "authDomain");
             return CompositeHttpConfigurer.combineConfigurers(configurer,
-                    new NTMLAuthenticationHttpClientConfigurer(false, username, password,
domain, host));
+                    new NTLMAuthenticationHttpClientConfigurer(false, username, password,
domain, host));
         }
 
         throw new IllegalArgumentException("Unknown authMethod " + authMethod);
@@ -159,11 +159,11 @@ public class HttpComponent extends Heade
         if (authMethod == AuthMethod.Basic || authMethod == AuthMethod.Digest) {
             return CompositeHttpConfigurer.combineConfigurers(configurer,
                     new BasicAuthenticationHttpClientConfigurer(true, username, password));
-        } else if (authMethod == AuthMethod.NTML) {
+        } else if (authMethod == AuthMethod.NTLM) {
             // domain is mandatory for NTML
             ObjectHelper.notNull(domain, "proxyAuthDomain");
             return CompositeHttpConfigurer.combineConfigurers(configurer,
-                    new NTMLAuthenticationHttpClientConfigurer(true, username, password,
domain, host));
+                    new NTLMAuthenticationHttpClientConfigurer(true, username, password,
domain, host));
         }
 
         throw new IllegalArgumentException("Unknown proxyAuthMethod " + authMethod);
@@ -183,6 +183,7 @@ public class HttpComponent extends Heade
         Boolean matchOnUriPrefix = getAndRemoveParameter(parameters, "matchOnUriPrefix",
Boolean.class);
         String proxyHost = getAndRemoveParameter(parameters, "proxyHost", String.class);
         Integer proxyPort = getAndRemoveParameter(parameters, "proxyPort", Integer.class);
+        String authMethodPriority = getAndRemoveParameter(parameters, "authMethodPriority",
String.class);
         // http client can be configured from URI options
         HttpClientParams clientParams = new HttpClientParams();
         IntrospectionSupport.setProperties(clientParams, parameters, "httpClient.");
@@ -235,6 +236,11 @@ public class HttpComponent extends Heade
             endpoint.setProxyHost(httpConfiguration.getProxyHost());
             endpoint.setProxyPort(httpConfiguration.getProxyPort());
         }
+        if (authMethodPriority != null) {
+            endpoint.setAuthMethodPriority(authMethodPriority);
+        } else if (httpConfiguration != null) {
+            endpoint.setAuthMethodPriority(httpConfiguration.getAuthMethodPriority());
+        }
 
         setProperties(endpoint, parameters);
         return endpoint;

Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConfiguration.java?rev=934334&r1=934333&r2=934334&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConfiguration.java
(original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpConfiguration.java
Thu Apr 15 09:04:00 2010
@@ -37,6 +37,7 @@ public class HttpConfiguration implement
 
     private String proxyHost;
     private int proxyPort;
+    private String authMethodPriority;
 
     public String getAuthUsername() {
         return authUsername;
@@ -133,4 +134,12 @@ public class HttpConfiguration implement
     public void setProxyPort(int proxyPort) {
         this.proxyPort = proxyPort;
     }
+
+    public String getAuthMethodPriority() {
+        return authMethodPriority;
+    }
+
+    public void setAuthMethodPriority(String authMethodPriority) {
+        this.authMethodPriority = authMethodPriority;
+    }
 }

Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java?rev=934334&r1=934333&r2=934334&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
(original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
Thu Apr 15 09:04:00 2010
@@ -18,6 +18,10 @@ package org.apache.camel.component.http;
 
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
 import org.apache.camel.PollingConsumer;
 import org.apache.camel.Producer;
 import org.apache.camel.impl.DefaultPollingEndpoint;
@@ -26,6 +30,7 @@ import org.apache.camel.spi.HeaderFilter
 import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpConnectionManager;
+import org.apache.commons.httpclient.auth.AuthPolicy;
 import org.apache.commons.httpclient.params.HttpClientParams;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -51,6 +56,7 @@ public class HttpEndpoint extends Defaul
     private boolean chunked = true;
     private String proxyHost;
     private int proxyPort;
+    private String authMethodPriority;
 
     public HttpEndpoint() {
     }
@@ -108,6 +114,27 @@ public class HttpEndpoint extends Defaul
             answer.getHostConfiguration().setProxy(proxyHost, proxyPort);
         }
 
+        if (authMethodPriority != null) {
+            List<String> authPrefs = new ArrayList<String>();
+            Iterator it = getCamelContext().getTypeConverter().convertTo(Iterator.class,
authMethodPriority);
+            int i = 1;
+            while (it.hasNext()) {
+                Object value = it.next();
+                AuthMethod auth = getCamelContext().getTypeConverter().convertTo(AuthMethod.class,
value);
+                if (auth == null) {
+                    throw new IllegalArgumentException("Unknown authMethod: " + value + "
in authMethodPriority: " + authMethodPriority);
+                }
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Using authSchemePriority #" + i + ": " + auth);
+                }
+                authPrefs.add(auth.name());
+                i++;
+            }
+            if (!authPrefs.isEmpty()) {
+                answer.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
+            }
+        }
+
         answer.setHttpConnectionManager(httpConnectionManager);
         HttpClientConfigurer configurer = getHttpClientConfigurer();
         if (configurer != null) {
@@ -268,4 +295,12 @@ public class HttpEndpoint extends Defaul
     public void setProxyPort(int proxyPort) {
         this.proxyPort = proxyPort;
     }
+
+    public String getAuthMethodPriority() {
+        return authMethodPriority;
+    }
+
+    public void setAuthMethodPriority(String authMethodPriority) {
+        this.authMethodPriority = authMethodPriority;
+    }
 }

Copied: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/NTLMAuthenticationHttpClientConfigurer.java
(from r934296, camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/NTMLAuthenticationHttpClientConfigurer.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/NTLMAuthenticationHttpClientConfigurer.java?p2=camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/NTLMAuthenticationHttpClientConfigurer.java&p1=camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/NTMLAuthenticationHttpClientConfigurer.java&r1=934296&r2=934334&rev=934334&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/NTMLAuthenticationHttpClientConfigurer.java
(original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/NTLMAuthenticationHttpClientConfigurer.java
Thu Apr 15 09:04:00 2010
@@ -21,14 +21,14 @@ import org.apache.commons.httpclient.Htt
 import org.apache.commons.httpclient.NTCredentials;
 import org.apache.commons.httpclient.auth.AuthScope;
 
-public class NTMLAuthenticationHttpClientConfigurer implements HttpClientConfigurer {
+public class NTLMAuthenticationHttpClientConfigurer implements HttpClientConfigurer {
     private final boolean proxy;
     private final String username;
     private final String password;
     private final String domain;
     private final String host;
 
-    public NTMLAuthenticationHttpClientConfigurer(boolean proxy, String user, String pwd,
String domain, String host) {
+    public NTLMAuthenticationHttpClientConfigurer(boolean proxy, String user, String pwd,
String domain, String host) {
         this.proxy = proxy;
         this.username = user;
         this.password = pwd;

Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/NTLMAuthenticationHttpClientConfigurer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/NTLMAuthenticationHttpClientConfigurer.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpAuthMethodPriorityTest.java
(from r934296, camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyAuthBasicTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpAuthMethodPriorityTest.java?p2=camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpAuthMethodPriorityTest.java&p1=camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyAuthBasicTest.java&r1=934296&r2=934334&rev=934334&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyAuthBasicTest.java
(original)
+++ camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpAuthMethodPriorityTest.java
Thu Apr 15 09:04:00 2010
@@ -23,10 +23,10 @@ import org.junit.Test;
 /**
  * @version $Revision: 905992 $
  */
-public class HttpProxyAuthBasicTest extends CamelTestSupport {
+public class HttpAuthMethodPriorityTest extends CamelTestSupport {
 
     @Test
-    public void testProxyAuthBasic() throws Exception {
+    public void testAuthMethodPriority() throws Exception {
         HttpClientConfigurer configurer = getMandatoryEndpoint("http://www.google.com/search",
HttpEndpoint.class).getHttpClientConfigurer();
         assertNotNull(configurer);
 
@@ -34,7 +34,7 @@ public class HttpProxyAuthBasicTest exte
         assertEquals(1, comp.getConfigurers().size());
 
         BasicAuthenticationHttpClientConfigurer basic = assertIsInstanceOf(BasicAuthenticationHttpClientConfigurer.class,
comp.getConfigurers().get(0));
-        assertTrue(basic.isProxy());
+        assertFalse(basic.isProxy());
         assertEquals("myUser", basic.getUsername());
         assertEquals("myPassword", basic.getPassword());
     }
@@ -45,12 +45,11 @@ public class HttpProxyAuthBasicTest exte
             public void configure() {
                 // setup proxy details
                 HttpConfiguration config = new HttpConfiguration();
-                config.setProxyHost("myProxyHosy");
-                config.setProxyPort(1234);
-                // proxy requires auth as well
-                config.setProxyAuthMethod(AuthMethod.Basic);
-                config.setProxyAuthUsername("myUser");
-                config.setProxyAuthPassword("myPassword");
+                config.setAuthMethod(AuthMethod.Basic);
+                config.setAuthUsername("myUser");
+                config.setAuthPassword("myPassword");
+                // to avoid NTLM
+                config.setAuthMethodPriority("Basic,Digest");
 
                 HttpComponent http = context.getComponent("http", HttpComponent.class);
                 http.setHttpConfiguration(config);
@@ -60,4 +59,4 @@ public class HttpProxyAuthBasicTest exte
             }
         };
     }
-}
+}
\ No newline at end of file

Modified: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyAuthNTLMTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyAuthNTLMTest.java?rev=934334&r1=934333&r2=934334&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyAuthNTLMTest.java
(original)
+++ camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyAuthNTLMTest.java
Thu Apr 15 09:04:00 2010
@@ -33,7 +33,7 @@ public class HttpProxyAuthNTLMTest exten
         CompositeHttpConfigurer comp = assertIsInstanceOf(CompositeHttpConfigurer.class,
configurer);
         assertEquals(1, comp.getConfigurers().size());
 
-        NTMLAuthenticationHttpClientConfigurer ntlm = assertIsInstanceOf(NTMLAuthenticationHttpClientConfigurer.class,
comp.getConfigurers().get(0));
+        NTLMAuthenticationHttpClientConfigurer ntlm = assertIsInstanceOf(NTLMAuthenticationHttpClientConfigurer.class,
comp.getConfigurers().get(0));
         assertTrue(ntlm.isProxy());
         assertEquals("myUser", ntlm.getUsername());
         assertEquals("myPassword", ntlm.getPassword());
@@ -50,7 +50,7 @@ public class HttpProxyAuthNTLMTest exten
                 config.setProxyHost("myProxyHosy");
                 config.setProxyPort(1234);
 
-                config.setProxyAuthMethod(AuthMethod.NTML);
+                config.setProxyAuthMethod(AuthMethod.NTLM);
                 config.setProxyAuthUsername("myUser");
                 config.setProxyAuthPassword("myPassword");
                 config.setProxyAuthDomain("myDomain");

Copied: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpAuthMethodPriorityTest.java
(from r934296, camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBasicAuthTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpAuthMethodPriorityTest.java?p2=camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpAuthMethodPriorityTest.java&p1=camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBasicAuthTest.java&r1=934296&r2=934334&rev=934334&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBasicAuthTest.java
(original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpAuthMethodPriorityTest.java
Thu Apr 15 09:04:00 2010
@@ -18,10 +18,10 @@ package org.apache.camel.component.jetty
 
 import java.io.IOException;
 import java.security.Principal;
-
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.camel.Exchange;
+import org.apache.camel.FailedToCreateProducerException;
 import org.apache.camel.Processor;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.builder.RouteBuilder;
@@ -39,7 +39,7 @@ import org.junit.Test;
 /**
  * @version $Revision$
  */
-public class HttpBasicAuthTest extends CamelTestSupport {
+public class HttpAuthMethodPriorityTest extends CamelTestSupport {
 
     @Override
     protected JndiRegistry createRegistry() throws Exception {
@@ -59,7 +59,7 @@ public class HttpBasicAuthTest extends C
         ConstraintSecurityHandler sh = new ConstraintSecurityHandler();
         sh.setAuthenticator(new BasicAuthenticator());
         sh.setConstraintMappings(new ConstraintMapping[] {cm});
-        
+
         HashLoginService loginService = new HashLoginService("MyRealm", "src/test/resources/myRealm.properties");
         sh.setLoginService(loginService);
         sh.setConstraintMappings(new ConstraintMapping[]{cm});
@@ -68,15 +68,32 @@ public class HttpBasicAuthTest extends C
     }
 
     @Test
-    public void testHttpBaiscAuth() throws Exception {
-        String out = template.requestBody("http://localhost:9080/test?authMethod=Basic&authUsername=donald&authPassword=duck",
"Hello World", String.class);
+    public void testAuthMethodPriorityBasicDigest() throws Exception {
+        String out = template.requestBody("http://localhost:9080/test?authMethod=Basic&authMethodPriority=Basic,Digest&authUsername=donald&authPassword=duck",
"Hello World", String.class);
+        assertEquals("Bye World", out);
+    }
+
+    @Test
+    public void testAuthMethodPriorityNTLMBasic() throws Exception {
+        String out = template.requestBody("http://localhost:9080/test?authMethod=Basic&authMethodPriority=NTLM,Basic&authUsername=donald&authPassword=duck",
"Hello World", String.class);
         assertEquals("Bye World", out);
     }
 
     @Test
-    public void testHttpBaiscAuthInvalidPassword() throws Exception {
+    public void testAuthMethodPriorityInvalid() throws Exception {
+        try {
+            template.requestBody("http://localhost:9080/test?authMethod=Basic&authMethodPriority=Basic,foo&authUsername=donald&authPassword=duck",
"Hello World", String.class);
+            fail("Should have thrown an exception");
+        } catch (FailedToCreateProducerException e) {
+            IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class,
e.getCause());
+            assertEquals("Unknown authMethod: foo in authMethodPriority: Basic,foo", cause.getMessage());
+        }
+    }
+
+    @Test
+    public void testAuthMethodPriorityNTLM() throws Exception {
         try {
-            template.requestBody("http://localhost:9080/test?authMethod=Basic&authUsername=donald&authPassword=sorry",
"Hello World", String.class);
+            template.requestBody("http://localhost:9080/test?authMethod=Basic&authMethodPriority=NTLM&authUsername=donald&authPassword=duck",
"Hello World", String.class);
         } catch (RuntimeCamelException e) {
             HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class,
e.getCause());
             assertEquals(401, cause.getStatusCode());
@@ -102,4 +119,4 @@ public class HttpBasicAuthTest extends C
             }
         };
     }
-}
+}
\ No newline at end of file



Mime
View raw message