< prev index next >

src/java.base/share/classes/sun/net/www/protocol/http/AuthenticationHeader.java

Print this page
rev 14210 : 8154231: Simplify access to System properties from JDK code
Reviewed-by: rriggs


   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.net.www.protocol.http;
  27 
  28 import sun.net.www.*;
  29 import java.util.Iterator;
  30 import java.util.HashMap;


  31 
  32 /**
  33  * This class is used to parse the information in WWW-Authenticate: and Proxy-Authenticate:
  34  * headers. It searches among multiple header lines and within each header line
  35  * for the best currently supported scheme. It can also return a HeaderParser
  36  * containing the challenge data for that particular scheme.
  37  *
  38  * Some examples:
  39  *
  40  * WWW-Authenticate: Basic realm="foo" Digest realm="bar" NTLM
  41  *  Note the realm parameter must be associated with the particular scheme.
  42  *
  43  * or
  44  *
  45  * WWW-Authenticate: Basic realm="foo"
  46  * WWW-Authenticate: Digest realm="foo",qop="auth",nonce="thisisanunlikelynonce"
  47  * WWW-Authenticate: NTLM
  48  *
  49  * or
  50  *


  76  * This also means that the real "Kerberos" scheme can never be set as a preference.
  77  */
  78 
  79 public class AuthenticationHeader {
  80 
  81     MessageHeader rsp; // the response to be parsed
  82     HeaderParser preferred;
  83     String preferred_r; // raw Strings
  84     private final HttpCallerInfo hci;   // un-schemed, need check
  85 
  86     // When set true, do not use Negotiate even if the response
  87     // headers suggest so.
  88     boolean dontUseNegotiate = false;
  89     static String authPref=null;
  90 
  91     public String toString() {
  92         return "AuthenticationHeader: prefer " + preferred_r;
  93     }
  94 
  95     static {
  96         authPref = java.security.AccessController.doPrivileged(
  97             new sun.security.action.GetPropertyAction("http.auth.preference"));
  98 
  99         // http.auth.preference can be set to SPNEGO or Kerberos.
 100         // In fact they means "Negotiate with SPNEGO" and "Negotiate with
 101         // Kerberos" separately, so here they are all translated into
 102         // Negotiate. Read NegotiateAuthentication.java to see how they
 103         // were used later.
 104 
 105         if (authPref != null) {
 106             authPref = authPref.toLowerCase();
 107             if(authPref.equals("spnego") || authPref.equals("kerberos")) {
 108                 authPref = "negotiate";
 109             }
 110         }
 111     }
 112 
 113     String hdrname; // Name of the header to look for
 114 
 115     /**
 116      * parse a set of authentication headers and choose the preferred scheme
 117      * that we support for a given host




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.net.www.protocol.http;
  27 

  28 import java.util.Iterator;
  29 import java.util.HashMap;
  30 import sun.net.www.*;
  31 import sun.security.action.GetPropertyAction;
  32 
  33 /**
  34  * This class is used to parse the information in WWW-Authenticate: and Proxy-Authenticate:
  35  * headers. It searches among multiple header lines and within each header line
  36  * for the best currently supported scheme. It can also return a HeaderParser
  37  * containing the challenge data for that particular scheme.
  38  *
  39  * Some examples:
  40  *
  41  * WWW-Authenticate: Basic realm="foo" Digest realm="bar" NTLM
  42  *  Note the realm parameter must be associated with the particular scheme.
  43  *
  44  * or
  45  *
  46  * WWW-Authenticate: Basic realm="foo"
  47  * WWW-Authenticate: Digest realm="foo",qop="auth",nonce="thisisanunlikelynonce"
  48  * WWW-Authenticate: NTLM
  49  *
  50  * or
  51  *


  77  * This also means that the real "Kerberos" scheme can never be set as a preference.
  78  */
  79 
  80 public class AuthenticationHeader {
  81 
  82     MessageHeader rsp; // the response to be parsed
  83     HeaderParser preferred;
  84     String preferred_r; // raw Strings
  85     private final HttpCallerInfo hci;   // un-schemed, need check
  86 
  87     // When set true, do not use Negotiate even if the response
  88     // headers suggest so.
  89     boolean dontUseNegotiate = false;
  90     static String authPref=null;
  91 
  92     public String toString() {
  93         return "AuthenticationHeader: prefer " + preferred_r;
  94     }
  95 
  96     static {
  97         authPref = GetPropertyAction.getProperty("http.auth.preference");

  98 
  99         // http.auth.preference can be set to SPNEGO or Kerberos.
 100         // In fact they means "Negotiate with SPNEGO" and "Negotiate with
 101         // Kerberos" separately, so here they are all translated into
 102         // Negotiate. Read NegotiateAuthentication.java to see how they
 103         // were used later.
 104 
 105         if (authPref != null) {
 106             authPref = authPref.toLowerCase();
 107             if(authPref.equals("spnego") || authPref.equals("kerberos")) {
 108                 authPref = "negotiate";
 109             }
 110         }
 111     }
 112 
 113     String hdrname; // Name of the header to look for
 114 
 115     /**
 116      * parse a set of authentication headers and choose the preferred scheme
 117      * that we support for a given host


< prev index next >