home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / prog / VJ11 / VJTRIAL.EXE / IE30Java.exe / classd.exe / sun / net / www / http / AuthenticationInfo.java < prev    next >
Encoding:
Java Source  |  1997-01-27  |  3.0 KB  |  112 lines

  1. /*
  2.  * @(#)AuthenticationInfo.java    1.6 95/09/18 Jonathan Payne
  3.  *
  4.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. package sun.net.www.http;
  21.  
  22. import java.net.URL;
  23. import java.util.Hashtable;
  24.  
  25. public class AuthenticationInfo {
  26.     String  host;
  27.     int        port;
  28.     String  realm;
  29.     String  auth;
  30.  
  31.     static Hashtable    cache = new Hashtable();
  32.     static Hashtable     preemptiveCache = new Hashtable();
  33.  
  34.     public static void cacheInfo(AuthenticationInfo info) {
  35.     cache.put(info, info);
  36.     }
  37.  
  38.     public static void uncacheInfo(AuthenticationInfo info) {
  39.     cache.remove(info);
  40.     }
  41.  
  42.     public static void cacheInfo(AuthenticationInfo info, URL url) {
  43.     cacheInfo(info);
  44.     preemptiveCache.put(url, info);
  45.     }
  46.  
  47.     public static void uncacheInfo(AuthenticationInfo info, URL url) {
  48.     uncacheInfo(info);
  49.     preemptiveCache.remove(url);
  50.     }
  51.  
  52.     public static AuthenticationInfo getAuth(URL url) {
  53.     AuthenticationInfo info = (AuthenticationInfo)
  54.         preemptiveCache.get(url);
  55.     return info;
  56.     }
  57.     
  58.     public static AuthenticationInfo getAuth(URL url, String realm) {
  59.     AuthenticationInfo  info = (AuthenticationInfo)
  60.         cache.get(new AuthenticationInfo(url.getHost(),
  61.                          url.getPort(), realm));
  62.  
  63.     return info;
  64.     }
  65.  
  66.     public AuthenticationInfo(URL url, String realm, String auth) {
  67.     this(url, auth);
  68.     this.realm = realm;
  69.     }
  70.  
  71.     public AuthenticationInfo(URL url, String auth) {
  72.     this.realm = "";
  73.     this.host = url.getHost();
  74.     this.port = url.getPort();
  75.     this.auth = auth;
  76.     cacheInfo(this, url);
  77.     }
  78.     
  79.     public AuthenticationInfo(String host, int port, String realm) {
  80.     this.host = host;
  81.     this.port = port;
  82.     this.realm = realm;
  83.     }
  84.  
  85.     public AuthenticationInfo(String host, int port, String realm, String auth) {
  86.     this(host, port, realm);
  87.     this.auth = auth;
  88.     cacheInfo(this);
  89.     }
  90.  
  91.     public int hashCode() {
  92.     return host.hashCode() ^ port ^ realm.hashCode();
  93.     }
  94.  
  95.  
  96.     public boolean equals(Object o) {
  97.     if (o instanceof AuthenticationInfo) {
  98.         AuthenticationInfo    i = (AuthenticationInfo) o;
  99.  
  100.         return i.host.equals(host) && i.port == port &&
  101.         i.realm.equals(realm);
  102.     }
  103.     return false;
  104.     }
  105.  
  106.     public String toString() {
  107.     return "AuthenticationInfo[" + realm + "@" + host + ":" + port + "] -> "+
  108.         auth;
  109.        
  110.     }
  111. }
  112.