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 09:06:59 UTC
[1/2] git commit: CAMEL-6786 Added the AuthenticationPreemptive
option for the camel-http4 endpoint with thanks to Martin
Updated Branches:
refs/heads/camel-2.11.x 36acab20f -> fa4b5a8dd
refs/heads/camel-2.12.x 7b428956a -> 53d891565
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/53d89156
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/53d89156
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/53d89156
Branch: refs/heads/camel-2.12.x
Commit: 53d8915654b32071f08f0d487980f4a90767f4cb
Parents: 7b42895
Author: Willem Jiang <ni...@apache.org>
Authored: Wed Oct 30 15:56:12 2013 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Wed Oct 30 16:02:07 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/53d89156/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/53d89156/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/53d89156/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 {
[2/2] git commit: CAMEL-6786 Added the AuthenticationPreemptive
option for the camel-http4 endpoint with thanks to Martin
Posted by ni...@apache.org.
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/fa4b5a8d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/fa4b5a8d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/fa4b5a8d
Branch: refs/heads/camel-2.11.x
Commit: fa4b5a8dd975586c022ffae26daeb07bebc65caf
Parents: 36acab2
Author: Willem Jiang <ni...@apache.org>
Authored: Wed Oct 30 15:56:12 2013 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Wed Oct 30 16:04:56 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/fa4b5a8d/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 e63e380..98452d2 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/fa4b5a8d/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 91ba769..f45ce94 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/fa4b5a8d/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 {