src/share/classes/sun/net/www/protocol/http/AuthenticationInfo.java
Print this page
@@ -23,12 +23,14 @@
* have any questions.
*/
package sun.net.www.protocol.http;
-import java.io.*;
-import java.net.*;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.net.PasswordAuthentication;
+import java.net.URL;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Enumeration;
import java.util.HashMap;
@@ -49,16 +51,16 @@
// authorized for baz.foo.com.
// NB: When this gets implemented, be careful about the uncaching
// policy in HttpURLConnection. A failure on baz.foo.com shouldn't
// uncache foo.com!
-abstract class AuthenticationInfo extends AuthCacheValue implements Cloneable {
+public abstract class AuthenticationInfo extends AuthCacheValue implements Cloneable {
// Constants saying what kind of authroization this is. This determines
// the namespace in the hash table lookup.
- static final char SERVER_AUTHENTICATION = 's';
- static final char PROXY_AUTHENTICATION = 'p';
+ public static final char SERVER_AUTHENTICATION = 's';
+ public static final char PROXY_AUTHENTICATION = 'p';
/**
* If true, then simultaneous authentication requests to the same realm/proxy
* are serialized, in order to avoid a user having to type the same username/passwords
* repeatedly, via the Authenticator. Default is false, which means that this
@@ -186,11 +188,11 @@
/** The shortest path from the URL we authenticated against. */
String path;
/** Use this constructor only for proxy entries */
- AuthenticationInfo(char type, AuthScheme authScheme, String host, int port, String realm) {
+ public AuthenticationInfo(char type, AuthScheme authScheme, String host, int port, String realm) {
this.type = type;
this.authScheme = authScheme;
this.protocol = "";
this.host = host.toLowerCase();
this.port = port;
@@ -209,11 +211,11 @@
/*
* Constructor used to limit the authorization to the path within
* the URL. Use this constructor for origin server entries.
*/
- AuthenticationInfo(char type, AuthScheme authScheme, URL url, String realm) {
+ public AuthenticationInfo(char type, AuthScheme authScheme, URL url, String realm) {
this.type = type;
this.authScheme = authScheme;
this.protocol = url.getProtocol().toLowerCase();
this.host = url.getHost().toLowerCase();
this.port = url.getPort();
@@ -356,17 +358,23 @@
}
/**
* @return true if this authentication supports preemptive authorization
*/
- abstract boolean supportsPreemptiveAuthorization();
+ public abstract boolean supportsPreemptiveAuthorization();
/**
* @return the name of the HTTP header this authentication wants set.
* This is used for preemptive authorization.
*/
- abstract String getHeaderName();
+ public String getHeaderName() {
+ if (type == SERVER_AUTHENTICATION) {
+ return "Authorization";
+ } else {
+ return "Proxy-authorization";
+ }
+ }
/**
* Calculates and returns the authentication header value based
* on the stored authentication parameters. If the calculation does not depend
* on the URL or the request method then these parameters are ignored.
@@ -373,11 +381,11 @@
* @param url The URL
* @param method The request method
* @return the value of the HTTP header this authentication wants set.
* Used for preemptive authorization.
*/
- abstract String getHeaderValue(URL url, String method);
+ public abstract String getHeaderValue(URL url, String method);
/**
* Set header(s) on the given connection. Subclasses must override
* This will only be called for
* definitive (i.e. non-preemptive) authorization.
@@ -384,21 +392,21 @@
* @param conn The connection to apply the header(s) to
* @param p A source of header values for this connection, if needed.
* @param raw The raw header field (if needed)
* @return true if all goes well, false if no headers were set.
*/
- abstract boolean setHeaders(HttpURLConnection conn, HeaderParser p, String raw);
+ public abstract boolean setHeaders(HttpURLConnection conn, HeaderParser p, String raw);
/**
* Check if the header indicates that the current auth. parameters are stale.
* If so, then replace the relevant field with the new value
* and return true. Otherwise return false.
* returning true means the request can be retried with the same userid/password
* returning false means we have to go back to the user to ask for a new
* username password.
*/
- abstract boolean isAuthorizationStale (String header);
+ public abstract boolean isAuthorizationStale (String header);
/**
* Give a key for hash table lookups.
* @param includeRealm if you want the realm considered. Preemptively
* setting an authorization is done before the realm is known.