hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r526919 - in /jakarta/httpcomponents/httpclient/trunk/src: java/org/apache/http/auth/ java/org/apache/http/auth/params/ java/org/apache/http/impl/auth/ java/org/apache/http/impl/conn/ test/org/apache/http/impl/auth/
Date Mon, 09 Apr 2007 21:10:11 GMT
Author: olegk
Date: Mon Apr  9 14:10:01 2007
New Revision: 526919

URL: http://svn.apache.org/viewvc?view=rev&rev=526919
Log:
Ported RFC2617Scheme from Commons HttpClient

Added:
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/HTTPAuth.java  
(with props)
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/params/
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/params/AuthParams.java
  (with props)
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/auth/
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/auth/BasicScheme.java
      - copied, changed from r526469, jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/auth/BasicScheme.java
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/auth/RFC2617Scheme.java
      - copied, changed from r526468, jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/auth/RFC2617Scheme.java
    jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/auth/
    jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/auth/TestAllAuthImpl.java
  (with props)
    jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/auth/TestRFC2617Scheme.java
  (with props)
Modified:
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/AuthScheme.java
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/Credentials.java
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/Wire.java

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/AuthScheme.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/AuthScheme.java?view=diff&rev=526919&r1=526918&r2=526919
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/AuthScheme.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/AuthScheme.java
Mon Apr  9 14:10:01 2007
@@ -134,6 +134,7 @@
      * 
      * @return the authorization string
      */
-    Header authenticate(Credentials credentials, HttpMessage message) throws AuthenticationException;
+    Header authenticate(Credentials credentials, HttpMessage message) 
+            throws AuthenticationException;
     
 }

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/Credentials.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/Credentials.java?view=diff&rev=526919&r1=526918&r2=526919
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/Credentials.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/Credentials.java
Mon Apr  9 14:10:01 2007
@@ -32,13 +32,19 @@
 
 /**
  * <p>Authentication credentials.</p>
- * <p>
- * This  is just a marker interface, the  current implementation has no methods.
- * </p>
+ * 
  * @author Unascribed
  * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
  * 
  * @version $Revision$ $Date$
  */
 public interface Credentials {
+    
+    /** Returns textual representation of the user credentials, which, for instance,
+     * could be sent in the {@link HTTPAuth#WWW_AUTH} header.
+     * 
+     * @return user credentials as a string of text
+     */ 
+    String toText();
+    
 }

Added: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/HTTPAuth.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/HTTPAuth.java?view=auto&rev=526919
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/HTTPAuth.java (added)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/HTTPAuth.java Mon
Apr  9 14:10:01 2007
@@ -0,0 +1,66 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * 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;
+
+/**
+ * Constants and static helpers related to the HTTP authentication.
+ * 
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @since 4.0
+ */
+public final class HTTPAuth {
+
+    /**
+     * The www authenticate challange header.
+     */
+    public static final String WWW_AUTH = "WWW-Authenticate";
+
+    /**
+     * The www authenticate response header.
+     */
+    public static final String WWW_AUTH_RESP = "Authorization";
+
+    /**
+     * The proxy authenticate challange header.
+     */
+    public static final String PROXY_AUTH = "Proxy-Authenticate";
+
+    /**
+     * The proxy authenticate response header.
+     */
+    public static final String PROXY_AUTH_RESP = "Proxy-Authorization";
+    
+    private HTTPAuth() {
+    }
+       
+}

Propchange: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/HTTPAuth.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

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

Added: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/params/AuthParams.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/params/AuthParams.java?view=auto&rev=526919
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/params/AuthParams.java
(added)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/params/AuthParams.java
Mon Apr  9 14:10:01 2007
@@ -0,0 +1,93 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * 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.params;
+
+import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.HTTP;
+
+/**
+ * This class implements an adaptor around the {@link HttpParams} interface
+ * to simplify manipulation of the HTTP authentication specific parameters.
+ * 
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ * 
+ * @version $Revision$
+ * 
+ * @since 4.0
+ */
+public final class AuthParams {
+
+    /**
+     * Defines the charset to be used when encoding 
+     * {@link org.apache.http.auth.Credentials}. If not defined then the 
+     * {@link #HTTP_ELEMENT_CHARSET} should be used.
+     * <p>
+     * This parameter expects a value of type {@link String}.
+     * </p>
+     */
+    public static final String CREDENTIAL_CHARSET = "http.protocol.credential-charset"; 
+    
+    
+    private AuthParams() {
+        super();
+    }
+
+    /**
+     * Returns the charset to be used when encoding {@link org.apache.http.auth.Credentials}.
+     * If not configured the {@link HTTP.DEFAULT_PROTOCOL_CHARSET} is used instead.
+     * 
+     * @return The charset
+     */
+    public static String getCredentialCharset(final HttpParams params) {
+        if (params == null) {
+            throw new IllegalArgumentException("HTTP parameters may not be null");
+        }
+        String charset = (String) params.getParameter(CREDENTIAL_CHARSET);
+        if (charset == null) {
+            charset = HTTP.DEFAULT_PROTOCOL_CHARSET;
+        }
+        return charset;
+    }
+    
+    /**
+     * Sets the charset to be used when encoding {@link org.apache.http.auth.Credentials}.
+     * 
+     * @param charset The charset
+     */
+    public static void setCredentialCharset(final HttpParams params, final String charset)
{
+        if (params == null) {
+            throw new IllegalArgumentException("HTTP parameters may not be null");
+        }
+        params.setParameter(CREDENTIAL_CHARSET, charset);
+    }
+
+}

Propchange: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/params/AuthParams.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

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

Copied: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/auth/BasicScheme.java
(from r526469, jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/auth/BasicScheme.java)
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/auth/BasicScheme.java?view=diff&rev=526919&p1=jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/auth/BasicScheme.java&r1=526469&p2=jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/auth/BasicScheme.java&r2=526919
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/auth/BasicScheme.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/auth/BasicScheme.java
Mon Apr  9 14:10:01 2007
@@ -1,5 +1,5 @@
 /*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/auth/BasicScheme.java,v
1.17 2004/05/13 04:02:00 mbecke Exp $
+ * $HeadURL$
  * $Revision$
  * $Date$
  *
@@ -28,15 +28,19 @@
  *
  */
 
-package org.apache.commons.httpclient.auth;
+package org.apache.http.impl.auth;
 
 import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.httpclient.Credentials;
-import org.apache.commons.httpclient.HttpMethod;
-import org.apache.commons.httpclient.UsernamePasswordCredentials;
-import org.apache.commons.httpclient.util.EncodingUtil;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.http.Header;
+import org.apache.http.HttpMessage;
+import org.apache.http.auth.AuthenticationException;
+import org.apache.http.auth.Credentials;
+import org.apache.http.auth.HTTPAuth;
+import org.apache.http.auth.MalformedChallengeException;
+import org.apache.http.auth.params.AuthParams;
+import org.apache.http.message.BufferedHeader;
+import org.apache.http.util.CharArrayBuffer;
+import org.apache.http.util.EncodingUtils;
 
 /**
  * <p>
@@ -46,18 +50,15 @@
  * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
  * @author Rodney Waldhoff
  * @author <a href="mailto:jsdever@apache.org">Jeff Dever</a>
- * @author Ortwin Gl?ck
+ * @author Ortwin Glueck
  * @author Sean C. Sullivan
  * @author <a href="mailto:adrian@ephox.com">Adrian Sutton</a>
  * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
- * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  */
 
 public class BasicScheme extends RFC2617Scheme {
     
-    /** Log object for this class. */
-    private static final Log LOG = LogFactory.getLog(BasicScheme.class);
-    
     /** Whether the basic authentication process is complete */
     private boolean complete;
     
@@ -72,22 +73,6 @@
     }
 
     /**
-     * Constructor for the basic authetication scheme.
-     * 
-     * @param challenge authentication challenge
-     * 
-     * @throws MalformedChallengeException is thrown if the authentication challenge
-     * is malformed
-     * 
-     * @deprecated Use parameterless constructor and {@link AuthScheme#processChallenge(String)}

-     *             method
-     */
-    public BasicScheme(final String challenge) throws MalformedChallengeException {
-        super(challenge);
-        this.complete = true;
-    }
-
-    /**
      * Returns textual designation of the basic authentication scheme.
      * 
      * @return <code>basic</code>
@@ -106,10 +91,9 @@
      * 
      * @since 3.0
      */
-    public void processChallenge(String challenge) 
-        throws MalformedChallengeException 
-    {
-        super.processChallenge(challenge);
+    public void processChallenge(
+            final Header header) throws MalformedChallengeException {
+        super.processChallenge(header);
         this.complete = true;
     }
 
@@ -126,38 +110,6 @@
     }
 
     /**
-     * Produces basic authorization string for the given set of 
-     * {@link Credentials}.
-     * 
-     * @param credentials The set of credentials to be used for athentication
-     * @param method Method name is ignored by the basic authentication scheme
-     * @param uri URI is ignored by the basic authentication scheme
-     * @throws InvalidCredentialsException if authentication credentials
-     *         are not valid or not applicable for this authentication scheme
-     * @throws AuthenticationException if authorization string cannot 
-     *   be generated due to an authentication failure
-     * 
-     * @return a basic authorization string
-     * 
-     * @deprecated Use {@link #authenticate(Credentials, HttpMethod)}
-     */
-    public String authenticate(Credentials credentials, String method, String uri)
-      throws AuthenticationException {
-
-        LOG.trace("enter BasicScheme.authenticate(Credentials, String, String)");
-
-        UsernamePasswordCredentials usernamepassword = null;
-        try {
-            usernamepassword = (UsernamePasswordCredentials) credentials;
-        } catch (ClassCastException e) {
-            throw new InvalidCredentialsException(
-             "Credentials cannot be used for basic authentication: " 
-              + credentials.getClass().getName());
-        }
-        return BasicScheme.authenticate(usernamepassword);
-    }
-
-    /**
      * Returns <tt>false</tt>. Basic authentication scheme is request based.
      * 
      * @return <tt>false</tt>.
@@ -169,10 +121,10 @@
     }
 
     /**
-     * Produces basic authorization string for the given set of {@link Credentials}.
+     * Produces basic authorization header for the given set of {@link Credentials}.
      * 
      * @param credentials The set of credentials to be used for athentication
-     * @param method The method being authenticated
+     * @param message The message being authenticated
      * @throws InvalidCredentialsException if authentication credentials
      *         are not valid or not applicable for this authentication scheme
      * @throws AuthenticationException if authorization string cannot 
@@ -180,70 +132,52 @@
      * 
      * @return a basic authorization string
      * 
-     * @since 3.0
+     * @since 4.0
      */
-    public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException
{
-
-        LOG.trace("enter BasicScheme.authenticate(Credentials, HttpMethod)");
+    public Header authenticate(
+            final Credentials credentials, 
+            final HttpMessage message) throws AuthenticationException {
 
-        if (method == null) {
-            throw new IllegalArgumentException("Method may not be null");
+        if (credentials == null) {
+            throw new IllegalArgumentException("Credentials may not be null");
         }
-        UsernamePasswordCredentials usernamepassword = null;
-        try {
-            usernamepassword = (UsernamePasswordCredentials) credentials;
-        } catch (ClassCastException e) {
-            throw new InvalidCredentialsException(
-                    "Credentials cannot be used for basic authentication: " 
-                    + credentials.getClass().getName());
+        if (message == null) {
+            throw new IllegalArgumentException("HTTP message may not be null");
         }
-        return BasicScheme.authenticate(
-            usernamepassword, 
-            method.getParams().getCredentialCharset());
+        
+        String charset = AuthParams.getCredentialCharset(message.getParams());
+        return authenticate(credentials, charset);
     }
     
     /**
-     * @deprecated Use {@link #authenticate(UsernamePasswordCredentials, String)}
-     * 
      * Returns a basic <tt>Authorization</tt> header value for the given 
-     * {@link UsernamePasswordCredentials}.
-     * 
-     * @param credentials The credentials to encode.
-     * 
-     * @return a basic authorization string
-     */
-    public static String authenticate(UsernamePasswordCredentials credentials) {
-        return authenticate(credentials, "ISO-8859-1");
-    }
-
-    /**
-     * Returns a basic <tt>Authorization</tt> header value for the given 
-     * {@link UsernamePasswordCredentials} and charset.
+     * {@link Credentials} and charset.
      * 
      * @param credentials The credentials to encode.
      * @param charset The charset to use for encoding the credentials
      * 
-     * @return a basic authorization string
+     * @return a basic authorization header
      * 
-     * @since 3.0
+     * @since 4.0
      */
-    public static String authenticate(UsernamePasswordCredentials credentials, String charset)
{
-
-        LOG.trace("enter BasicScheme.authenticate(UsernamePasswordCredentials, String)");
-
+    public static Header authenticate(final Credentials credentials, final String charset)
{
         if (credentials == null) {
             throw new IllegalArgumentException("Credentials may not be null"); 
         }
-        if (charset == null || charset.length() == 0) {
-            throw new IllegalArgumentException("charset may not be null or empty");
+        if (charset == null) {
+            throw new IllegalArgumentException("charset may not be null");
         }
-        StringBuffer buffer = new StringBuffer();
-        buffer.append(credentials.getUserName());
-        buffer.append(":");
-        buffer.append(credentials.getPassword());
+        CharArrayBuffer buffer = new CharArrayBuffer(32);
+        buffer.append(HTTPAuth.WWW_AUTH_RESP);
+        buffer.append(": ");
+        buffer.append("Basic ");
+        
+        byte[] passwd = Base64.encodeBase64(
+                EncodingUtils.getBytes(credentials.toText(), charset));
+        
+        buffer.append(passwd, 0, passwd.length);
         
-        return "Basic " + EncodingUtil.getAsciiString(
-                Base64.encodeBase64(EncodingUtil.getBytes(buffer.toString(), charset)));
+        return new BufferedHeader(buffer);
     }
     
 }

Copied: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/auth/RFC2617Scheme.java
(from r526468, jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/auth/RFC2617Scheme.java)
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/auth/RFC2617Scheme.java?view=diff&rev=526919&p1=jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/auth/RFC2617Scheme.java&r1=526468&p2=jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/auth/RFC2617Scheme.java&r2=526919
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/auth/RFC2617Scheme.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/auth/RFC2617Scheme.java
Mon Apr  9 14:10:01 2007
@@ -1,5 +1,5 @@
 /*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/auth/RFC2617Scheme.java,v
1.10 2004/05/13 04:02:00 mbecke Exp $
+ * $HeadeURL$
  * $Revision$
  * $Date$
  *
@@ -28,10 +28,21 @@
  *
  */
 
-package org.apache.commons.httpclient.auth;
+package org.apache.http.impl.auth;
 
+import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.http.Header;
+import org.apache.http.HeaderElement;
+import org.apache.http.auth.AuthScheme;
+import org.apache.http.auth.HTTPAuth;
+import org.apache.http.auth.MalformedChallengeException;
+import org.apache.http.message.BasicHeaderElement;
+import org.apache.http.message.BufferedHeader;
+import org.apache.http.protocol.HTTP;
+import org.apache.http.util.CharArrayBuffer;
+
 /**
  * <p>
  * Abstract authentication scheme class that lays foundation for all
@@ -39,7 +50,7 @@
  * to all authentication schemes defined in RFC 2617.
  * </p>
  *
- * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
 */
 public abstract class RFC2617Scheme implements AuthScheme {
 
@@ -58,22 +69,6 @@
     }
 
     /**
-     * Default constructor for RFC2617 compliant authetication schemes.
-     * 
-     * @param challenge authentication challenge
-     * 
-     * @throws MalformedChallengeException is thrown if the authentication challenge
-     * is malformed
-     * 
-     * @deprecated Use parameterless constructor and {@link AuthScheme#processChallenge(String)}

-     *             method
-     */
-    public RFC2617Scheme(final String challenge) throws MalformedChallengeException {
-        super();
-        processChallenge(challenge);
-    }
-
-    /**
      * 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 
@@ -85,13 +80,45 @@
      * 
      * @since 3.0
      */
-    public void processChallenge(final String challenge) throws MalformedChallengeException
{
-        String s = AuthChallengeParser.extractScheme(challenge);
+    public void processChallenge(final Header header) throws MalformedChallengeException
{
+        if (header == null) {
+            throw new IllegalArgumentException("Header may not be null");
+        }
+        if (!header.getName().equalsIgnoreCase(HTTPAuth.WWW_AUTH)) {
+            throw new MalformedChallengeException("Unexpected header name: " + header.getName());
+        }
+        CharArrayBuffer buffer;
+        int pos;
+        if (header instanceof BufferedHeader) {
+            buffer = ((BufferedHeader) header).getBuffer();
+            pos = ((BufferedHeader) header).getValuePos();
+        } else {
+            String s = header.getValue();
+            if (s == null) {
+                throw new MalformedChallengeException("Header value is null");
+            }
+            buffer = new CharArrayBuffer(s.length());
+            buffer.append(s);
+            pos = 0;
+        }
+        while (pos < buffer.length() && HTTP.isWhitespace(buffer.charAt(pos)))
{
+            pos++;
+        }
+        int beginIndex = pos;
+        while (pos < buffer.length() && !HTTP.isWhitespace(buffer.charAt(pos)))
{
+            pos++;
+        }
+        int endIndex = pos;
+        String s = buffer.substring(beginIndex, endIndex);
         if (!s.equalsIgnoreCase(getSchemeName())) {
-            throw new MalformedChallengeException(
-              "Invalid " + getSchemeName() + " challenge: " + challenge); 
+            throw new MalformedChallengeException("Invalid scheme identifier: " + s);
+        }
+        HeaderElement[] elements = BasicHeaderElement.parseAll(buffer, pos, buffer.length());
+        this.params = new HashMap(elements.length);
+        for (int i = 0; i < elements.length; i++) {
+            HeaderElement element = elements[i];
+            this.params.put(element.getName(), element.getValue());
         }
-        this.params = AuthChallengeParser.extractParams(challenge);
     }
 
     /**
@@ -110,7 +137,7 @@
      * 
      * @return the parameter with the given name
      */
-    public String getParameter(String name) {
+    public String getParameter(final String name) {
         if (name == null) {
             throw new IllegalArgumentException("Parameter name may not be null"); 
         }
@@ -129,27 +156,4 @@
         return getParameter("realm");
     }
     
-    /**
-     * Returns a String identifying the authentication challenge.  This is
-     * used, in combination with the host and port to determine if
-     * authorization has already been attempted or not.  Schemes which
-     * require multiple requests to complete the authentication should
-     * return a different value for each stage in the request.
-     * 
-     * <p>Additionally, the ID should take into account any changes to the
-     * authentication challenge and return a different value when appropriate.
-     * For example when the realm changes in basic authentication it should be
-     * considered a different authentication attempt and a different value should
-     * be returned.</p>
-     * 
-     * <p>This method simply returns the realm for the challenge.</p>
-     * 
-     * @return String a String identifying the authentication challenge.  The
-     * returned value may be null.
-     * 
-     * @deprecated no longer used
-     */
-    public String getID() {
-        return getRealm();
-    }
 }

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/Wire.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/Wire.java?view=diff&rev=526919&r1=526918&r2=526919
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/Wire.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/Wire.java Mon
Apr  9 14:10:01 2007
@@ -42,7 +42,7 @@
  * 
  * @since 2.0beta1
  */
-class Wire {
+public class Wire {
 
     private Log log;
     

Added: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/auth/TestAllAuthImpl.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/auth/TestAllAuthImpl.java?view=auto&rev=526919
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/auth/TestAllAuthImpl.java
(added)
+++ jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/auth/TestAllAuthImpl.java
Mon Apr  9 14:10:01 2007
@@ -0,0 +1,56 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ * ====================================================================
+ * 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.impl.auth;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class TestAllAuthImpl extends TestCase {
+
+    public TestAllAuthImpl(String testName) {
+        super(testName);
+    }
+
+    public static Test suite() {
+        TestSuite suite = new TestSuite();
+
+        suite.addTest(TestRFC2617Scheme.suite());
+
+        return suite;
+    }
+
+    public static void main(String args[]) {
+        String[] testCaseName = { TestAllAuthImpl.class.getName() };
+        junit.textui.TestRunner.main(testCaseName);
+    }
+
+}

Propchange: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/auth/TestAllAuthImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/auth/TestAllAuthImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/auth/TestRFC2617Scheme.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/auth/TestRFC2617Scheme.java?view=auto&rev=526919
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/auth/TestRFC2617Scheme.java
(added)
+++ jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/auth/TestRFC2617Scheme.java
Mon Apr  9 14:10:01 2007
@@ -0,0 +1,131 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ * ====================================================================
+ * 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.impl.auth;
+
+import org.apache.http.Header;
+import org.apache.http.HttpMessage;
+import org.apache.http.auth.AuthenticationException;
+import org.apache.http.auth.Credentials;
+import org.apache.http.auth.HTTPAuth;
+import org.apache.http.auth.MalformedChallengeException;
+import org.apache.http.message.BasicHeader;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class TestRFC2617Scheme extends TestCase {
+
+
+    // ------------------------------------------------------------ Constructor
+
+    public TestRFC2617Scheme(String name) {
+        super(name);
+    }
+
+    // ------------------------------------------------------- TestCase Methods
+
+    public static Test suite() {
+        return new TestSuite(TestRFC2617Scheme.class);
+    }
+
+    static class TestAuthScheme extends RFC2617Scheme {
+
+        public Header authenticate(
+                final Credentials credentials, 
+                final HttpMessage message) throws AuthenticationException {
+            return null;
+        }
+
+        public String getSchemeName() {
+            return "test";
+        }
+
+        public boolean isComplete() {
+            return false;
+        }
+
+        public boolean isConnectionBased() {
+            return false;
+        }
+        
+    }
+
+    public void testProcessChallenge() throws Exception {
+        TestAuthScheme authscheme = new TestAuthScheme();
+        Header header = new BasicHeader(
+                HTTPAuth.WWW_AUTH,
+                "Test realm=\"realm1\", test, test1 =  stuff, test2 =  \"stuff, stuff\",
test3=\"crap");
+        
+        authscheme.processChallenge(header);
+        
+        assertEquals("test", authscheme.getSchemeName());
+        assertEquals("realm1", authscheme.getParameter("realm"));
+        assertEquals(null, authscheme.getParameter("test"));
+        assertEquals("stuff", authscheme.getParameter("test1"));
+        assertEquals("stuff, stuff", authscheme.getParameter("test2"));
+        assertEquals("\"crap", authscheme.getParameter("test3"));
+    }
+
+    public void testProcessChallengeWithLotsOfBlanks() throws Exception {
+        TestAuthScheme authscheme = new TestAuthScheme();
+        Header header = new BasicHeader(HTTPAuth.WWW_AUTH, "     Test       realm=\"realm1\"");
+        
+        authscheme.processChallenge(header);
+        
+        assertEquals("test", authscheme.getSchemeName());
+        assertEquals("realm1", authscheme.getParameter("realm"));
+    }
+
+    public void testInvalidHeader() throws Exception {
+        TestAuthScheme authscheme = new TestAuthScheme();
+        Header header = new BasicHeader("whatever", "Test realm=\"realm1\"");
+        try {
+            authscheme.processChallenge(header);
+            fail("MalformedChallengeException should have been thrown");
+        } catch (MalformedChallengeException ex) {
+            //expected
+        }
+    }
+    
+    public void testInvalidHeaderValue() throws Exception {
+        TestAuthScheme authscheme = new TestAuthScheme();
+        Header header = new BasicHeader("whatever", "whatever");
+        try {
+            authscheme.processChallenge(header);
+            fail("MalformedChallengeException should have been thrown");
+        } catch (MalformedChallengeException ex) {
+            //expected
+        }
+    }
+
+}
+

Propchange: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/auth/TestRFC2617Scheme.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/auth/TestRFC2617Scheme.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message