src/share/classes/sun/net/www/protocol/http/NegotiateAuthentication.java

Print this page

        

@@ -23,21 +23,17 @@
  * have any questions.
  */
 
 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;
 
 /**
  * NegotiateAuthentication:

@@ -76,11 +72,12 @@
     }
 
     /**
      * @return true if this authentication supports preemptive authorization
      */
-    boolean supportsPreemptiveAuthorization() {
+    @Override
+    public boolean supportsPreemptiveAuthorization() {
         return false;
     }
 
     /**
      * Find out if the HttpCallerInfo supports Negotiate protocol. In order to

@@ -102,38 +99,28 @@
         hostname = hostname.toLowerCase();
         if (supported.containsKey(hostname)) {
             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");
     }
 
     /**
      * Check if the header indicates that the current auth. parameters are stale.

@@ -141,11 +128,12 @@
      * 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.
      */
-    boolean isAuthorizationStale (String header) {
+    @Override
+    public boolean isAuthorizationStale (String header) {
         return false; /* should not be called for Negotiate */
     }
 
     /**
      * Set header(s) on the given connection.

@@ -153,11 +141,12 @@
      * @param p A source of header values for this connection, not used because
      *          HeaderParser converts the fields to lower case, use raw instead
      * @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;
             byte[] incoming = null;
             String[] parts = raw.split("\\s+");

@@ -175,11 +164,11 @@
     }
 
     /**
      * 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 {
         negotiator = null;
         if (cache != null) {

@@ -189,15 +178,13 @@
                     cache.remove(getHost()); // so that it is only used once
                 }
             }
         }
         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;
             }
         }
 
         return negotiator.firstToken();

@@ -225,58 +212,6 @@
     // if the server can be trusted. This is not the same concept as Digest's
     // Authentication-Info header.
     //
     // 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);
-    }
 }