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/12/09 09:21:35 UTC
git commit: CAMEL-7010 Added a missing file
Updated Branches:
refs/heads/master a4a3f6914 -> 65616ee43
CAMEL-7010 Added a missing file
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/65616ee4
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/65616ee4
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/65616ee4
Branch: refs/heads/master
Commit: 65616ee4365a96cf16a7dd5835a3ee4d3bc639b9
Parents: a4a3f69
Author: Willem Jiang <wi...@gmail.com>
Authored: Mon Dec 9 16:21:14 2013 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Mon Dec 9 16:21:25 2013 +0800
----------------------------------------------------------------------
.../http4/PreemptiveAuthInterceptor.java | 50 ++++++++++++++++++++
1 file changed, 50 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/65616ee4/components/camel-http4/src/main/java/org/apache/camel/component/http4/PreemptiveAuthInterceptor.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/PreemptiveAuthInterceptor.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/PreemptiveAuthInterceptor.java
new file mode 100644
index 0000000..1ae9d4b
--- /dev/null
+++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/PreemptiveAuthInterceptor.java
@@ -0,0 +1,50 @@
+/**
+ * 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.http4;
+
+import java.io.IOException;
+
+import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpRequestInterceptor;
+import org.apache.http.auth.AuthScheme;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.AuthState;
+import org.apache.http.auth.Credentials;
+import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.protocol.HttpContext;
+
+public class PreemptiveAuthInterceptor implements HttpRequestInterceptor {
+
+ public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
+ AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE);
+ // If no auth scheme avaialble yet, try to initialize it preemptively
+ if (authState.getAuthScheme() == null) {
+ AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth");
+ CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(HttpClientContext.CREDS_PROVIDER);
+ if (authScheme != null) {
+ Credentials creds = credsProvider.getCredentials(AuthScope.ANY);
+ if (creds == null) {
+ throw new HttpException("No credentials for preemptive authentication");
+ }
+ authState.update(authScheme, creds);
+ }
+ }
+
+ }
+}
\ No newline at end of file