You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ol...@apache.org on 2003/08/12 20:46:47 UTC

cvs commit: jakarta-commons/httpclient/src/java/org/apache/commons/httpclient HttpMethodDirector.java

olegk       2003/08/12 11:46:47

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        HttpMethodDirector.java
  Log:
  The patch addresses the problem with the proxy authentication realm reported by David Rowe <Da...@conagrafoods.com>.
  
  HttpMethodDirector changed to correctly determine authentication realm
  
  Contributed by Oleg Kalnichevski
  
  Revision  Changes    Path
  1.2       +30 -24    jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodDirector.java
  
  Index: HttpMethodDirector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodDirector.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HttpMethodDirector.java	12 Aug 2003 02:35:17 -0000	1.1
  +++ HttpMethodDirector.java	12 Aug 2003 18:46:47 -0000	1.2
  @@ -510,14 +510,20 @@
   		// handle authentication required
   		Header[] challenges = null;
   		Set realmsUsed = null;
  +        String host = null;
   		switch (statusCode) {
   			case HttpStatus.SC_UNAUTHORIZED:
   				challenges = method.getResponseHeaders(HttpAuthenticator.WWW_AUTH);
   				realmsUsed = realms;
  +                host = conn.getVirtualHost();
  +                if (host == null) {
  +                    host = conn.getHost();
  +                }
   				break;
   			case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
                   challenges = method.getResponseHeaders(HttpAuthenticator.PROXY_AUTH);
   				realmsUsed = proxyRealms;
  +                host = conn.getProxyHost();
   				break;
   		}
   		boolean authenticated = false;
  @@ -538,27 +544,27 @@
   				return true;
   			}
           
  -			StringBuffer buffer = new StringBuffer();
  -			buffer.append(conn.getHost());
  -			int port = conn.getPort();
  -			if (conn.getProtocol().getDefaultPort() != port) {
  -				buffer.append(':');
  -				buffer.append(port);
  -			}
  -			buffer.append('#');
  -			buffer.append(authscheme.getID());
  -			String realm = buffer.toString();
  +            StringBuffer buffer = new StringBuffer();
  +            buffer.append(host);
  +            buffer.append('#');
  +            buffer.append(authscheme.getID());
  +            String realm = buffer.toString();
   
  -			if (realmsUsed.contains(realm)) {
  -				if (LOG.isInfoEnabled()) {
  -					LOG.info("Already tried to authenticate to \""
  -							 + realm + "\" but still receiving "
  -							 + statusCode + ".");
  -				}
  -				return true;
  -			} else {
  -				realmsUsed.add(realm);
  -			}
  +            if (realmsUsed.contains(realm)) {
  +                if (LOG.isInfoEnabled()) {
  +                    buffer = new StringBuffer();
  +                    buffer.append("Already tried to authenticate with '");
  +                    buffer.append(authscheme.getRealm());
  +                    buffer.append("' authentication realm at ");
  +                    buffer.append(host);
  +                    buffer.append(", but still receiving: ");
  +                    buffer.append(method.getStatusLine().toString());
  +                    LOG.info(buffer.toString());
  +                }
  +                return true;
  +            } else {
  +                realmsUsed.add(realm);
  +            }
   
   			try {
   				//remove preemptive header and reauthenticate