hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1235752 - in /httpcomponents/httpclient/trunk: fluent-hc/src/main/java/org/apache/http/client/fluent/ httpclient/src/main/java/org/apache/http/auth/ httpclient/src/main/java/org/apache/http/impl/auth/
Date Wed, 25 Jan 2012 14:17:38 GMT
Author: olegk
Date: Wed Jan 25 14:17:37 2012
New Revision: 1235752

URL: http://svn.apache.org/viewvc?rev=1235752&view=rev
Log:
Added an option to initalize BASIC and DIGEST schemes in a particular challenge state

Added:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/ChallengeState.java
  (with props)
Modified:
    httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/AuthSchemeBase.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/BasicScheme.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/DigestScheme.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java

Modified: httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java?rev=1235752&r1=1235751&r2=1235752&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java
(original)
+++ httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java
Wed Jan 25 14:17:37 2012
@@ -30,6 +30,7 @@ import java.io.IOException;
 
 import org.apache.http.HttpHost;
 import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.ChallengeState;
 import org.apache.http.auth.Credentials;
 import org.apache.http.auth.NTCredentials;
 import org.apache.http.auth.UsernamePasswordCredentials;
@@ -88,7 +89,12 @@ public class Executor {
     }
 
     public Executor authPreemptive(final HttpHost host) {
-        this.authCache.put(host, new BasicScheme());
+        this.authCache.put(host, new BasicScheme(ChallengeState.TARGET));
+        return this;
+    }
+
+    public Executor authPreemptiveProxy(final HttpHost host) {
+        this.authCache.put(host, new BasicScheme(ChallengeState.PROXY));
         return this;
     }
 

Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/ChallengeState.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/ChallengeState.java?rev=1235752&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/ChallengeState.java
(added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/ChallengeState.java
Wed Jan 25 14:17:37 2012
@@ -0,0 +1,37 @@
+/*
+ * ====================================================================
+ *
+ *  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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+package org.apache.http.auth;
+
+/**
+ * Challenge mode (TARGET or PROXY)
+ *
+ * @since 4.2
+ */
+public enum ChallengeState {
+
+    TARGET, PROXY
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/ChallengeState.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/ChallengeState.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/ChallengeState.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/ChallengeState.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/AuthSchemeBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/AuthSchemeBase.java?rev=1235752&r1=1235751&r2=1235752&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/AuthSchemeBase.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/AuthSchemeBase.java
Wed Jan 25 14:17:37 2012
@@ -35,6 +35,7 @@ import org.apache.http.Header;
 import org.apache.http.HttpRequest;
 import org.apache.http.auth.AUTH;
 import org.apache.http.auth.AuthenticationException;
+import org.apache.http.auth.ChallengeState;
 import org.apache.http.auth.ContextAwareAuthScheme;
 import org.apache.http.auth.Credentials;
 import org.apache.http.auth.MalformedChallengeException;
@@ -52,16 +53,24 @@ import org.apache.http.util.CharArrayBuf
  *
  * @since 4.0
  */
-@NotThreadSafe // proxy
+@NotThreadSafe
 public abstract class AuthSchemeBase implements ContextAwareAuthScheme {
 
+    private ChallengeState challengeState;
+
     /**
-     * Flag whether authenticating against a proxy.
+     * Creates an instance of <tt>AuthSchemeBase</tt> with the given challenge
+     * state.
+     *
+     * @since 4.2
      */
-    private boolean proxy;
+    public AuthSchemeBase(final ChallengeState challengeState) {
+        super();
+        this.challengeState = challengeState;
+    }
 
     public AuthSchemeBase() {
-        super();
+        this(null);
     }
 
     /**
@@ -80,9 +89,9 @@ public abstract class AuthSchemeBase imp
         }
         String authheader = header.getName();
         if (authheader.equalsIgnoreCase(AUTH.WWW_AUTH)) {
-            this.proxy = false;
+            this.challengeState = ChallengeState.TARGET;
         } else if (authheader.equalsIgnoreCase(AUTH.PROXY_AUTH)) {
-            this.proxy = true;
+            this.challengeState = ChallengeState.PROXY;
         } else {
             throw new MalformedChallengeException("Unexpected header name: " + authheader);
         }
@@ -132,12 +141,18 @@ public abstract class AuthSchemeBase imp
     /**
      * Returns <code>true</code> if authenticating against a proxy, <code>false</code>
      * otherwise.
-     *
-     * @return <code>true</code> if authenticating against a proxy, <code>false</code>
-     * otherwise
      */
     public boolean isProxy() {
-        return this.proxy;
+        return this.challengeState != null && this.challengeState == ChallengeState.PROXY;
+    }
+
+    /**
+     * Returns {@link ChallengeState} value or <code>null</code> if unchallenged.
+     *
+     * @since 4.2
+     */
+    public ChallengeState getChallengeState() {
+        return this.challengeState;
     }
 
     @Override

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/BasicScheme.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/BasicScheme.java?rev=1235752&r1=1235751&r2=1235752&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/BasicScheme.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/BasicScheme.java
Wed Jan 25 14:17:37 2012
@@ -32,6 +32,7 @@ import org.apache.commons.codec.binary.B
 import org.apache.http.Header;
 import org.apache.http.HttpRequest;
 import org.apache.http.auth.AuthenticationException;
+import org.apache.http.auth.ChallengeState;
 import org.apache.http.auth.Credentials;
 import org.apache.http.auth.AUTH;
 import org.apache.http.auth.InvalidCredentialsException;
@@ -61,13 +62,20 @@ public class BasicScheme extends RFC2617
     private boolean complete;
 
     /**
-     * Default constructor for the basic authentication scheme.
+     * Creates an instance of <tt>BasicScheme</tt> with the given challenge
+     * state.
+     *
+     * @since 4.2
      */
-    public BasicScheme() {
-        super();
+    public BasicScheme(final ChallengeState challengeState) {
+        super(challengeState);
         this.complete = false;
     }
 
+    public BasicScheme() {
+        this(null);
+    }
+
     /**
      * Returns textual designation of the basic authentication scheme.
      *

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/DigestScheme.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/DigestScheme.java?rev=1235752&r1=1235751&r2=1235752&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/DigestScheme.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/DigestScheme.java
Wed Jan 25 14:17:37 2012
@@ -44,6 +44,7 @@ import org.apache.http.HttpEntity;
 import org.apache.http.HttpEntityEnclosingRequest;
 import org.apache.http.HttpRequest;
 import org.apache.http.auth.AuthenticationException;
+import org.apache.http.auth.ChallengeState;
 import org.apache.http.auth.Credentials;
 import org.apache.http.auth.AUTH;
 import org.apache.http.auth.MalformedChallengeException;
@@ -110,13 +111,20 @@ public class DigestScheme extends RFC261
     private String a2;
 
     /**
-     * Default constructor for the digest authetication scheme.
+     * Creates an instance of <tt>DigestScheme</tt> with the given challenge
+     * state.
+     *
+     * @since 4.2
      */
-    public DigestScheme() {
-        super();
+    public DigestScheme(final ChallengeState challengeState) {
+        super(challengeState);
         this.complete = false;
     }
 
+    public DigestScheme() {
+        this(null);
+    }
+
     /**
      * Processes the Digest challenge.
      *

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java?rev=1235752&r1=1235751&r2=1235752&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java
Wed Jan 25 14:17:37 2012
@@ -33,6 +33,7 @@ import java.util.Map;
 import org.apache.http.annotation.NotThreadSafe;
 
 import org.apache.http.HeaderElement;
+import org.apache.http.auth.ChallengeState;
 import org.apache.http.auth.MalformedChallengeException;
 import org.apache.http.message.BasicHeaderValueParser;
 import org.apache.http.message.HeaderValueParser;
@@ -55,13 +56,20 @@ public abstract class RFC2617Scheme exte
     private final Map<String, String> params;
 
     /**
-     * Default constructor for RFC2617 compliant authentication schemes.
+     * Creates an instance of <tt>RFC2617Scheme</tt> with the given challenge
+     * state.
+     *
+     * @since 4.2
      */
-    public RFC2617Scheme() {
-        super();
+    public RFC2617Scheme(final ChallengeState challengeState) {
+        super(challengeState);
         this.params = new HashMap<String, String>();
     }
 
+    public RFC2617Scheme() {
+        this(null);
+    }
+
     @Override
     protected void parseChallenge(
             final CharArrayBuffer buffer, int pos, int len) throws MalformedChallengeException
{



Mime
View raw message