You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2013/10/30 08:57:20 UTC
git commit: CAMEL-6786 Added the AuthenticationPreemptive option for
the camel-http4 endpoint with thanks to Martin
Updated Branches:
refs/heads/master 29e4411cf -> 26968c874
CAMEL-6786 Added the AuthenticationPreemptive option for the camel-http4 endpoint with thanks to Martin
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/26968c87
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/26968c87
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/26968c87
Branch: refs/heads/master
Commit: 26968c874d46c6d4d299dcd31ba00328feb5dd8b
Parents: 29e4411
Author: Willem Jiang <ni...@apache.org>
Authored: Wed Oct 30 15:56:12 2013 +0800
Committer: Willem Jiang <ni...@apache.org>
Committed: Wed Oct 30 15:56:12 2013 +0800
----------------------------------------------------------------------
.../org/apache/camel/component/http4/HttpEndpoint.java | 9 +++++++++
.../org/apache/camel/component/http4/HttpProducer.java | 7 +++++++
.../camel/component/http4/HttpAuthenticationTest.java | 11 +++++++++++
3 files changed, 27 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/26968c87/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java
index 0c9a355..c5086a3 100644
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java
+++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java
@@ -63,6 +63,7 @@ public class HttpEndpoint extends DefaultPollingEndpoint implements HeaderFilter
private boolean disableStreamCache;
private boolean transferException;
private boolean traceEnabled;
+ private boolean authenticationPreemptive;
private String httpMethodRestrict;
private UrlRewrite urlRewrite;
private boolean clearExpiredCookies = true;
@@ -374,4 +375,12 @@ public class HttpEndpoint extends DefaultPollingEndpoint implements HeaderFilter
public void setCookieStore(CookieStore cookieStore) {
this.cookieStore = cookieStore;
}
+
+ public boolean isAuthenticationPreemptive() {
+ return authenticationPreemptive;
+ }
+
+ public void setAuthenticationPreemptive(boolean authenticationPreemptive) {
+ this.authenticationPreemptive = authenticationPreemptive;
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/26968c87/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
index 6d95677..4d6f911 100644
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
+++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
@@ -49,6 +49,8 @@ import org.apache.camel.util.URISupport;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.Credentials;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpRequestBase;
@@ -58,6 +60,7 @@ import org.apache.http.entity.ContentType;
import org.apache.http.entity.FileEntity;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.protocol.HttpContext;
@@ -106,6 +109,10 @@ public class HttpProducer extends DefaultProducer {
exchange.getIn().getHeaders().remove("host");
}
HttpRequestBase httpRequest = createMethod(exchange);
+ if (getEndpoint().isAuthenticationPreemptive()) {
+ Credentials creds = ((DefaultHttpClient) httpClient).getCredentialsProvider().getCredentials(AuthScope.ANY);
+ httpRequest.addHeader(new BasicScheme().authenticate(creds, httpRequest));
+ }
Message in = exchange.getIn();
String httpProtocolVersion = in.getHeader(Exchange.HTTP_PROTOCOL_VERSION, String.class);
if (httpProtocolVersion != null) {
http://git-wip-us.apache.org/repos/asf/camel/blob/26968c87/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpAuthenticationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpAuthenticationTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpAuthenticationTest.java
index 4b31bb5..2d4c3de 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpAuthenticationTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpAuthenticationTest.java
@@ -48,6 +48,17 @@ public class HttpAuthenticationTest extends BaseHttpTest {
assertExchange(exchange);
}
+
+
+ @Test
+ public void basicAuthenticationPreemptive() throws Exception {
+ Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/search?authUsername=" + user + "&authPassword=" + password + "&preemptiveAuth=true", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ }
+ });
+
+ assertExchange(exchange);
+ }
@Test
public void basicAuthenticationShouldFailWithoutCreds() throws Exception {