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:47:43 GMT
olegk       2003/08/07 23:47:43

  Modified:    httpclient/src/java/org/apache/commons/httpclient/auth
                        HttpAuthenticator.java
               httpclient/src/test/org/apache/commons/httpclient
                        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
  1.11      +24 -13    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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- HttpAuthenticator.java	22 Jul 2003 18:10:24 -0000	1.10
  +++ HttpAuthenticator.java	8 Aug 2003 06:47:43 -0000	1.11
  @@ -295,30 +295,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 CredentialsNotAvailableException(
  -                "No credentials available for the " + authscheme.getSchemeName() 
  -                + " authentication realm '" + realm + "'");
  +            throw new AuthenticationException(
  +                "No credentials available for the '" + authscheme.getRealm() 
  +                + "' authentication realm at " + host);
           }
           String auth = authscheme.authenticate(credentials, method.getName(), method.getPath());
           if (auth != null) {
  
  
  
  1.27      +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.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- TestAuthenticator.java	5 Jul 2003 22:31:21 -0000	1.26
  +++ TestAuthenticator.java	8 Aug 2003 06:47:43 -0000	1.27
  @@ -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