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/java/org/apache/commons/httpclient/auth BasicScheme.java DigestScheme.java HttpAuthenticator.java NTLM.java NTLMScheme.java
Date Tue, 22 Jul 2003 18:10:26 GMT
olegk       2003/07/22 11:10:25

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        HttpMethodBase.java
               httpclient/src/java/org/apache/commons/httpclient/auth
                        BasicScheme.java DigestScheme.java
                        HttpAuthenticator.java NTLM.java NTLMScheme.java
  Log:
  Bug fix #19868(Exception handling in HttpClient requires redesign)
  
  Handling of authentication exceptions refactored.
  
  Contributed by Oleg Kalnichevski
  Reviewed by Adrian Sutton
  
  Revision  Changes    Path
  1.171     +14 -6     jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java
  
  Index: HttpMethodBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
  retrieving revision 1.170
  retrieving revision 1.171
  diff -u -r1.170 -r1.171
  --- HttpMethodBase.java	19 Jul 2003 09:41:37 -0000	1.170
  +++ HttpMethodBase.java	22 Jul 2003 18:10:22 -0000	1.171
  @@ -73,6 +73,7 @@
   
   import org.apache.commons.httpclient.auth.AuthScheme;
   import org.apache.commons.httpclient.auth.AuthenticationException;
  +import org.apache.commons.httpclient.auth.CredentialsNotAvailableException;
   import org.apache.commons.httpclient.auth.HttpAuthenticator;
   import org.apache.commons.httpclient.auth.MalformedChallengeException;
   import org.apache.commons.httpclient.cookie.CookiePolicy;
  @@ -857,7 +858,7 @@
   
           // Connection must be closed due to an abnormal circumstance 
           if (isConnectionCloseForced()) {
  -            LOG.debug("Should forcefully close connection.");
  +            LOG.debug("Should force-close connection.");
               return true;
           }
   
  @@ -2438,8 +2439,15 @@
                           this.proxyRealm = authscheme.getRealm();
                           break;
                   }
  +            } catch (CredentialsNotAvailableException e) {
  +                if (LOG.isWarnEnabled()) {
  +                    LOG.warn(e.getMessage());
  +                }
  +                return true; // finished request
               } catch (AuthenticationException e) {
  -                LOG.warn(e.getMessage());
  +                if (LOG.isErrorEnabled()) {
  +                    LOG.error(e.getMessage(), e);
  +                }
                   return true; // finished request
               }
               if (!authenticated) {
  
  
  
  1.5       +6 -4      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/BasicScheme.java
  
  Index: BasicScheme.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/BasicScheme.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BasicScheme.java	26 May 2003 22:07:22 -0000	1.4
  +++ BasicScheme.java	22 Jul 2003 18:10:24 -0000	1.5
  @@ -119,6 +119,8 @@
        * @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
        * 
  @@ -133,7 +135,7 @@
           try {
               usernamepassword = (UsernamePasswordCredentials) credentials;
           } catch (ClassCastException e) {
  -            throw new AuthenticationException(
  +            throw new InvalidCredentialsException(
                "Credentials cannot be used for basic authentication: " 
                 + credentials.toString());
           }
  
  
  
  1.5       +6 -4      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/DigestScheme.java
  
  Index: DigestScheme.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/DigestScheme.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DigestScheme.java	26 May 2003 22:07:22 -0000	1.4
  +++ DigestScheme.java	22 Jul 2003 18:10:24 -0000	1.5
  @@ -135,6 +135,8 @@
        * @param method the name of the method that requires authorization. 
        * @param uri The URI for which authorization is needed. 
        * 
  +     * @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
        * 
  @@ -152,7 +154,7 @@
           try {
               usernamepassword = (UsernamePasswordCredentials) credentials;
           } catch (ClassCastException e) {
  -            throw new AuthenticationException(
  +            throw new InvalidCredentialsException(
                "Credentials cannot be used for basic authentication: " 
                 + credentials.toString());
           }
  
  
  
  1.10      +14 -6     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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- HttpAuthenticator.java	15 Jul 2003 23:35:06 -0000	1.9
  +++ HttpAuthenticator.java	22 Jul 2003 18:10:24 -0000	1.10
  @@ -201,7 +201,7 @@
               return false;
           }
           if (!(credentials instanceof UsernamePasswordCredentials)) {
  -            throw new AuthenticationException(
  +            throw new InvalidCredentialsException(
                "Credentials cannot be used for basic authentication: " 
                 + credentials.toString());
           }
  @@ -230,8 +230,10 @@
        * @return true if the <tt>Authenticate</tt> response header 
        *   was added
        * 
  +     * @throws InvalidCredentialsException if authentication credentials
  +     *         are not valid or not applicable for basic scheme
        * @throws AuthenticationException when a parsing or other error occurs
  -
  +     *
        * @see HttpState#setCredentials(String,String,Credentials)
        */
       public static boolean authenticateDefault(
  @@ -259,6 +261,8 @@
        * @return true if the <tt>Proxy-Authenticate</tt> response header 
        *   was added
        * 
  +     * @throws InvalidCredentialsException if authentication credentials
  +     *         are not valid or not applicable for basic scheme
        * @throws AuthenticationException when a parsing or other error occurs
   
        * @see HttpState#setCredentials(String,String,Credentials)
  @@ -312,7 +316,7 @@
               ? state.getProxyCredentials(realm, host) 
               : state.getCredentials(realm, host);
           if (credentials == null) {
  -            throw new AuthenticationException(
  +            throw new CredentialsNotAvailableException(
                   "No credentials available for the " + authscheme.getSchemeName() 
                   + " authentication realm '" + realm + "'");
           }
  @@ -340,6 +344,8 @@
        * 
        * @return true if the <tt>Authenticate</tt> response header was added
        * 
  +     * @throws CredentialsNotAvailableException if authentication credentials
  +     *         required to respond to the authentication challenge are not available
        * @throws AuthenticationException when a parsing or other error occurs
   
        * @see HttpState#setCredentials(String,String,Credentials)
  @@ -372,6 +378,8 @@
        * @return true if the <tt>Proxy-Authenticate</tt> response header 
        *  was added
        * 
  +     * @throws CredentialsNotAvailableException if authentication credentials
  +     *         required to respond to the authentication challenge are not available
        * @throws AuthenticationException when a parsing or other error occurs
   
        * @see HttpState#setCredentials(String,String,Credentials)
  
  
  
  1.3       +13 -14    jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/NTLM.java
  
  Index: NTLM.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/NTLM.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- NTLM.java	15 Jul 2003 02:19:58 -0000	1.2
  +++ NTLM.java	22 Jul 2003 18:10:25 -0000	1.3
  @@ -75,7 +75,6 @@
   import javax.crypto.spec.SecretKeySpec;
   
   import org.apache.commons.httpclient.HttpConstants;
  -import org.apache.commons.httpclient.HttpException;
   import org.apache.commons.httpclient.util.Base64;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  @@ -148,7 +147,7 @@
        */
       public final String getResponseFor(String message,
               String username, String password, String host, String domain)
  -            throws HttpException {
  +            throws AuthenticationException {
                   
           final String response;
           if (message == null || message.trim().equals("")) {
  @@ -164,9 +163,9 @@
        * Return the cipher for the specified key.
        * @param key The key.
        * @return Cipher The cipher.
  -     * @throws HttpException If the cipher cannot be retrieved.
  +     * @throws AuthenticationException If the cipher cannot be retrieved.
        */
  -    private Cipher getCipher(byte[] key) throws HttpException {
  +    private Cipher getCipher(byte[] key) throws AuthenticationException {
           try {
               final Cipher ecipher = Cipher.getInstance("DES/ECB/NoPadding");
               key = setupKey(key);
  @@ -218,7 +217,7 @@
        * @throws HttpException If {@link Cipher.doFinal(byte[])} fails
        */
       private byte[] encrypt(byte[] key, byte[] bytes)
  -        throws HttpException {
  +        throws AuthenticationException {
           Cipher ecipher = getCipher(key);
           try {
               byte[] enc = ecipher.doFinal(bytes);
  @@ -378,11 +377,11 @@
        * @param domain The domain.
        * @param nonce the 8 byte array the server sent.
        * @return The type 3 message.
  -     * @throws HttpException If {@encrypt(byte[],byte[])} fails.
  +     * @throws AuthenticationException If {@encrypt(byte[],byte[])} fails.
        */
       private String getType3Message(String user, String password,
               String host, String domain, byte[] nonce)
  -    throws HttpException {
  +    throws AuthenticationException {
   
           int ntRespLen = 0;
           int lmRespLen = 24;
  @@ -480,7 +479,7 @@
        * @throws HttpException If {@link #encrypt(byte[],byte[])} fails.
        */
       private byte[] hashPassword(String password, byte[] nonce)
  -        throws HttpException {
  +        throws AuthenticationException {
           byte[] passw = getBytes(password.toUpperCase());
           byte[] lmPw1 = new byte[7];
           byte[] lmPw2 = new byte[7];
  @@ -546,10 +545,10 @@
        * @param keys The keys.
        * @param plaintext The plain text to encrypt.
        * @param results Where the results are stored.
  -     * @throws HttpException If {@link #encrypt(byte[],byte[])} fails.
  +     * @throws AuthenticationException If {@link #encrypt(byte[],byte[])} fails.
        */
       private void calcResp(byte[] keys, byte[] plaintext, byte[] results)
  -        throws HttpException {
  +        throws AuthenticationException {
           byte[] keys1 = new byte[7];
           byte[] keys2 = new byte[7];
           byte[] keys3 = new byte[7];
  
  
  
  1.9       +9 -13     jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/NTLMScheme.java
  
  Index: NTLMScheme.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/NTLMScheme.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- NTLMScheme.java	15 Jul 2003 02:19:58 -0000	1.8
  +++ NTLMScheme.java	22 Jul 2003 18:10:25 -0000	1.9
  @@ -63,7 +63,6 @@
   
   package org.apache.commons.httpclient.auth;
   
  -import org.apache.commons.httpclient.HttpException;
   import org.apache.commons.httpclient.Credentials;
   import org.apache.commons.httpclient.NTCredentials;
   import org.apache.commons.logging.Log;
  @@ -189,14 +188,9 @@
           }
           
           NTLM ntlm = new NTLM();
  -        String s = null;
  -        try {
  -            s = ntlm.getResponseFor(challenge,
  -              credentials.getUserName(), credentials.getPassword(),
  -              credentials.getHost(), credentials.getDomain());
  -        } catch (HttpException e) {
  -            throw new AuthenticationException(e.getMessage(), e);
  -        }
  +        String s = ntlm.getResponseFor(challenge,
  +        credentials.getUserName(), credentials.getPassword(),
  +        credentials.getHost(), credentials.getDomain());
           return "NTLM " + s;
       }
       
  @@ -207,6 +201,8 @@
        * @param credentials The set of credentials to be used for athentication
        * @param method Method name is ignored by the NTLM authentication scheme
        * @param uri URI is ignored by the NTLM 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
        * 
  @@ -220,7 +216,7 @@
           try {
               ntcredentials = (NTCredentials) credentials;
           } catch (ClassCastException e) {
  -            throw new AuthenticationException(
  +            throw new InvalidCredentialsException(
                "Credentials cannot be used for NTLM authentication: " 
                 + credentials.toString());
           }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message