hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1692371 [1/3] - in /httpcomponents/httpclient/trunk: fluent-hc/src/main/java/org/apache/http/client/fluent/ httpclient-cache/src/main/java/org/apache/http/client/cache/ httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ http...
Date Thu, 23 Jul 2015 10:00:47 GMT
Author: olegk
Date: Thu Jul 23 10:00:46 2015
New Revision: 1692371

URL: http://svn.apache.org/r1692371
Log:
AuthScheme API changes; User credentials made optional for those schemes that do not require them

Removed:
    httpcomponents/httpclient/trunk/httpclient-win/src/main/java/org/apache/http/impl/auth/win/CurrentWindowsCredentials.java
    httpcomponents/httpclient/trunk/httpclient-win/src/main/java/org/apache/http/impl/auth/win/WindowsCredentialsProvider.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/AuthOption.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/NonStandardAuthScheme.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/StandardAuthScheme.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestNonStandardHttpScheme.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestStandardHttpScheme.java
Modified:
    httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheStorage.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheUpdateException.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheConfig.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryUpdater.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingExec.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/DefaultFailureCache.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCache.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ehcache/EhcacheHttpCacheStorage.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/MemcachedHttpCacheStorage.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRequirements.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ehcache/TestEhcacheHttpCacheStorage.java
    httpcomponents/httpclient/trunk/httpclient-win/src/main/java/org/apache/http/impl/auth/win/WindowsNegotiateScheme.java
    httpcomponents/httpclient/trunk/httpclient-win/src/main/java/org/apache/http/impl/client/WinHttpClients.java
    httpcomponents/httpclient/trunk/httpclient-win/src/test/java/org/apache/http/impl/auth/win/TestWindowsNegotiateScheme.java
    httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveBasicAuthentication.java
    httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveDigestAuthentication.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/AuthScheme.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/AuthState.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthCache.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/cookie/CookieAttributeHandler.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/cookie/CookiePriorityComparator.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/GGSSchemeBase.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/HttpAuthenticator.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/KerberosScheme.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/NTLMScheme.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/SPNegoScheme.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultUserTokenHandler.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/ProxyClient.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/ProtocolExec.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAuthCache.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestBasicScheme.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestDigestScheme.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestHttpAuthenticator.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthentication.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientReauthentication.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestMainClientExec.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestRedirectExec.java
    httpcomponents/httpclient/trunk/src/docbkx/connmgmt.xml

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=1692371&r1=1692370&r2=1692371&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 Thu Jul 23 10:00:46 2015
@@ -29,18 +29,13 @@ package org.apache.http.client.fluent;
 import java.io.IOException;
 import java.security.KeyManagementException;
 import java.security.NoSuchAlgorithmException;
-import java.util.Collections;
 import java.util.concurrent.TimeUnit;
 
 import javax.net.ssl.SSLContext;
 
 import org.apache.http.HttpHost;
-import org.apache.http.NameValuePair;
-import org.apache.http.auth.AuthChallenge;
 import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.ChallengeType;
 import org.apache.http.auth.Credentials;
-import org.apache.http.auth.MalformedChallengeException;
 import org.apache.http.auth.NTCredentials;
 import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.client.AuthCache;
@@ -151,12 +146,14 @@ public class Executor {
     }
 
     public Executor authPreemptive(final HttpHost host) {
-        final BasicScheme basicScheme = new BasicScheme();
-        try {
-            basicScheme.processChallenge(ChallengeType.TARGET, new AuthChallenge("basic", null, Collections.<NameValuePair>emptyList()));
-        } catch (final MalformedChallengeException ignore) {
+        if (this.credentialsStore != null) {
+            final Credentials credentials = this.credentialsStore.getCredentials(new AuthScope(host));
+            if (credentials == null) {
+                final BasicScheme basicScheme = new BasicScheme();
+                basicScheme.initPreemptive(credentials);
+                this.authCache.put(host, basicScheme);
+            }
         }
-        this.authCache.put(host, basicScheme);
         return this;
     }
 
@@ -168,12 +165,14 @@ public class Executor {
     }
 
     public Executor authPreemptiveProxy(final HttpHost proxy) {
-        final BasicScheme basicScheme = new BasicScheme();
-        try {
-            basicScheme.processChallenge(ChallengeType.PROXY, new AuthChallenge("basic", null, Collections.<NameValuePair>emptyList()));
-        } catch (final MalformedChallengeException ignore) {
+        if (this.credentialsStore != null) {
+            final Credentials credentials = this.credentialsStore.getCredentials(new AuthScope(proxy));
+            if (credentials == null) {
+                final BasicScheme basicScheme = new BasicScheme();
+                basicScheme.initPreemptive(credentials);
+                this.authCache.put(proxy, basicScheme);
+            }
         }
-        this.authCache.put(proxy, basicScheme);
         return this;
     }
 

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheStorage.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheStorage.java?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheStorage.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheStorage.java Thu Jul 23 10:00:46 2015
@@ -65,10 +65,10 @@ public interface HttpCacheStorage {
     void removeEntry(String key) throws IOException;
 
     /**
-     * Atomically applies the given callback to update an existing cache
+     * Atomically applies the given callback to processChallenge an existing cache
      * entry under a given key.
      * @param key indicates which entry to modify
-     * @param callback performs the update; see
+     * @param callback performs the processChallenge; see
      *   {@link HttpCacheUpdateCallback} for details, but roughly the
      *   callback expects to be handed the current entry and will return
      *   the new value for the entry.

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheUpdateException.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheUpdateException.java?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheUpdateException.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheUpdateException.java Thu Jul 23 10:00:46 2015
@@ -28,7 +28,7 @@ package org.apache.http.client.cache;
 
 /**
  * Signals that {@link HttpCacheStorage} encountered an error performing an
- * update operation.
+ * processChallenge operation.
  *
  * @since 4.1
  */

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java Thu Jul 23 10:00:46 2015
@@ -165,7 +165,7 @@ class BasicHttpCache implements HttpCach
         try {
             storage.updateEntry(parentURI, callback);
         } catch (final HttpCacheUpdateException e) {
-            log.warn("Could not update key [" + parentURI + "]", e);
+            log.warn("Could not processChallenge key [" + parentURI + "]", e);
         }
     }
 
@@ -189,7 +189,7 @@ class BasicHttpCache implements HttpCach
         try {
             storage.updateEntry(parentCacheKey, callback);
         } catch (final HttpCacheUpdateException e) {
-            log.warn("Could not update key [" + parentCacheKey + "]", e);
+            log.warn("Could not processChallenge key [" + parentCacheKey + "]", e);
         }
     }
 

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheConfig.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheConfig.java?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheConfig.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheConfig.java Thu Jul 23 10:00:46 2015
@@ -113,7 +113,7 @@ public class CacheConfig implements Clon
     public final static int DEFAULT_MAX_CACHE_ENTRIES = 1000;
 
     /** Default setting for the number of retries on a failed
-     * cache update
+     * cache processChallenge
      */
     public final static int DEFAULT_MAX_UPDATE_RETRIES = 1;
 
@@ -234,7 +234,7 @@ public class CacheConfig implements Clon
     }
 
     /**
-     * Returns the number of times to retry a cache update on failure
+     * Returns the number of times to retry a cache processChallenge on failure
      */
     public int getMaxUpdateRetries(){
         return maxUpdateRetries;
@@ -400,7 +400,7 @@ public class CacheConfig implements Clon
         }
 
         /**
-         * Sets the number of times to retry a cache update on failure
+         * Sets the number of times to retry a cache processChallenge on failure
          */
         public Builder setMaxUpdateRetries(final int maxUpdateRetries) {
             this.maxUpdateRetries = maxUpdateRetries;

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryUpdater.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryUpdater.java?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryUpdater.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryUpdater.java Thu Jul 23 10:00:46 2015
@@ -48,7 +48,7 @@ import org.apache.http.util.Args;
 /**
  * Update a {@link HttpCacheEntry} with new or updated information based on the latest
  * 304 status response from the Server.  Use the {@link HttpResponse} to perform
- * the update.
+ * the processChallenge.
  *
  * @since 4.1
  */

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingExec.java?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingExec.java Thu Jul 23 10:00:46 2015
@@ -712,7 +712,7 @@ public class CachingExec implements Clie
             responseEntry = responseCache.updateVariantCacheEntry(target, conditionalRequest,
                     matchedEntry, backendResponse, requestDate, responseDate, matchingVariant.getCacheKey());
         } catch (final IOException ioe) {
-            log.warn("Could not update cache entry", ioe);
+            log.warn("Could not processChallenge cache entry", ioe);
         } finally {
             backendResponse.close();
         }
@@ -726,7 +726,7 @@ public class CachingExec implements Clie
         try {
             responseCache.reuseVariantEntryFor(target, request, matchingVariant);
         } catch (final IOException ioe) {
-            log.warn("Could not update cache entry to reuse variant", ioe);
+            log.warn("Could not processChallenge cache entry to reuse variant", ioe);
         }
     }
 

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/DefaultFailureCache.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/DefaultFailureCache.java?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/DefaultFailureCache.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/DefaultFailureCache.java Thu Jul 23 10:00:46 2015
@@ -98,7 +98,7 @@ public class DefaultFailureCache impleme
          *
          * In case there is a lot of contention on that identifier, a thread
          * might starve. Thus it gives up after a certain number of failed
-         * update tries.
+         * processChallenge tries.
          */
         for (int i = 0; i < MAX_UPDATE_TRIES; i++) {
             final FailureCacheValue oldValue = storage.get(identifier);

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCache.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCache.java?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCache.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/HttpCache.java Thu Jul 23 10:00:46 2015
@@ -159,7 +159,7 @@ interface HttpCache {
      * @param target host of the upstream client request
      * @param req request sent by upstream client
      * @param variant variant cache entry to reuse
-     * @throws IOException may be thrown during cache update
+     * @throws IOException may be thrown during cache processChallenge
      */
     void reuseVariantEntryFor(HttpHost target, final HttpRequest req,
             final Variant variant) throws IOException;

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ehcache/EhcacheHttpCacheStorage.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ehcache/EhcacheHttpCacheStorage.java?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ehcache/EhcacheHttpCacheStorage.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ehcache/EhcacheHttpCacheStorage.java Thu Jul 23 10:00:46 2015
@@ -156,6 +156,6 @@ public class EhcacheHttpCacheStorage imp
                 }
             }
         }while(numRetries <= maxUpdateRetries);
-        throw new HttpCacheUpdateException("Failed to update");
+        throw new HttpCacheUpdateException("Failed to processChallenge");
     }
 }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/MemcachedHttpCacheStorage.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/MemcachedHttpCacheStorage.java?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/MemcachedHttpCacheStorage.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/memcached/MemcachedHttpCacheStorage.java Thu Jul 23 10:00:46 2015
@@ -268,6 +268,6 @@ public class MemcachedHttpCacheStorage i
             }
         } while (numRetries <= maxUpdateRetries);
 
-        throw new HttpCacheUpdateException("Failed to update");
+        throw new HttpCacheUpdateException("Failed to processChallenge");
     }
 }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java Thu Jul 23 10:00:46 2015
@@ -1208,7 +1208,7 @@ public class TestProtocolRecommendations
     }
 
     /* "If the entity-tag of the new response matches that of an existing
-     * entry, the new response SHOULD be used to update the header fields
+     * entry, the new response SHOULD be used to processChallenge the header fields
      * of the existing entry, and the result MUST be returned to the
      * client."
      *

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRequirements.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRequirements.java?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRequirements.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRequirements.java Thu Jul 23 10:00:46 2015
@@ -2198,8 +2198,8 @@ public class TestProtocolRequirements ex
     }
 
     /*
-     * "If a cache uses a received 304 response to update a cache entry, the
-     * cache MUST update the entry to reflect any new field values given in the
+     * "If a cache uses a received 304 response to processChallenge a cache entry, the
+     * cache MUST processChallenge the entry to reflect any new field values given in the
      * response.
      *
      * http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5
@@ -4539,7 +4539,7 @@ public class TestProtocolRequirements ex
      * the ETag header field in its 304 (Not Modified) response to
      * tell the cache which entry is appropriate. If the entity-tag of
      * the new response matches that of an existing entry, the new
-     * response SHOULD be used to update the header fields of the
+     * response SHOULD be used to processChallenge the header fields of the
      * existing entry, and the result MUST be returned to the client.
      *
      * http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.6

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ehcache/TestEhcacheHttpCacheStorage.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ehcache/TestEhcacheHttpCacheStorage.java?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ehcache/TestEhcacheHttpCacheStorage.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ehcache/TestEhcacheHttpCacheStorage.java Thu Jul 23 10:00:46 2015
@@ -168,7 +168,7 @@ public class TestEhcacheHttpCacheStorage
         when(mockCache.get(key)).thenReturn(existingElement);
         when(mockSerializer.readFrom(isA(InputStream.class))).thenReturn(existingValue);
 
-        // update
+        // processChallenge
         mockSerializer.writeTo(same(updatedValue), isA(OutputStream.class));
         when(mockCache.replace(same(existingElement), isA(Element.class))).thenReturn(true);
 
@@ -231,7 +231,7 @@ public class TestEhcacheHttpCacheStorage
         when(mockCache.get(key)).thenReturn(existingElement);
         when(mockSerializer.readFrom(isA(InputStream.class))).thenReturn(existingValue);
 
-        // update but fail
+        // processChallenge but fail
         when(mockCache.replace(same(existingElement), isA(Element.class))).thenReturn(false);
 
         try{

Modified: httpcomponents/httpclient/trunk/httpclient-win/src/main/java/org/apache/http/impl/auth/win/WindowsNegotiateScheme.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-win/src/main/java/org/apache/http/impl/auth/win/WindowsNegotiateScheme.java?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-win/src/main/java/org/apache/http/impl/auth/win/WindowsNegotiateScheme.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-win/src/main/java/org/apache/http/impl/auth/win/WindowsNegotiateScheme.java Thu Jul 23 10:00:46 2015
@@ -26,29 +26,28 @@
  */
 package org.apache.http.impl.auth.win;
 
+import java.security.Principal;
+
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.http.Header;
-import org.apache.http.HttpHeaders;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.annotation.NotThreadSafe;
 import org.apache.http.auth.AuthChallenge;
+import org.apache.http.auth.AuthScheme;
 import org.apache.http.auth.AuthenticationException;
-import org.apache.http.auth.ChallengeType;
-import org.apache.http.auth.Credentials;
-import org.apache.http.auth.InvalidCredentialsException;
+import org.apache.http.auth.BasicUserPrincipal;
+import org.apache.http.auth.CredentialsProvider;
 import org.apache.http.auth.MalformedChallengeException;
 import org.apache.http.client.config.AuthSchemes;
 import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.conn.routing.RouteInfo;
-import org.apache.http.impl.auth.NonStandardAuthScheme;
-import org.apache.http.message.BufferedHeader;
 import org.apache.http.protocol.HttpContext;
-import org.apache.http.util.CharArrayBuffer;
+import org.apache.http.util.Args;
 
 import com.sun.jna.platform.win32.Secur32;
+import com.sun.jna.platform.win32.Secur32Util;
 import com.sun.jna.platform.win32.Sspi;
 import com.sun.jna.platform.win32.Sspi.CredHandle;
 import com.sun.jna.platform.win32.Sspi.CtxtHandle;
@@ -70,7 +69,7 @@ import com.sun.jna.ptr.IntByReference;
  * @since 4.4
  */
 @NotThreadSafe
-public class WindowsNegotiateScheme extends NonStandardAuthScheme {
+public class WindowsNegotiateScheme implements AuthScheme {
 
     private final Log log = LogFactory.getLog(getClass());
 
@@ -78,6 +77,7 @@ public class WindowsNegotiateScheme exte
     private final String scheme;
     private final String servicePrincipalName;
 
+    private String challenge;
     private CredHandle clientCred;
     private CtxtHandle sspiContext;
     private boolean continueNeeded;
@@ -119,7 +119,7 @@ public class WindowsNegotiateScheme exte
     }
 
     @Override
-    public String getSchemeName() {
+    public String getName() {
         return scheme;
     }
 
@@ -129,10 +129,19 @@ public class WindowsNegotiateScheme exte
     }
 
     @Override
+    public String getRealm() {
+        return null;
+    }
+
+    @Override
     public void processChallenge(
-            final ChallengeType challengeType, final AuthChallenge authChallenge) throws MalformedChallengeException {
-        update(challengeType, authChallenge);
-        final String challenge = getChallenge();
+            final AuthChallenge authChallenge,
+            final HttpContext context) throws MalformedChallengeException {
+        Args.notNull(authChallenge, "AuthChallenge");
+        if (authChallenge.getValue() == null) {
+            throw new MalformedChallengeException("Missing auth challenge");
+        }
+        challenge = authChallenge.getValue();
         if (challenge.isEmpty()) {
             if (clientCred != null) {
                 dispose(); // run cleanup first before throwing an exception otherwise can leak OS resources
@@ -144,24 +153,38 @@ public class WindowsNegotiateScheme exte
     }
 
     @Override
-    public Header authenticate(
-            final Credentials credentials,
+    public boolean isResponseReady(
+            final HttpHost host,
+            final CredentialsProvider credentialsProvider,
+            final HttpContext context) throws AuthenticationException {
+        return true;
+    }
+
+    /**
+     * Get the SAM-compatible username of the currently logged-on user.
+     *
+     * @return String.
+     */
+    public static String getCurrentUsername() {
+        return Secur32Util.getUserNameEx(Secur32.EXTENDED_NAME_FORMAT.NameSamCompatible);
+    }
+
+    @Override
+    public Principal getPrinciple() {
+        return new BasicUserPrincipal(getCurrentUsername());
+    }
+
+    @Override
+    public String generateAuthResponse(
+            final HttpHost host,
             final HttpRequest request,
             final HttpContext context) throws AuthenticationException {
 
-        final String challenge = getChallenge();
         final String response;
         if (clientCred == null) {
-            // ?? We don't use the credentials, should we allow anything?
-            if (!(credentials instanceof CurrentWindowsCredentials)) {
-                throw new InvalidCredentialsException(
-                        "Credentials cannot be used for " + getSchemeName() + " authentication: "
-                                + credentials.getClass().getName());
-            }
-
             // client credentials handle
             try {
-                final String username = CurrentWindowsCredentials.getCurrentUsername();
+                final String username = getCurrentUsername();
                 final TimeStamp lifetime = new TimeStamp();
 
                 clientCred = new CredHandle();
@@ -202,18 +225,7 @@ public class WindowsNegotiateScheme exte
                 }
             }
         }
-
-        final CharArrayBuffer buffer = new CharArrayBuffer(scheme.length() + 30);
-        if (isProxy()) {
-            buffer.append(HttpHeaders.PROXY_AUTHORIZATION);
-        } else {
-            buffer.append(HttpHeaders.AUTHORIZATION);
-        }
-        buffer.append(": ");
-        buffer.append(scheme); // NTLM or Negotiate
-        buffer.append(" ");
-        buffer.append(response);
-        return new BufferedHeader(buffer);
+        return scheme + " " + response;
     }
 
     private void failAuthCleanup() {
@@ -281,7 +293,7 @@ public class WindowsNegotiateScheme exte
     }
 
     @Override
-    public boolean isComplete() {
+    public boolean isChallengeComplete() {
         return !continueNeeded;
     }
 

Modified: httpcomponents/httpclient/trunk/httpclient-win/src/main/java/org/apache/http/impl/client/WinHttpClients.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-win/src/main/java/org/apache/http/impl/client/WinHttpClients.java?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-win/src/main/java/org/apache/http/impl/client/WinHttpClients.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-win/src/main/java/org/apache/http/impl/client/WinHttpClients.java Thu Jul 23 10:00:46 2015
@@ -29,13 +29,11 @@ package org.apache.http.impl.client;
 import java.util.Locale;
 
 import org.apache.http.auth.AuthSchemeProvider;
-import org.apache.http.auth.CredentialsProvider;
 import org.apache.http.client.config.AuthSchemes;
 import org.apache.http.config.Registry;
 import org.apache.http.config.RegistryBuilder;
 import org.apache.http.impl.auth.BasicSchemeFactory;
 import org.apache.http.impl.auth.DigestSchemeFactory;
-import org.apache.http.impl.auth.win.WindowsCredentialsProvider;
 import org.apache.http.impl.auth.win.WindowsNTLMSchemeFactory;
 import org.apache.http.impl.auth.win.WindowsNegotiateSchemeFactory;
 
@@ -74,9 +72,7 @@ public class WinHttpClients {
                     .register(AuthSchemes.NTLM, new WindowsNTLMSchemeFactory(null))
                     .register(AuthSchemes.SPNEGO, new WindowsNegotiateSchemeFactory(null))
                     .build();
-            final CredentialsProvider credsProvider = new WindowsCredentialsProvider(new SystemDefaultCredentialsProvider());
             return HttpClientBuilder.create()
-                    .setDefaultCredentialsProvider(credsProvider)
                     .setDefaultAuthSchemeRegistry(authSchemeRegistry);
         } else {
             return HttpClientBuilder.create();

Modified: httpcomponents/httpclient/trunk/httpclient-win/src/test/java/org/apache/http/impl/auth/win/TestWindowsNegotiateScheme.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-win/src/test/java/org/apache/http/impl/auth/win/TestWindowsNegotiateScheme.java?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-win/src/test/java/org/apache/http/impl/auth/win/TestWindowsNegotiateScheme.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-win/src/test/java/org/apache/http/impl/auth/win/TestWindowsNegotiateScheme.java Thu Jul 23 10:00:46 2015
@@ -36,7 +36,6 @@ import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.auth.AuthScheme;
 import org.apache.http.auth.AuthSchemeProvider;
-import org.apache.http.auth.CredentialsProvider;
 import org.apache.http.client.config.AuthSchemes;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpGet;
@@ -44,7 +43,6 @@ import org.apache.http.config.Registry;
 import org.apache.http.config.RegistryBuilder;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.impl.client.SystemDefaultCredentialsProvider;
 import org.apache.http.impl.client.WinHttpClients;
 import org.apache.http.localserver.LocalServerTestBase;
 import org.apache.http.protocol.HttpContext;
@@ -105,10 +103,7 @@ public class TestWindowsNegotiateScheme
                     return new WindowsNegotiateSchemeGetTokenFail(AuthSchemes.SPNEGO, "HTTP/example.com");
                 }
             }).build();
-        final CredentialsProvider credsProvider =
-                new WindowsCredentialsProvider(new SystemDefaultCredentialsProvider());
         final CloseableHttpClient customClient = HttpClientBuilder.create()
-                .setDefaultCredentialsProvider(credsProvider)
                 .setDefaultAuthSchemeRegistry(authSchemeRegistry).build();
 
         final HttpHost target = start();

Modified: httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveBasicAuthentication.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveBasicAuthentication.java?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveBasicAuthentication.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveBasicAuthentication.java Thu Jul 23 10:00:46 2015
@@ -27,7 +27,6 @@
 package org.apache.http.examples.client;
 
 import org.apache.http.HttpHost;
-import org.apache.http.auth.AuthScope;
 import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.client.AuthCache;
 import org.apache.http.client.methods.CloseableHttpResponse;
@@ -35,7 +34,6 @@ import org.apache.http.client.methods.Ht
 import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.impl.auth.BasicScheme;
 import org.apache.http.impl.client.BasicAuthCache;
-import org.apache.http.impl.client.BasicCredentialsProvider;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClients;
 import org.apache.http.util.EntityUtils;
@@ -52,18 +50,13 @@ public class ClientPreemptiveBasicAuthen
 
     public static void main(String[] args) throws Exception {
         HttpHost target = new HttpHost("localhost", 80, "http");
-        BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
-        credsProvider.setCredentials(
-                new AuthScope(target.getHostName(), target.getPort()),
-                new UsernamePasswordCredentials("username", "password"));
-        try (CloseableHttpClient httpclient = HttpClients.custom()
-                .setDefaultCredentialsProvider(credsProvider).build()) {
+        try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
 
             // Create AuthCache instance
             AuthCache authCache = new BasicAuthCache();
-            // Generate BASIC scheme object and add it to the local
-            // auth cache
+            // Generate BASIC scheme object and add it to the local auth cache
             BasicScheme basicAuth = new BasicScheme();
+            basicAuth.initPreemptive(new UsernamePasswordCredentials("username", "password"));
             authCache.put(target, basicAuth);
 
             // Add AuthCache to the execution context

Modified: httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveDigestAuthentication.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveDigestAuthentication.java?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveDigestAuthentication.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveDigestAuthentication.java Thu Jul 23 10:00:46 2015
@@ -27,7 +27,6 @@
 package org.apache.http.examples.client;
 
 import org.apache.http.HttpHost;
-import org.apache.http.auth.AuthScope;
 import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.client.AuthCache;
 import org.apache.http.client.methods.CloseableHttpResponse;
@@ -35,7 +34,6 @@ import org.apache.http.client.methods.Ht
 import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.impl.auth.DigestScheme;
 import org.apache.http.impl.client.BasicAuthCache;
-import org.apache.http.impl.client.BasicCredentialsProvider;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClients;
 import org.apache.http.util.EntityUtils;
@@ -53,23 +51,14 @@ public class ClientPreemptiveDigestAuthe
 
     public static void main(String[] args) throws Exception {
         HttpHost target = new HttpHost("localhost", 80, "http");
-        BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
-        credsProvider.setCredentials(
-                new AuthScope(target.getHostName(), target.getPort()),
-                new UsernamePasswordCredentials("username", "password"));
-        try (CloseableHttpClient httpclient = HttpClients.custom()
-                .setDefaultCredentialsProvider(credsProvider)
-                .build()) {
+        try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
 
             // Create AuthCache instance
             AuthCache authCache = new BasicAuthCache();
-            // Generate DIGEST scheme object, initialize it and add it to the local
-            // auth cache
+            // Generate DIGEST scheme object, initialize it and add it to the local auth cache
             DigestScheme digestAuth = new DigestScheme();
-            // Suppose we already know the realm name
-            digestAuth.overrideParamter("realm", "some realm");
-            // Suppose we already know the expected nonce value
-            digestAuth.overrideParamter("nonce", "whatever");
+            // Suppose we already know the realm name and the expected nonce value
+            digestAuth.initPreemptive(new UsernamePasswordCredentials("username", "password"), "whatever", "realm");
             authCache.put(target, digestAuth);
 
             // Add AuthCache to the execution context

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/AuthScheme.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/AuthScheme.java?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/AuthScheme.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/AuthScheme.java Thu Jul 23 10:00:46 2015
@@ -26,69 +26,106 @@
  */
 package org.apache.http.auth;
 
-import org.apache.http.Header;
+import java.security.Principal;
+
+import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.protocol.HttpContext;
 
 /**
- * This interface represents an abstract challenge-response oriented
- * authentication scheme.
+ * This interface represents an abstract challenge-response oriented authentication scheme.
+ * <p>
+ * Authentication schemes can be either request or connection based. The former are
+ * expected to provide an authorization response with each request message while the latter
+ * is executed only once and applies to the underlying connection for its entire life span.
+ * Care must be taken when re-using connections authorized through a connection based
+ * authentication scheme and they may carry a particular security context and be authorized
+ * for a particular user identity. It is important that such schemes always provide
+ * the user identity they represent through the {@link #getPrinciple()} method.
+ * <p>
+ * Authentication scheme are expected to transition through a series of standard phases or
+ * states.
+ * <p>
+ * Authentication scheme starts off its life cycle with no context and no specific state.
+ * <p>
+ * The {@link #processChallenge(AuthChallenge, HttpContext)} method is called  to
+ * process an authentication challenge received either from the target server or a proxy.
+ * The authentication scheme transitions to CHALLENGED state and is expected to validate
+ * the token passed to it as a parameter and initialize its internal state based on
+ * challenge details. Standard authentication schemes are expected to provide a realm
+ * attribute in the challenge. {@link #getRealm()} can be called to obtain an identifier
+ * of the realm that requires authorization.
  * <p>
- * Authentication schemes may be stateful involving a series of
- * challenge-response exchanges.
+ * Once the challenge has been fully processed the {@link #isResponseReady(HttpHost,
+ * CredentialsProvider, HttpContext)} method to determine whether the scheme is capable of
+ * generating a authorization response based on its current state and it holds user credentials
+ * required to do so. If this method returns {@code false} the authentication is considered
+ * to be in FAILED state and no authorization response. Otherwise the scheme is considered
+ * to be in RESPONSE_READY state.
+ * <p>
+ * Once the scheme is ready to respond to the challenge the {@link #generateAuthResponse(
+ * HttpHost, HttpRequest, HttpContext)} method to generate a response token, which will
+ * be sent to the opposite endpoint in the subsequent request message.
+ * <p>
+ * Certain non-standard schemes may involve multiple challenge / response exchanges to
+ * fully establish a shared context and complete the authentication process. Authentication
+ * schemes are required to return {@code true} {@link #isChallengeComplete()} once the
+ * handshake is considered complete.
+ * <p>
+ * The authentication scheme is considered successfully completed and in SUCCESS state
+ * if the opposite endpoint accepts the request message containing the authorization
+ * response and responds with a message indicating no authentication failure .
+ * If the opposite endpoint sends status code 401 or 407 in response to a request message
+ * containing the terminal authorization response, the scheme is considered unsuccessful
+ * and in FAILED state.
  *
  * @since 4.0
  */
-
 public interface AuthScheme {
 
     /**
-     * Processes the given challenge token. Some authentication schemes
-     * may involve multiple challenge-response exchanges. Such schemes must be able
-     * to maintain the state information when dealing with sequential challenges
-     *
-     * @param challengeType the challenge type
-     * @param authChallenge the auth challenge
+     * Returns textual designation of the given authentication scheme.
      *
-     * @since 5.0
+     * @return the name of the given authentication scheme
      */
-    void processChallenge(
-            ChallengeType challengeType,
-            AuthChallenge authChallenge) throws  MalformedChallengeException;
+    String getName();
 
     /**
-     * Produces an authorization string for the given set of {@link Credentials}.
+     * Determines if the authentication scheme is expected to provide an authorization response
+     * on a per connection basis instead of the standard per request basis
      *
-     * @param credentials The credentials to be used for authentication
-     * @param request The request being authenticated
-     * @param context HTTP context
-     * @throws AuthenticationException if authorization string cannot
-     *   be generated due to an authentication failure
-     *
-     * @return authorization header
-     *
-     * @since 5.0
+     * @return {@code true} if the scheme is connection based, {@code false}
+     * if the scheme is request based.
      */
-    Header authenticate(
-            Credentials credentials,
-            HttpRequest request,
-            HttpContext context) throws AuthenticationException;
+    boolean isConnectionBased();
 
     /**
-     * Returns textual designation of the given authentication scheme.
+     * Processes the given auth challenge. Some authentication schemes may involve multiple
+     * challenge-response exchanges. Such schemes must be able to maintain internal state
+     * when dealing with sequential challenges
      *
-     * @return the name of the given authentication scheme
+     * @param authChallenge the auth challenge
+     * @param context HTTP context
+     * @throws MalformedChallengeException in case the auth challenge is incomplete,
+     * malformed or otherwise invalid.
+     * @since 5.0
      */
-    String getSchemeName();
+    void processChallenge(
+            AuthChallenge authChallenge,
+            HttpContext context) throws  MalformedChallengeException;
 
     /**
-     * Returns authentication parameter with the given name, if available.
+     * Authentication process may involve a series of challenge-response exchanges.
+     * This method tests if the authorization process has been fully completed (either
+     * successfully or unsuccessfully), that is, all the required authorization
+     * challenges have been processed in their entirety.
      *
-     * @param name The name of the parameter to be returned
+     * @return {@code true} if the authentication process has been completed,
+     * {@code false} otherwise.
      *
-     * @return the parameter with the given name
+     * @since 5.0
      */
-    String getParameter(final String name);
+    boolean isChallengeComplete();
 
     /**
      * Returns authentication realm. If the concept of an authentication
@@ -100,23 +137,58 @@ public interface AuthScheme {
     String getRealm();
 
     /**
-     * Tests if the authentication scheme is provides authorization on a per
-     * connection basis instead of usual per request basis
+     * Determines whether or not an authorization response can be generated based on
+     * the actual authentication state. Generally the outcome of this method will depend
+     * upon availability of user credentials necessary to produce an authorization
+     * response.
      *
-     * @return {@code true} if the scheme is connection based, {@code false}
-     * if the scheme is request based.
+     * @param credentialsProvider The credentials to be used for authentication
+     * @param context HTTP context
+     * @throws AuthenticationException if authorization string cannot
+     *   be generated due to an authentication failure
+     *
+     * @return {@code true} if an authorization response can be generated and
+     * the authentication handshake can proceed, {@code false} otherwise.
+     *
+     * @since 5.0
      */
-    boolean isConnectionBased();
+    boolean isResponseReady(
+            HttpHost host,
+            CredentialsProvider credentialsProvider,
+            HttpContext context) throws AuthenticationException;
 
     /**
-     * Authentication process may involve a series of challenge-response exchanges.
-     * This method tests if the authorization process has been completed, either
-     * successfully or unsuccessfully, that is, all the required authorization
-     * challenges have been processed in their entirety.
+     * Returns {@link Principal} whose credentials are used to generate
+     * an authentication response. Connection based schemes are required
+     * to return a user {@link Principal} if authorization applies to
+     * for the entire life span of connection.
+     * @return user principle
      *
-     * @return {@code true} if the authentication process has been completed,
-     * {@code false} otherwise.
+     * @see #isConnectionBased()
+     *
+     * @since 5.0
      */
-    boolean isComplete();
+    Principal getPrinciple();
+
+    /**
+     * Generates an authorization response based on the current state. Some authentication
+     * schemes may need to load user credentials required to generate an authorization
+     * response from a {@link CredentialsProvider} prior to this method call.
+     *
+     * @param request The request being authenticated
+     * @param context HTTP context
+     * @throws AuthenticationException if authorization string cannot
+     *   be generated due to an authentication failure
+     *
+     * @return authorization header
+     *
+     * @see #isResponseReady(HttpHost, CredentialsProvider, HttpContext)
+     *
+     * @since 5.0
+     */
+    String generateAuthResponse(
+            HttpHost host,
+            HttpRequest request,
+            HttpContext context) throws AuthenticationException;
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/AuthState.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/AuthState.java?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/AuthState.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/AuthState.java Thu Jul 23 10:00:46 2015
@@ -45,11 +45,8 @@ public class AuthState {
     /** Actual authentication scheme */
     private AuthScheme authScheme;
 
-    /** Credentials selected for authentication */
-    private Credentials credentials;
-
     /** Available auth options */
-    private Queue<AuthOption> authOptions;
+    private Queue<AuthScheme> authOptions;
 
     public AuthState() {
         super();
@@ -65,7 +62,6 @@ public class AuthState {
         this.state = AuthProtocolState.UNCHALLENGED;
         this.authOptions = null;
         this.authScheme = null;
-        this.credentials = null;
     }
 
     /**
@@ -90,71 +86,48 @@ public class AuthState {
     }
 
     /**
-     * Returns actual {@link Credentials}. May be null.
-     */
-    public Credentials getCredentials() {
-        return this.credentials;
-    }
-
-    /**
-     * Updates the auth state with {@link AuthScheme} and {@link Credentials}.
+     * Updates the auth state with {@link AuthScheme} and clears auth options.
      *
      * @param authScheme auth scheme. May not be null.
-     * @param credentials user crednetials. May not be null.
      *
      * @since 4.2
      */
-    public void update(final AuthScheme authScheme, final Credentials credentials) {
+    public void update(final AuthScheme authScheme) {
         Args.notNull(authScheme, "Auth scheme");
-        Args.notNull(credentials, "Credentials");
         this.authScheme = authScheme;
-        this.credentials = credentials;
         this.authOptions = null;
     }
 
     /**
-     * Returns available {@link AuthOption}s. May be null.
+     * Returns available auth options. May be null.
      *
      * @since 4.2
      */
-    public Queue<AuthOption> getAuthOptions() {
+    public Queue<AuthScheme> getAuthOptions() {
         return this.authOptions;
     }
 
     /**
-     * Returns {@code true} if {@link AuthOption}s are available, {@code false}
-     * otherwise.
-     *
-     * @since 4.2
-     */
-    public boolean hasAuthOptions() {
-        return this.authOptions != null && !this.authOptions.isEmpty();
-    }
-
-    /**
-     * Updates the auth state with a queue of {@link AuthOption}s.
+     * Updates the auth state with a queue of auth options.
      *
      * @param authOptions a queue of auth options. May not be null or empty.
      *
      * @since 4.2
      */
-    public void update(final Queue<AuthOption> authOptions) {
+    public void update(final Queue<AuthScheme> authOptions) {
         Args.notEmpty(authOptions, "Queue of auth options");
         this.authOptions = authOptions;
         this.authScheme = null;
-        this.credentials = null;
     }
 
     @Override
     public String toString() {
         final StringBuilder buffer = new StringBuilder();
-        buffer.append("state:").append(this.state).append(";");
+        buffer.append("[").append(this.state);
         if (this.authScheme != null) {
-            buffer.append("auth scheme:").append(this.authScheme.getSchemeName()).append(";");
-        }
-        if (this.credentials != null) {
-            buffer.append("credentials present");
+            buffer.append(" ").append(this.authScheme);
         }
+        buffer.append("]");
         return buffer.toString();
     }
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthCache.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthCache.java?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthCache.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthCache.java Thu Jul 23 10:00:46 2015
@@ -38,9 +38,7 @@ import org.apache.http.HttpRequestInterc
 import org.apache.http.annotation.Immutable;
 import org.apache.http.auth.AuthProtocolState;
 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.auth.CredentialsProvider;
 import org.apache.http.client.AuthCache;
 import org.apache.http.conn.routing.RouteInfo;
@@ -106,7 +104,10 @@ public class RequestAuthCache implements
         if (targetState != null && targetState.getState() == AuthProtocolState.UNCHALLENGED) {
             final AuthScheme authScheme = authCache.get(target);
             if (authScheme != null) {
-                doPreemptiveAuth(target, authScheme, targetState, credsProvider);
+                if (this.log.isDebugEnabled()) {
+                    this.log.debug("Re-using cached '" + authScheme.getName() + "' auth scheme for " + target);
+                }
+                targetState.update(authScheme);
             }
         }
 
@@ -115,34 +116,12 @@ public class RequestAuthCache implements
         if (proxy != null && proxyState != null && proxyState.getState() == AuthProtocolState.UNCHALLENGED) {
             final AuthScheme authScheme = authCache.get(proxy);
             if (authScheme != null) {
-                doPreemptiveAuth(proxy, authScheme, proxyState, credsProvider);
+                if (this.log.isDebugEnabled()) {
+                    this.log.debug("Re-using cached '" + authScheme.getName() + "' auth scheme for " + proxy);
+                }
+                proxyState.update(authScheme);
             }
         }
     }
 
-    private void doPreemptiveAuth(
-            final HttpHost host,
-            final AuthScheme authScheme,
-            final AuthState authState,
-            final CredentialsProvider credsProvider) {
-        final String schemeName = authScheme.getSchemeName();
-        if (this.log.isDebugEnabled()) {
-            this.log.debug("Re-using cached '" + schemeName + "' auth scheme for " + host);
-        }
-
-        final AuthScope authScope = new AuthScope(host, AuthScope.ANY_REALM, schemeName);
-        final Credentials creds = credsProvider.getCredentials(authScope);
-
-        if (creds != null) {
-            if ("BASIC".equalsIgnoreCase(authScheme.getSchemeName())) {
-                authState.setState(AuthProtocolState.CHALLENGED);
-            } else {
-                authState.setState(AuthProtocolState.SUCCESS);
-            }
-            authState.update(authScheme, creds);
-        } else {
-            this.log.debug("No credentials for preemptive authentication");
-        }
-    }
-
 }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/cookie/CookieAttributeHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/cookie/CookieAttributeHandler.java?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/cookie/CookieAttributeHandler.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/cookie/CookieAttributeHandler.java Thu Jul 23 10:00:46 2015
@@ -41,7 +41,7 @@ package org.apache.http.cookie;
 public interface CookieAttributeHandler {
 
   /**
-   * Parse the given cookie attribute value and update the corresponding
+   * Parse the given cookie attribute value and processChallenge the corresponding
    * {@link org.apache.http.cookie.Cookie} property.
    *
    * @param cookie {@link org.apache.http.cookie.Cookie} to be updated

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/cookie/CookiePriorityComparator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/cookie/CookiePriorityComparator.java?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/cookie/CookiePriorityComparator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/cookie/CookiePriorityComparator.java Thu Jul 23 10:00:46 2015
@@ -54,7 +54,7 @@ public class CookiePriorityComparator im
     public int compare(final Cookie c1, final Cookie c2) {
         final int l1 = getPathLength(c1);
         final int l2 = getPathLength(c2);
-        //TODO: update this class once Cookie interface has been expended with #getCreationTime method
+        //TODO: processChallenge this class once Cookie interface has been expended with #getCreationTime method
         final int result = l2 - l1;
         if (result == 0 && c1 instanceof BasicClientCookie && c2 instanceof BasicClientCookie) {
             final Date d1 = ((BasicClientCookie) c1).getCreationDate();

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=1692371&r1=1692370&r2=1692371&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 Thu Jul 23 10:00:46 2015
@@ -30,23 +30,29 @@ import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.ObjectStreamException;
+import java.io.Serializable;
 import java.nio.charset.Charset;
+import java.security.Principal;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
 
 import org.apache.commons.codec.binary.Base64;
 import org.apache.http.Consts;
-import org.apache.http.Header;
-import org.apache.http.HttpHeaders;
+import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
+import org.apache.http.NameValuePair;
 import org.apache.http.annotation.NotThreadSafe;
 import org.apache.http.auth.AuthChallenge;
+import org.apache.http.auth.AuthScheme;
+import org.apache.http.auth.AuthScope;
 import org.apache.http.auth.AuthenticationException;
-import org.apache.http.auth.ChallengeType;
 import org.apache.http.auth.Credentials;
+import org.apache.http.auth.CredentialsProvider;
 import org.apache.http.auth.MalformedChallengeException;
-import org.apache.http.message.BufferedHeader;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.util.Args;
-import org.apache.http.util.CharArrayBuffer;
 import org.apache.http.util.CharsetUtils;
 import org.apache.http.util.EncodingUtils;
 
@@ -56,17 +62,21 @@ import org.apache.http.util.EncodingUtil
  * @since 4.0
  */
 @NotThreadSafe
-public class BasicScheme extends StandardAuthScheme {
+public class BasicScheme implements AuthScheme, Serializable {
 
     private static final long serialVersionUID = -1931571557597830536L;
 
+    private final Map<String, String> paramMap;
     private transient Charset charset;
     private boolean complete;
+    private String username;
+    private String password;
 
     /**
      * @since 4.3
      */
     public BasicScheme(final Charset charset) {
+        this.paramMap = new HashMap<>();
         this.charset = charset != null ? charset : Consts.ASCII;
         this.complete = false;
     }
@@ -75,54 +85,88 @@ public class BasicScheme extends Standar
         this(Consts.ASCII);
     }
 
+    public void initPreemptive(final Credentials credentials) {
+        if (credentials != null) {
+            this.username = credentials.getUserPrincipal().getName();
+            this.password = credentials.getPassword();
+        } else {
+            this.username = null;
+            this.password = null;
+        }
+    }
+
     @Override
-    public String getSchemeName() {
+    public String getName() {
         return "basic";
     }
 
-    public void processChallenge(
-            final ChallengeType challengeType,
-            final AuthChallenge authChallenge) throws MalformedChallengeException {
-        update(challengeType, authChallenge);
-        this.complete = true;
+    @Override
+    public boolean isConnectionBased() {
+        return false;
     }
 
     @Override
-    public boolean isComplete() {
-        return this.complete;
+    public String getRealm() {
+        return this.paramMap.get("realm");
     }
 
     @Override
-    public boolean isConnectionBased() {
-        return false;
+    public void processChallenge(
+            final AuthChallenge authChallenge,
+            final HttpContext context) throws MalformedChallengeException {
+        this.paramMap.clear();
+        final List<NameValuePair> params = authChallenge.getParams();
+        if (params != null) {
+            for (NameValuePair param: params) {
+                this.paramMap.put(param.getName().toLowerCase(Locale.ROOT), param.getValue());
+            }
+        }
+        this.complete = true;
     }
 
     @Override
-    public Header authenticate(
-            final Credentials credentials,
-            final HttpRequest request,
+    public boolean isChallengeComplete() {
+        return this.complete;
+    }
+
+    @Override
+    public boolean isResponseReady(
+            final HttpHost host,
+            final CredentialsProvider credentialsProvider,
             final HttpContext context) throws AuthenticationException {
 
-        Args.notNull(credentials, "Credentials");
-        Args.notNull(request, "HTTP request");
-        final CharArrayBuffer buffer = new CharArrayBuffer(32);
-        if (isProxy()) {
-            buffer.append(HttpHeaders.PROXY_AUTHORIZATION);
+        Args.notNull(host, "Auth host");
+        Args.notNull(credentialsProvider, "CredentialsProvider");
+
+        final Credentials credentials = credentialsProvider.getCredentials(new AuthScope(host, getRealm(), getName()));
+        if (credentials != null) {
+            this.username = credentials.getUserPrincipal().getName();
+            this.password = credentials.getPassword();
+            return true;
         } else {
-            buffer.append(HttpHeaders.AUTHORIZATION);
+            this.username = null;
+            this.password = null;
+            return false;
         }
-        buffer.append(": Basic ");
+    }
 
-        final StringBuilder tmp = new StringBuilder();
-        tmp.append(credentials.getUserPrincipal().getName());
-        tmp.append(":");
-        tmp.append((credentials.getPassword() == null) ? "null" : credentials.getPassword());
+    @Override
+    public Principal getPrinciple() {
+        return null;
+    }
 
+    @Override
+    public String generateAuthResponse(
+            final HttpHost host,
+            final HttpRequest request,
+            final HttpContext context) throws AuthenticationException {
+        final StringBuilder buffer = new StringBuilder();
+        buffer.append(this.username);
+        buffer.append(":");
+        buffer.append(this.password);
         final Base64 base64codec = new Base64(0);
-        final byte[] base64password = base64codec.encode(EncodingUtils.getBytes(tmp.toString(), charset.name()));
-
-        buffer.append(base64password, 0, base64password.length);
-        return new BufferedHeader(buffer);
+        final byte[] encodedCreds = base64codec.encode(EncodingUtils.getBytes(buffer.toString(), charset.name()));
+        return "Basic " + new String(encodedCreds, 0, encodedCreds.length, Consts.ASCII);
     }
 
     private void writeObject(final ObjectOutputStream out) throws IOException {
@@ -142,4 +186,9 @@ public class BasicScheme extends Standar
     private void readObjectNoData() throws ObjectStreamException {
     }
 
+    @Override
+    public String toString() {
+        return this.paramMap.toString();
+    }
+
 }

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=1692371&r1=1692370&r2=1692371&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 Thu Jul 23 10:00:46 2015
@@ -27,30 +27,35 @@
 package org.apache.http.impl.auth;
 
 import java.io.IOException;
+import java.io.Serializable;
 import java.security.MessageDigest;
+import java.security.Principal;
 import java.security.SecureRandom;
 import java.util.ArrayList;
 import java.util.Formatter;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 import java.util.Set;
 import java.util.StringTokenizer;
 
-import org.apache.http.Header;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpEntityEnclosingRequest;
-import org.apache.http.HttpHeaders;
+import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
+import org.apache.http.NameValuePair;
 import org.apache.http.annotation.NotThreadSafe;
 import org.apache.http.auth.AuthChallenge;
+import org.apache.http.auth.AuthScheme;
+import org.apache.http.auth.AuthScope;
 import org.apache.http.auth.AuthenticationException;
-import org.apache.http.auth.ChallengeType;
 import org.apache.http.auth.Credentials;
+import org.apache.http.auth.CredentialsProvider;
 import org.apache.http.auth.MalformedChallengeException;
 import org.apache.http.message.BasicHeaderValueFormatter;
 import org.apache.http.message.BasicNameValuePair;
-import org.apache.http.message.BufferedHeader;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.util.Args;
 import org.apache.http.util.CharArrayBuffer;
@@ -71,7 +76,7 @@ import org.apache.http.util.EncodingUtil
  * @since 4.0
  */
 @NotThreadSafe
-public class DigestScheme extends StandardAuthScheme {
+public class DigestScheme implements AuthScheme, Serializable {
 
     private static final long serialVersionUID = 3883908186234566916L;
 
@@ -86,40 +91,71 @@ public class DigestScheme extends Standa
         'e', 'f'
     };
 
-    /** Whether the digest authentication process is complete */
-    private boolean complete;
-
     private static final int QOP_UNKNOWN = -1;
     private static final int QOP_MISSING = 0;
     private static final int QOP_AUTH_INT = 1;
     private static final int QOP_AUTH = 2;
 
+    private final Map<String, String> paramMap;
+    private boolean complete;
     private String lastNonce;
     private long nounceCount;
     private String cnonce;
     private String a1;
     private String a2;
 
+    private String username;
+    private String password;
+
     public DigestScheme() {
+        this.paramMap = new HashMap<>();
         this.complete = false;
     }
 
+    public void initPreemptive(final Credentials credentials, final String cnonce, final String realm) {
+        Args.notNull(credentials, "Credentials");
+        this.username = credentials.getUserPrincipal().getName();
+        this.password = credentials.getPassword();
+        this.paramMap.put("cnonce", cnonce);
+        this.paramMap.put("realm", realm);
+    }
+
+    @Override
+    public String getName() {
+        return "digest";
+    }
+
+    @Override
+    public boolean isConnectionBased() {
+        return false;
+    }
+
+    @Override
+    public String getRealm() {
+        return this.paramMap.get("realm");
+    }
+
     @Override
     public void processChallenge(
-            final ChallengeType challengeType,
-            final AuthChallenge authChallenge) throws MalformedChallengeException {
-        Args.notNull(challengeType, "ChallengeType");
+            final AuthChallenge authChallenge,
+            final HttpContext context) throws MalformedChallengeException {
         Args.notNull(authChallenge, "AuthChallenge");
-        update(challengeType, authChallenge);
-        if (getParameters().isEmpty()) {
+        this.paramMap.clear();
+        final List<NameValuePair> params = authChallenge.getParams();
+        if (params != null) {
+            for (NameValuePair param: params) {
+                this.paramMap.put(param.getName().toLowerCase(Locale.ROOT), param.getValue());
+            }
+        }
+        if (this.paramMap.isEmpty()) {
             throw new MalformedChallengeException("Missing digest auth parameters");
         }
         this.complete = true;
     }
 
     @Override
-    public boolean isComplete() {
-        final String s = getParameter("stale");
+    public boolean isChallengeComplete() {
+        final String s = this.paramMap.get("stale");
         if ("true".equalsIgnoreCase(s)) {
             return false;
         } else {
@@ -128,37 +164,45 @@ public class DigestScheme extends Standa
     }
 
     @Override
-    public String getSchemeName() {
-        return "digest";
-    }
+    public boolean isResponseReady(
+            final HttpHost host,
+            final CredentialsProvider credentialsProvider,
+            final HttpContext context) throws AuthenticationException {
 
-    @Override
-    public boolean isConnectionBased() {
-        return false;
+        Args.notNull(host, "Auth host");
+        Args.notNull(credentialsProvider, "CredentialsProvider");
+
+        final Credentials credentials = credentialsProvider.getCredentials(new AuthScope(host, getRealm(), getName()));
+        if (credentials != null) {
+            this.username = credentials.getUserPrincipal().getName();
+            this.password = credentials.getPassword();
+            return true;
+        } else {
+            this.username = null;
+            this.password = null;
+            return false;
+        }
     }
 
-    public void overrideParamter(final String name, final String value) {
-        getParameters().put(name, value);
+    @Override
+    public Principal getPrinciple() {
+        return null;
     }
 
     @Override
-    public Header authenticate(
-            final Credentials credentials,
+    public String generateAuthResponse(
+            final HttpHost host,
             final HttpRequest request,
             final HttpContext context) throws AuthenticationException {
 
-        Args.notNull(credentials, "Credentials");
         Args.notNull(request, "HTTP request");
-        if (getParameter("realm") == null) {
-            throw new AuthenticationException("missing realm in challenge");
+        if (this.paramMap.get("realm") == null) {
+            throw new AuthenticationException("missing realm");
         }
-        if (getParameter("nonce") == null) {
-            throw new AuthenticationException("missing nonce in challenge");
+        if (this.paramMap.get("nonce") == null) {
+            throw new AuthenticationException("missing nonce");
         }
-        // Add method name and request-URI to the parameter map
-        getParameters().put("methodname", request.getRequestLine().getMethod());
-        getParameters().put("uri", request.getRequestLine().getUri());
-        return createDigestHeader(credentials, request);
+        return createDigestResponse(request);
     }
 
     private static MessageDigest createMessageDigest(
@@ -172,15 +216,14 @@ public class DigestScheme extends Standa
         }
     }
 
-    private Header createDigestHeader(
-            final Credentials credentials,
-            final HttpRequest request) throws AuthenticationException {
-        final String uri = getParameter("uri");
-        final String realm = getParameter("realm");
-        final String nonce = getParameter("nonce");
-        final String opaque = getParameter("opaque");
-        final String method = getParameter("methodname");
-        String algorithm = getParameter("algorithm");
+    private String createDigestResponse(final HttpRequest request) throws AuthenticationException {
+
+        final String uri = request.getRequestLine().getUri();
+        final String method = request.getRequestLine().getMethod();
+        final String realm = this.paramMap.get("realm");
+        final String nonce = this.paramMap.get("nonce");
+        final String opaque = this.paramMap.get("opaque");
+        String algorithm = this.paramMap.get("algorithm");
         // If an algorithm is not specified, default to MD5.
         if (algorithm == null) {
             algorithm = "MD5";
@@ -188,7 +231,7 @@ public class DigestScheme extends Standa
 
         final Set<String> qopset = new HashSet<>(8);
         int qop = QOP_UNKNOWN;
-        final String qoplist = getParameter("qop");
+        final String qoplist = this.paramMap.get("qop");
         if (qoplist != null) {
             final StringTokenizer tok = new StringTokenizer(qoplist, ",");
             while (tok.hasMoreTokens()) {
@@ -208,7 +251,7 @@ public class DigestScheme extends Standa
             throw new AuthenticationException("None of the qop methods is supported: " + qoplist);
         }
 
-        String charset = getParameter("charset");
+        String charset = this.paramMap.get("charset");
         if (charset == null) {
             charset = "ISO-8859-1";
         }
@@ -225,9 +268,6 @@ public class DigestScheme extends Standa
             throw new AuthenticationException("Unsuppported digest algorithm: " + digAlg);
         }
 
-        final String uname = credentials.getUserPrincipal().getName();
-        final String pwd = credentials.getPassword();
-
         if (nonce.equals(this.lastNonce)) {
             nounceCount++;
         } else {
@@ -255,7 +295,7 @@ public class DigestScheme extends Standa
 
             // calculated one per session
             sb.setLength(0);
-            sb.append(uname).append(':').append(realm).append(':').append(pwd);
+            sb.append(username).append(':').append(realm).append(':').append(password);
             final String checksum = encode(digester.digest(EncodingUtils.getBytes(sb.toString(), charset)));
             sb.setLength(0);
             sb.append(checksum).append(':').append(nonce).append(':').append(cnonce);
@@ -263,7 +303,7 @@ public class DigestScheme extends Standa
         } else {
             // unq(username-value) ":" unq(realm-value) ":" passwd
             sb.setLength(0);
-            sb.append(uname).append(':').append(realm).append(':').append(pwd);
+            sb.append(username).append(':').append(realm).append(':').append(password);
             a1 = sb.toString();
         }
 
@@ -323,15 +363,10 @@ public class DigestScheme extends Standa
         final String digest = encode(digester.digest(EncodingUtils.getAsciiBytes(digestValue)));
 
         final CharArrayBuffer buffer = new CharArrayBuffer(128);
-        if (isProxy()) {
-            buffer.append(HttpHeaders.PROXY_AUTHORIZATION);
-        } else {
-            buffer.append(HttpHeaders.AUTHORIZATION);
-        }
-        buffer.append(": Digest ");
+        buffer.append("Digest ");
 
         final List<BasicNameValuePair> params = new ArrayList<>(20);
-        params.add(new BasicNameValuePair("username", uname));
+        params.add(new BasicNameValuePair("username", username));
         params.add(new BasicNameValuePair("realm", realm));
         params.add(new BasicNameValuePair("nonce", nonce));
         params.add(new BasicNameValuePair("uri", uri));
@@ -358,7 +393,7 @@ public class DigestScheme extends Standa
                     || "algorithm".equals(name));
             BasicHeaderValueFormatter.INSTANCE.formatNameValuePair(buffer, param, !noQuotes);
         }
-        return new BufferedHeader(buffer);
+        return buffer.toString();
     }
 
     String getCnonce() {
@@ -405,4 +440,9 @@ public class DigestScheme extends Standa
         return encode(tmp);
     }
 
+    @Override
+    public String toString() {
+        return this.paramMap.toString();
+    }
+
 }



Mime
View raw message