Return-Path: Delivered-To: apmail-hc-commits-archive@www.apache.org Received: (qmail 23120 invoked from network); 6 May 2008 18:18:00 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 6 May 2008 18:18:00 -0000 Received: (qmail 43259 invoked by uid 500); 6 May 2008 18:18:02 -0000 Delivered-To: apmail-hc-commits-archive@hc.apache.org Received: (qmail 43233 invoked by uid 500); 6 May 2008 18:18:02 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 43213 invoked by uid 99); 6 May 2008 18:18:02 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 06 May 2008 11:18:02 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 06 May 2008 18:17:16 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 3F17A238899B; Tue, 6 May 2008 11:17:31 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r653867 - in /httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth: AuthSchemeBase.java BasicScheme.java DigestScheme.java RFC2617Scheme.java Date: Tue, 06 May 2008 18:17:30 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080506181731.3F17A238899B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: olegk Date: Tue May 6 11:17:29 2008 New Revision: 653867 URL: http://svn.apache.org/viewvc?rev=653867&view=rev Log: Factored out AuthSchemeBase class from RFC2617Scheme Added: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/AuthSchemeBase.java - copied, changed from r653240, httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/BasicScheme.java httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/DigestScheme.java httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java Copied: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/AuthSchemeBase.java (from r653240, httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java) URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/AuthSchemeBase.java?p2=httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/AuthSchemeBase.java&p1=httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java&r1=653240&r2=653867&rev=653867&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java (original) +++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/AuthSchemeBase.java Tue May 6 11:17:29 2008 @@ -1,5 +1,5 @@ /* - * $HeadeURL$ + * $HeadURL$ * $Revision$ * $Date$ * @@ -30,47 +30,31 @@ package org.apache.http.impl.auth; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - -import org.apache.http.Header; -import org.apache.http.HeaderElement; import org.apache.http.FormattedHeader; -import org.apache.http.auth.AuthScheme; +import org.apache.http.Header; import org.apache.http.auth.AUTH; +import org.apache.http.auth.AuthScheme; import org.apache.http.auth.MalformedChallengeException; -import org.apache.http.message.BasicHeaderValueParser; -import org.apache.http.message.HeaderValueParser; -import org.apache.http.message.ParserCursor; import org.apache.http.protocol.HTTP; import org.apache.http.util.CharArrayBuffer; /** - *

- * Abstract authentication scheme class that lays foundation for all - * RFC 2617 compliant authetication schemes and provides capabilities common - * to all authentication schemes defined in RFC 2617. - *

+ * Abstract authentication scheme class that serves as a basis + * for all authentication schemes supported by HttpClient. This class + * defines the generic way of parsing an authentication challenge. It + * does not make any assumptions regarding the format of the challenge + * nor does it impose any specific way of responding to that challenge. * * @author Oleg Kalnichevski */ -public abstract class RFC2617Scheme implements AuthScheme { - - /** - * Authentication parameter map. - */ - private Map params; +public abstract class AuthSchemeBase implements AuthScheme { /** * Flag whether authenticating against a proxy. */ private boolean proxy; - /** - * Default constructor for RFC2617 compliant authetication schemes. - */ - public RFC2617Scheme() { + public AuthSchemeBase() { super(); } @@ -123,53 +107,12 @@ if (!s.equalsIgnoreCase(getSchemeName())) { throw new MalformedChallengeException("Invalid scheme identifier: " + s); } - HeaderValueParser parser = BasicHeaderValueParser.DEFAULT; - ParserCursor cursor = new ParserCursor(pos, buffer.length()); - HeaderElement[] elements = parser.parseElements(buffer, cursor); - if (elements.length == 0) { - throw new MalformedChallengeException("Authentication challenge is empty"); - } - this.params = new HashMap(elements.length); - for (HeaderElement element : elements) { - this.params.put(element.getName(), element.getValue()); - } + parseChallenge(buffer, pos, buffer.length()); } - /** - * Returns authentication parameters map. Keys in the map are lower-cased. - * - * @return the map of authentication parameters - */ - protected Map getParameters() { - return this.params; - } - - /** - * Returns authentication parameter with the given name, if available. - * - * @param name The name of the parameter to be returned - * - * @return the parameter with the given name - */ - public String getParameter(final String name) { - if (name == null) { - throw new IllegalArgumentException("Parameter name may not be null"); - } - if (this.params == null) { - return null; - } - return this.params.get(name.toLowerCase(Locale.ENGLISH)); - } - - /** - * Returns authentication realm. The realm may not be null. - * - * @return the authentication realm - */ - public String getRealm() { - return getParameter("realm"); - } + protected abstract void parseChallenge( + CharArrayBuffer buffer, int pos, int len) throws MalformedChallengeException; /** * Returns true if authenticating against a proxy, false Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/BasicScheme.java URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/BasicScheme.java?rev=653867&r1=653866&r2=653867&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/BasicScheme.java (original) +++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/BasicScheme.java Tue May 6 11:17:29 2008 @@ -162,15 +162,15 @@ throw new IllegalArgumentException("charset may not be null"); } - CharArrayBuffer buffer = new CharArrayBuffer(32); - buffer.append(credentials.getPrincipalName()); - buffer.append(":"); - buffer.append((credentials.getPassword() == null) ? "null" : credentials.getPassword()); + StringBuilder tmp = new StringBuilder(); + tmp.append(credentials.getPrincipalName()); + tmp.append(":"); + tmp.append((credentials.getPassword() == null) ? "null" : credentials.getPassword()); byte[] base64password = Base64.encodeBase64( - EncodingUtils.getBytes(buffer.toString(), charset)); + EncodingUtils.getBytes(tmp.toString(), charset)); - buffer.clear(); + CharArrayBuffer buffer = new CharArrayBuffer(32); if (proxy) { buffer.append(AUTH.PROXY_AUTH_RESP); } else { Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/DigestScheme.java URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/DigestScheme.java?rev=653867&r1=653866&r2=653867&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/DigestScheme.java (original) +++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/DigestScheme.java Tue May 6 11:17:29 2008 @@ -274,7 +274,7 @@ String pwd = credentials.getPassword(); // 3.2.2.2: Calculating digest - CharArrayBuffer tmp = new CharArrayBuffer(uname.length() + realm.length() + pwd.length() + 2); + StringBuilder tmp = new StringBuilder(uname.length() + realm.length() + pwd.length() + 2); tmp.append(uname); tmp.append(':'); tmp.append(realm); @@ -289,7 +289,7 @@ // ":" unq(cnonce-value) String tmp2=encode(md5Helper.digest(EncodingUtils.getBytes(a1, charset))); - CharArrayBuffer tmp3 = new CharArrayBuffer(tmp2.length() + nonce.length() + cnonce.length() + 2); + StringBuilder tmp3 = new StringBuilder(tmp2.length() + nonce.length() + cnonce.length() + 2); tmp3.append(tmp2); tmp3.append(':'); tmp3.append(nonce); @@ -314,7 +314,7 @@ // 3.2.2.1 String serverDigestValue; if (qopVariant == QOP_MISSING) { - CharArrayBuffer tmp2 = new CharArrayBuffer(md5a1.length() + nonce.length() + md5a2.length()); + StringBuilder tmp2 = new StringBuilder(md5a1.length() + nonce.length() + md5a2.length()); tmp2.append(md5a1); tmp2.append(':'); tmp2.append(nonce); @@ -323,7 +323,7 @@ serverDigestValue = tmp2.toString(); } else { String qopOption = getQopVariantString(); - CharArrayBuffer tmp2 = new CharArrayBuffer(md5a1.length() + nonce.length() + StringBuilder tmp2 = new StringBuilder(md5a1.length() + nonce.length() + NC.length() + cnonce.length() + qopOption.length() + md5a2.length() + 5); tmp2.append(md5a1); tmp2.append(':'); Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java?rev=653867&r1=653866&r2=653867&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java (original) +++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java Tue May 6 11:17:29 2008 @@ -1,5 +1,5 @@ /* - * $HeadeURL$ + * $HeadURL$ * $Revision$ * $Date$ * @@ -34,28 +34,21 @@ import java.util.Locale; import java.util.Map; -import org.apache.http.Header; import org.apache.http.HeaderElement; -import org.apache.http.FormattedHeader; -import org.apache.http.auth.AuthScheme; -import org.apache.http.auth.AUTH; import org.apache.http.auth.MalformedChallengeException; import org.apache.http.message.BasicHeaderValueParser; import org.apache.http.message.HeaderValueParser; import org.apache.http.message.ParserCursor; -import org.apache.http.protocol.HTTP; import org.apache.http.util.CharArrayBuffer; /** - *

* Abstract authentication scheme class that lays foundation for all * RFC 2617 compliant authetication schemes and provides capabilities common * to all authentication schemes defined in RFC 2617. - *

* * @author Oleg Kalnichevski */ -public abstract class RFC2617Scheme implements AuthScheme { +public abstract class RFC2617Scheme extends AuthSchemeBase { /** * Authentication parameter map. @@ -63,66 +56,15 @@ private Map params; /** - * Flag whether authenticating against a proxy. - */ - private boolean proxy; - - /** * Default constructor for RFC2617 compliant authetication schemes. */ public RFC2617Scheme() { super(); } - /** - * 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 header the challenge header - * - * @throws MalformedChallengeException is thrown if the authentication challenge - * is malformed - */ - public void processChallenge(final Header header) throws MalformedChallengeException { - if (header == null) { - throw new IllegalArgumentException("Header may not be null"); - } - String authheader = header.getName(); - if (authheader.equalsIgnoreCase(AUTH.WWW_AUTH)) { - this.proxy = false; - } else if (authheader.equalsIgnoreCase(AUTH.PROXY_AUTH)) { - this.proxy = true; - } else { - throw new MalformedChallengeException("Unexpected header name: " + authheader); - } - - CharArrayBuffer buffer; - int pos; - if (header instanceof FormattedHeader) { - buffer = ((FormattedHeader) header).getBuffer(); - pos = ((FormattedHeader) 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 scheme identifier: " + s); - } + @Override + protected void parseChallenge( + final CharArrayBuffer buffer, int pos, int len) throws MalformedChallengeException { HeaderValueParser parser = BasicHeaderValueParser.DEFAULT; ParserCursor cursor = new ParserCursor(pos, buffer.length()); HeaderElement[] elements = parser.parseElements(buffer, cursor); @@ -171,15 +113,4 @@ return getParameter("realm"); } - /** - * Returns true if authenticating against a proxy, false - * otherwise. - * - * @return true if authenticating against a proxy, false - * otherwise - */ - public boolean isProxy() { - return this.proxy; - } - }