Print this page


Split Close
Expand all
Collapse all
          --- old/src/share/classes/sun/net/www/protocol/http/AuthenticationInfo.java
          +++ new/src/share/classes/sun/net/www/protocol/http/AuthenticationInfo.java
↓ open down ↓ 17 lines elided ↑ open up ↑
  18   18   * 2 along with this work; if not, write to the Free Software Foundation,
  19   19   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20   20   *
  21   21   * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  22   22   * CA 95054 USA or visit www.sun.com if you need additional information or
  23   23   * have any questions.
  24   24   */
  25   25  
  26   26  package sun.net.www.protocol.http;
  27   27  
  28      -import java.io.*;
  29      -import java.net.*;
       28 +import java.io.IOException;
       29 +import java.io.ObjectInputStream;
       30 +import java.net.PasswordAuthentication;
       31 +import java.net.URL;
  30   32  import java.util.Hashtable;
  31   33  import java.util.LinkedList;
  32   34  import java.util.ListIterator;
  33   35  import java.util.Enumeration;
  34   36  import java.util.HashMap;
  35   37  
  36   38  import sun.net.www.HeaderParser;
  37   39  
  38   40  
  39   41  /**
↓ open down ↓ 4 lines elided ↑ open up ↑
  44   46   * @author Herb Jellinek
  45   47   * @author Bill Foote
  46   48   */
  47   49  // REMIND:  It would be nice if this class understood about partial matching.
  48   50  //      If you're authorized for foo.com, chances are high you're also
  49   51  //      authorized for baz.foo.com.
  50   52  // NB:  When this gets implemented, be careful about the uncaching
  51   53  //      policy in HttpURLConnection.  A failure on baz.foo.com shouldn't
  52   54  //      uncache foo.com!
  53   55  
  54      -abstract class AuthenticationInfo extends AuthCacheValue implements Cloneable {
       56 +public abstract class AuthenticationInfo extends AuthCacheValue implements Cloneable {
  55   57  
  56   58      // Constants saying what kind of authroization this is.  This determines
  57   59      // the namespace in the hash table lookup.
  58      -    static final char SERVER_AUTHENTICATION = 's';
  59      -    static final char PROXY_AUTHENTICATION = 'p';
       60 +    public static final char SERVER_AUTHENTICATION = 's';
       61 +    public static final char PROXY_AUTHENTICATION = 'p';
  60   62  
  61   63      /**
  62   64       * If true, then simultaneous authentication requests to the same realm/proxy
  63   65       * are serialized, in order to avoid a user having to type the same username/passwords
  64   66       * repeatedly, via the Authenticator. Default is false, which means that this
  65   67       * behavior is switched off.
  66   68       */
  67   69      static boolean serializeAuth;
  68   70  
  69   71      static {
↓ open down ↓ 111 lines elided ↑ open up ↑
 181  183      /** The port on the host we're authenticating against. */
 182  184      int port;
 183  185  
 184  186      /** The realm we're authenticating against. */
 185  187      String realm;
 186  188  
 187  189      /** The shortest path from the URL we authenticated against. */
 188  190      String path;
 189  191  
 190  192      /** Use this constructor only for proxy entries */
 191      -    AuthenticationInfo(char type, AuthScheme authScheme, String host, int port, String realm) {
      193 +    public AuthenticationInfo(char type, AuthScheme authScheme, String host, int port, String realm) {
 192  194          this.type = type;
 193  195          this.authScheme = authScheme;
 194  196          this.protocol = "";
 195  197          this.host = host.toLowerCase();
 196  198          this.port = port;
 197  199          this.realm = realm;
 198  200          this.path = null;
 199  201      }
 200  202  
 201  203      public Object clone() {
↓ open down ↓ 2 lines elided ↑ open up ↑
 204  206          } catch (CloneNotSupportedException e) {
 205  207              // Cannot happen because Cloneable implemented by AuthenticationInfo
 206  208              return null;
 207  209          }
 208  210      }
 209  211  
 210  212      /*
 211  213       * Constructor used to limit the authorization to the path within
 212  214       * the URL. Use this constructor for origin server entries.
 213  215       */
 214      -    AuthenticationInfo(char type, AuthScheme authScheme, URL url, String realm) {
      216 +    public AuthenticationInfo(char type, AuthScheme authScheme, URL url, String realm) {
 215  217          this.type = type;
 216  218          this.authScheme = authScheme;
 217  219          this.protocol = url.getProtocol().toLowerCase();
 218  220          this.host = url.getHost().toLowerCase();
 219  221          this.port = url.getPort();
 220  222          if (this.port == -1) {
 221  223              this.port = url.getDefaultPort();
 222  224          }
 223  225          this.realm = realm;
 224  226  
↓ open down ↓ 126 lines elided ↑ open up ↑
 351  353      void removeFromCache() {
 352  354          cache.remove(cacheKey(true), this);
 353  355          if (supportsPreemptiveAuthorization()) {
 354  356              cache.remove(cacheKey(false), this);
 355  357          }
 356  358      }
 357  359  
 358  360      /**
 359  361       * @return true if this authentication supports preemptive authorization
 360  362       */
 361      -    abstract boolean supportsPreemptiveAuthorization();
      363 +    public abstract boolean supportsPreemptiveAuthorization();
 362  364  
 363  365      /**
 364  366       * @return the name of the HTTP header this authentication wants set.
 365  367       *          This is used for preemptive authorization.
 366  368       */
 367      -    abstract String getHeaderName();
      369 +    public String getHeaderName() {
      370 +        if (type == SERVER_AUTHENTICATION) {
      371 +            return "Authorization";
      372 +        } else {
      373 +            return "Proxy-authorization";
      374 +        }
      375 +    }
 368  376  
 369  377      /**
 370  378       * Calculates and returns the authentication header value based
 371  379       * on the stored authentication parameters. If the calculation does not depend
 372  380       * on the URL or the request method then these parameters are ignored.
 373  381       * @param url The URL
 374  382       * @param method The request method
 375  383       * @return the value of the HTTP header this authentication wants set.
 376  384       *          Used for preemptive authorization.
 377  385       */
 378      -    abstract String getHeaderValue(URL url, String method);
      386 +    public abstract String getHeaderValue(URL url, String method);
 379  387  
 380  388      /**
 381  389       * Set header(s) on the given connection.  Subclasses must override
 382  390       * This will only be called for
 383  391       * definitive (i.e. non-preemptive) authorization.
 384  392       * @param conn The connection to apply the header(s) to
 385  393       * @param p A source of header values for this connection, if needed.
 386  394       * @param raw The raw header field (if needed)
 387  395       * @return true if all goes well, false if no headers were set.
 388  396       */
 389      -    abstract boolean setHeaders(HttpURLConnection conn, HeaderParser p, String raw);
      397 +    public abstract boolean setHeaders(HttpURLConnection conn, HeaderParser p, String raw);
 390  398  
 391  399      /**
 392  400       * Check if the header indicates that the current auth. parameters are stale.
 393  401       * If so, then replace the relevant field with the new value
 394  402       * and return true. Otherwise return false.
 395  403       * returning true means the request can be retried with the same userid/password
 396  404       * returning false means we have to go back to the user to ask for a new
 397  405       * username password.
 398  406       */
 399      -    abstract boolean isAuthorizationStale (String header);
      407 +    public abstract boolean isAuthorizationStale (String header);
 400  408  
 401  409      /**
 402  410       * Give a key for hash table lookups.
 403  411       * @param includeRealm if you want the realm considered.  Preemptively
 404  412       *          setting an authorization is done before the realm is known.
 405  413       */
 406  414      String cacheKey(boolean includeRealm) {
 407  415          // This must be kept in sync with the getXXXAuth() methods in this
 408  416          // class.
 409  417          if (includeRealm) {
↓ open down ↓ 25 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX