home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VPage / Java.bin / CLASSES.ZIP / sun / net / www / protocol / http / AuthenticationInfo.class (.txt) next >
Encoding:
Java Class File  |  1997-07-08  |  3.2 KB  |  107 lines

  1. package sun.net.www.protocol.http;
  2.  
  3. import java.net.URL;
  4. import java.util.Hashtable;
  5.  
  6. public class AuthenticationInfo {
  7.    static Hashtable preemptiveCache = new Hashtable();
  8.    static Hashtable cache = new Hashtable();
  9.    String host;
  10.    int port;
  11.    String realm;
  12.    String auth;
  13.  
  14.    public AuthenticationInfo(URL var1, String var2, String var3) {
  15.       this.host = var1.getHost();
  16.       this.port = var1.getPort();
  17.       this.auth = var3;
  18.       this.realm = var2;
  19.       cacheInfo(this, var1);
  20.    }
  21.  
  22.    public AuthenticationInfo(URL var1, String var2) {
  23.       this.realm = "";
  24.       this.host = var1.getHost();
  25.       this.port = var1.getPort();
  26.       this.auth = var2;
  27.       cacheInfo(this, var1);
  28.    }
  29.  
  30.    public AuthenticationInfo(String var1, int var2, String var3) {
  31.       this.host = var1;
  32.       this.port = var2;
  33.       this.realm = var3;
  34.    }
  35.  
  36.    public AuthenticationInfo(String var1, int var2, String var3, String var4) {
  37.       this(var1, var2, var3);
  38.       this.auth = var4;
  39.       cacheInfo(this);
  40.    }
  41.  
  42.    public static void cacheInfo(AuthenticationInfo var0) {
  43.       cache.put(var0, var0);
  44.    }
  45.  
  46.    public static void cacheInfo(AuthenticationInfo var0, URL var1) {
  47.       cacheInfo(var0);
  48.       preemptiveCache.put(cacheKey(var1), var0);
  49.    }
  50.  
  51.    public static void uncacheInfo(AuthenticationInfo var0) {
  52.       cache.remove(var0);
  53.    }
  54.  
  55.    public static void uncacheInfo(AuthenticationInfo var0, URL var1) {
  56.       uncacheInfo(var0);
  57.       preemptiveCache.remove(cacheKey(var1));
  58.    }
  59.  
  60.    private void dumpCaches(String var1) {
  61.       System.err.println("\n" + var1);
  62.       System.err.println("\nCache:\n" + cache + "\n\nPreemptiveCache:\n" + preemptiveCache + "\n");
  63.    }
  64.  
  65.    public static AuthenticationInfo getAuth(URL var0) {
  66.       AuthenticationInfo var1 = (AuthenticationInfo)preemptiveCache.get(cacheKey(var0));
  67.       return var1;
  68.    }
  69.  
  70.    public static AuthenticationInfo getAuth(URL var0, String var1) {
  71.       AuthenticationInfo var2 = null;
  72.       if (var1 == null) {
  73.          var2 = getAuth(var0);
  74.       } else {
  75.          AuthenticationInfo var3 = new AuthenticationInfo(var0.getHost(), var0.getPort(), var1);
  76.          var2 = (AuthenticationInfo)cache.get(var3);
  77.       }
  78.  
  79.       return var2;
  80.    }
  81.  
  82.    public String getAuthString() {
  83.       return "Basic " + this.auth;
  84.    }
  85.  
  86.    static String cacheKey(URL var0) {
  87.       return var0.getHost() + ":" + var0.getPort();
  88.    }
  89.  
  90.    public int hashCode() {
  91.       return this.host.hashCode() ^ this.port ^ this.realm.hashCode();
  92.    }
  93.  
  94.    public boolean equals(Object var1) {
  95.       if (var1 instanceof AuthenticationInfo) {
  96.          AuthenticationInfo var2 = (AuthenticationInfo)var1;
  97.          return var2.host.equals(this.host) && var2.port == this.port && var2.realm.equals(this.realm);
  98.       } else {
  99.          return false;
  100.       }
  101.    }
  102.  
  103.    public String toString() {
  104.       return "AuthenticationInfo[" + this.realm + "@" + this.host + ":" + this.port + "]->" + this.auth;
  105.    }
  106. }
  107.