commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestAuthenticator.java
Date Fri, 08 Aug 2003 06:38:06 GMT
olegk       2003/08/07 23:38:06

  Modified:    httpclient/src/java/org/apache/commons/httpclient/auth Tag:
                        HTTPCLIENT_2_0_BRANCH HttpAuthenticator.java
               httpclient/src/test/org/apache/commons/httpclient Tag:
                        HTTPCLIENT_2_0_BRANCH TestAuthenticator.java
  Log:
  The patch addresses the problem with the proxy authentication realm reported by David Rowe
<David.Rowe2@conagrafoods.com>. HttpAuthenticator should now be picking up the correct
credentials when authenticating with an NTLM proxy (NTLM authentication does not support the
concept of authentication realm as defined in RFC2617)
  
  Contributed by Oleg Kalnichevski
  Reviewed by Michael Becke & Ortwin Glueck
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.7.2.1   +23 -12    jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/HttpAuthenticator.java
  
  Index: HttpAuthenticator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/HttpAuthenticator.java,v
  retrieving revision 1.7
  retrieving revision 1.7.2.1
  diff -u -r1.7 -r1.7.2.1
  --- HttpAuthenticator.java	26 May 2003 22:07:22 -0000	1.7
  +++ HttpAuthenticator.java	8 Aug 2003 06:38:06 -0000	1.7.2.1
  @@ -291,30 +291,41 @@
           }
           String host = null;
           if (conn != null) {
  -            host = proxy ? conn.getProxyHost() : conn.getHost();
  +            if (proxy) {
  +                host = conn.getProxyHost();
  +            } else {
  +                host = conn.getVirtualHost();
  +                if (host == null) {
  +                    host = conn.getHost();
  +                }
  +            }
           }
           String realm = authscheme.getRealm();
           // TODO: To be removed in the future. Required for backward compatibility
           if (realm == null) {
  -            Header hostheader = method.getRequestHeader("host");
  -            if (hostheader != null) {
  -                realm = hostheader.getValue();
  -            }
  +            realm = host;
           }
           if (LOG.isDebugEnabled()) {
  +            StringBuffer buffer = new StringBuffer();
  +            buffer.append("Authenticating with the "); 
               if (realm == null) {
  -                LOG.debug("Using default authentication realm");
  +                buffer.append("default");
               } else {
  -                LOG.debug("Using '" + realm + "' authentication realm");
  +                buffer.append('\'');
  +                buffer.append(authscheme.getRealm());
  +                buffer.append('\'');
               }
  +            buffer.append(" authentication realm at "); 
  +            buffer.append(host); 
  +            LOG.debug(buffer.toString());
           }
           Credentials credentials = proxy 
               ? state.getProxyCredentials(realm, host) 
               : state.getCredentials(realm, host);
           if (credentials == null) {
               throw new AuthenticationException(
  -                "No credentials available for the " + authscheme.getSchemeName() 
  -                + "authentication realm '" + realm + "'");
  +                "No credentials available for the '" + authscheme.getRealm() 
  +                + "' authentication realm at " + host);
           }
           String auth = authscheme.authenticate(credentials, method.getName(), method.getPath());
           if (auth != null) {
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.25.2.1  +7 -10     jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestAuthenticator.java
  
  Index: TestAuthenticator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestAuthenticator.java,v
  retrieving revision 1.25
  retrieving revision 1.25.2.1
  diff -u -r1.25 -r1.25.2.1
  --- TestAuthenticator.java	22 Apr 2003 17:00:26 -0000	1.25
  +++ TestAuthenticator.java	8 Aug 2003 06:38:06 -0000	1.25.2.1
  @@ -413,9 +413,8 @@
           HttpState state = new HttpState();
           NTCredentials cred = new NTCredentials("username","password", "host",
                   "domain");
  -        state.setCredentials("host", null, cred);
  +        state.setCredentials(null, null, cred);
           HttpMethod method = new SimpleHttpMethod(new Header("WwW-AuThEnTiCaTe", challenge));
  -        method.addRequestHeader("Host", "host");
           AuthScheme authscheme = new NTLMScheme(challenge);
           assertTrue(HttpAuthenticator.authenticate(authscheme, method, null, state));
           assertTrue(null != method.getRequestHeader("Authorization"));
  @@ -428,9 +427,8 @@
           HttpState state = new HttpState();
           NTCredentials cred = new NTCredentials("username","password", "host",
                   "domain");
  -        state.setCredentials("host", null, cred);
  +        state.setCredentials(null, null, cred);
           HttpMethod method = new SimpleHttpMethod(new Header("WWW-Authenticate", challenge));
  -        method.addRequestHeader("Host", "host");
           AuthScheme authscheme = new NTLMScheme(challenge);
           assertTrue(HttpAuthenticator.authenticate(authscheme, method, null, state));
           assertTrue(null != method.getRequestHeader("Authorization"));
  @@ -452,9 +450,8 @@
           HttpState state = new HttpState();
           NTCredentials cred = new NTCredentials("username","password", "host",
                   "domain");
  -        state.setCredentials("host", null, cred);
  +        state.setCredentials(null, null, cred);
           HttpMethod method = new SimpleHttpMethod(new Header("WWW-Authenticate", challenge));
  -        method.addRequestHeader("Host", "host");
           AuthScheme authscheme = new NTLMScheme(challenge);
           assertTrue(HttpAuthenticator.authenticate(authscheme, method, null, state));
           assertTrue(null != method.getRequestHeader("Authorization"));
  
  
  

Mime
View raw message