--- a/jdk/src/share/classes/sun/net/www/protocol/http/NegotiateAuthentication.java Mon Oct 19 16:31:48 2009 -0700
+++ b/jdk/src/share/classes/sun/net/www/protocol/http/NegotiateAuthentication.java Wed Oct 21 15:41:42 2009 +0100
@@ -25,17 +25,13 @@
package sun.net.www.protocol.http;
+import java.net.URL;
+import java.io.IOException;
+import java.net.Authenticator.RequestorType;
import java.util.HashMap;
-
import sun.net.www.HeaderParser;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
-import sun.util.logging.PlatformLogger;
-
-import java.net.URL;
-import java.io.IOException;
-import java.net.Authenticator.RequestorType;
-import java.lang.reflect.Constructor;
import static sun.net.www.protocol.http.AuthScheme.NEGOTIATE;
import static sun.net.www.protocol.http.AuthScheme.KERBEROS;
@@ -78,7 +74,8 @@
/**
* @return true if this authentication supports preemptive authorization
*/
- boolean supportsPreemptiveAuthorization() {
+ @Override
+ public boolean supportsPreemptiveAuthorization() {
return false;
}
@@ -104,34 +101,24 @@
return supported.get(hostname);
}
- try {
- Negotiator neg = Negotiator.getSupported(hci);
+ Negotiator neg = Negotiator.getNegotiator(hci);
+ if (neg != null) {
supported.put(hostname, true);
// the only place cache.put is called. here we can make sure
// the object is valid and the oneToken inside is not null
cache.put(hostname, neg);
return true;
- } catch(Exception e) {
+ } else {
supported.put(hostname, false);
return false;
}
}
/**
- * @return the name of the HTTP header this authentication wants to set
- */
- String getHeaderName() {
- if (type == SERVER_AUTHENTICATION) {
- return "Authorization";
- } else {
- return "Proxy-Authorization";
- }
- }
-
- /**
* Not supported. Must use the setHeaders() method
*/
- String getHeaderValue(URL url, String method) {
+ @Override
+ public String getHeaderValue(URL url, String method) {
throw new RuntimeException ("getHeaderValue not supported");
}
@@ -143,7 +130,8 @@
* returning false means we have to go back to the user to ask for a new
* username password.
*/
- boolean isAuthorizationStale (String header) {
+ @Override
+ public boolean isAuthorizationStale (String header) {
return false; /* should not be called for Negotiate */
}
@@ -155,7 +143,8 @@
* @param raw The raw header field.
* @return true if all goes well, false if no headers were set.
*/
- synchronized boolean setHeaders(HttpURLConnection conn, HeaderParser p, String raw) {
+ @Override
+ public synchronized boolean setHeaders(HttpURLConnection conn, HeaderParser p, String raw) {
try {
String response;
@@ -177,7 +166,7 @@
/**
* return the first token.
* @returns the token
- * @throws IOException if <code>Negotiator.getSupported()</code> or
+ * @throws IOException if <code>Negotiator.getNegotiator()</code> or
* <code>Negotiator.firstToken()</code> failed.
*/
private byte[] firstToken() throws IOException {
@@ -191,11 +180,9 @@
}
}
if (negotiator == null) {
- try {
- negotiator = Negotiator.getSupported(hci);
- } catch(Exception e) {
+ negotiator = Negotiator.getNegotiator(hci);
+ if (negotiator == null) {
IOException ioe = new IOException("Cannot initialize Negotiator");
- ioe.initCause(e);
throw ioe;
}
}
@@ -228,55 +215,3 @@
// Currently we ignore this header.
}
-
-/**
- * This abstract class is a bridge to connect NegotiteAuthentication and
- * NegotiatorImpl, so that JAAS and JGSS calls can be made
- */
-abstract class Negotiator {
- static Negotiator getSupported(HttpCallerInfo hci)
- throws Exception {
-
- // These lines are equivalent to
- // return new NegotiatorImpl(hci);
- // The current implementation will make sure NegotiatorImpl is not
- // directly referenced when compiling, thus smooth the way of building
- // the J2SE platform where HttpURLConnection is a bootstrap class.
- //
- // Makes NegotiatorImpl, and the security classes it references, a
- // runtime dependency rather than a static one.
-
- Class clazz;
- Constructor c;
- try {
- clazz = Class.forName("sun.net.www.protocol.http.NegotiatorImpl", true, null);
- c = clazz.getConstructor(HttpCallerInfo.class);
- } catch (ClassNotFoundException cnfe) {
- finest(cnfe);
- throw cnfe;
- } catch (ReflectiveOperationException roe) {
- // if the class is there then something seriously wrong if
- // the constructor is not.
- throw new AssertionError(roe);
- }
-
- try {
- return (Negotiator) (c.newInstance(hci));
- } catch (ReflectiveOperationException roe) {
- finest(roe);
- Throwable t = roe.getCause();
- if (t != null && t instanceof Exception)
- finest((Exception)t);
- throw roe;
- }
- }
-
- abstract byte[] firstToken() throws IOException;
-
- abstract byte[] nextToken(byte[] in) throws IOException;
-
- static void finest(Exception e) {
- PlatformLogger logger = HttpURLConnection.getHttpLogger();
- logger.finest("NegotiateAuthentication: " + e);
- }
-}