home *** CD-ROM | disk | FTP | other *** search
- package sun.net.www.protocol.http;
-
- import java.net.URL;
- import java.util.Hashtable;
- import sun.net.www.HeaderParser;
-
- abstract class AuthenticationInfo {
- static final char SERVER_AUTHENTICATION = 's';
- static final char PROXY_AUTHENTICATION = 'p';
- private static Hashtable cache = new Hashtable();
- char type;
- String host;
- int port;
- String realm;
- String path;
-
- AuthenticationInfo(char var1, String var2, int var3, String var4) {
- this.type = var1;
- this.host = var2;
- this.port = var3;
- this.realm = var4;
- this.path = null;
- }
-
- AuthenticationInfo(char var1, URL var2, String var3) {
- this.type = var1;
- this.host = var2.getHost();
- this.port = var2.getPort();
- this.realm = var3;
- String var4 = var2.getPath();
- if (var4.length() == 0) {
- this.path = var4;
- } else {
- int var5 = var4.lastIndexOf(47);
- int var6 = var4.lastIndexOf(46);
- if (var5 != -1) {
- if (var5 < var6) {
- this.path = var4.substring(0, var5 + 1);
- } else {
- this.path = var4;
- }
- } else {
- this.path = null;
- }
- }
-
- }
-
- static AuthenticationInfo getServerAuth(URL var0) {
- String var1 = "s:" + var0.getHost() + ":" + var0.getPort();
- return getAuth(var1, var0);
- }
-
- static AuthenticationInfo getServerAuth(URL var0, String var1) {
- String var2 = "s:" + var0.getHost() + ":" + var0.getPort() + ":" + var1;
- return getAuth(var2, var0);
- }
-
- private static AuthenticationInfo getAuth(String var0, URL var1) {
- AuthenticationInfo var2 = (AuthenticationInfo)cache.get(var0);
- if (var2 != null) {
- String var3 = var1.getPath();
- if (var2.path != null && !var3.startsWith(var2.path)) {
- var2 = null;
- }
- }
-
- return var2;
- }
-
- static AuthenticationInfo getProxyAuth(String var0, int var1) {
- String var2 = "p:" + var0 + ":" + var1;
- AuthenticationInfo var3 = (AuthenticationInfo)cache.get(var2);
- return var3;
- }
-
- static AuthenticationInfo getProxyAuth(String var0, int var1, String var2) {
- String var3 = "p:" + var0 + ":" + var1 + ":" + var2;
- AuthenticationInfo var4 = (AuthenticationInfo)cache.get(var3);
- return var4;
- }
-
- void addToCache() {
- cache.put(this.cacheKey(true), this);
- if (this.supportsPreemptiveAuthorization()) {
- cache.put(this.cacheKey(false), this);
- }
-
- }
-
- void removeFromCache() {
- cache.remove(this.cacheKey(true));
- if (this.supportsPreemptiveAuthorization()) {
- cache.remove(this.cacheKey(false));
- }
-
- }
-
- abstract boolean supportsPreemptiveAuthorization();
-
- abstract String getHeaderName();
-
- abstract String getHeaderValue();
-
- boolean setHeaders(HttpURLConnection var1, HeaderParser var2) {
- var1.setAuthenticationProperty(this.getHeaderName(), this.getHeaderValue());
- return true;
- }
-
- String cacheKey(boolean var1) {
- return var1 ? this.type + ":" + this.host + ":" + this.port + ":" + this.realm : this.type + ":" + this.host + ":" + this.port;
- }
- }
-