jdk/src/share/classes/sun/net/www/protocol/http/AuthenticationHeader.java
author chegar
Fri, 16 Sep 2011 12:09:04 -0700
changeset 10596 39b3a979e600
parent 5506 202f599c92aa
child 15000 8a1bb7eb6307
permissions -rw-r--r--
7090158: Networking Libraries don't build with javac -Werror Summary: Minor changes to networking java files to remove warnings Reviewed-by: chegar, weijun, hawtin Contributed-by: kurchi.subhra.hazra@oracle.com, sasha_bu@hotmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
     2
 * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2942
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2942
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2942
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2942
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2942
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.net.www.protocol.http;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import sun.net.www.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * This class is used to parse the information in WWW-Authenticate: and Proxy-Authenticate:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * headers. It searches among multiple header lines and within each header line
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * for the best currently supported scheme. It can also return a HeaderParser
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * containing the challenge data for that particular scheme.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Some examples:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * WWW-Authenticate: Basic realm="foo" Digest realm="bar" NTLM
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *  Note the realm parameter must be associated with the particular scheme.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * WWW-Authenticate: Basic realm="foo"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * WWW-Authenticate: Digest realm="foo",qop="auth",nonce="thisisanunlikelynonce"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * WWW-Authenticate: NTLM
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * WWW-Authenticate: Basic realm="foo"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * WWW-Authenticate: NTLM ASKAJK9893289889QWQIOIONMNMN
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * The last example shows how NTLM breaks the rules of rfc2617 for the structure of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * the authentication header. This is the reason why the raw header field is used for ntlm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * At present, the class chooses schemes in following order :
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *      1. Negotiate (if supported)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *      2. Kerberos (if supported)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *      3. Digest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *      4. NTLM (if supported)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *      5. Basic
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * This choice can be modified by setting a system property:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *      -Dhttp.auth.preference="scheme"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * which in this case, specifies that "scheme" should be used as the auth scheme when offered
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * disregarding the default prioritisation. If scheme is not offered then the default priority
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * Attention: when http.auth.preference is set as SPNEGO or Kerberos, it's actually "Negotiate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * with SPNEGO" or "Negotiate with Kerberos", which means the user will prefer the Negotiate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * scheme with GSS/SPNEGO or GSS/Kerberos mechanism.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * This also means that the real "Kerberos" scheme can never be set as a preference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
public class AuthenticationHeader {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    MessageHeader rsp; // the response to be parsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    HeaderParser preferred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    String preferred_r; // raw Strings
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents: 2
diff changeset
    84
    private final HttpCallerInfo hci;   // un-schemed, need check
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    // When set true, do not use Negotiate even if the response
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    // headers suggest so.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    boolean dontUseNegotiate = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    static String authPref=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        return "AuthenticationHeader: prefer " + preferred_r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        authPref = java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            new sun.security.action.GetPropertyAction("http.auth.preference"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        // http.auth.preference can be set to SPNEGO or Kerberos.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        // In fact they means "Negotiate with SPNEGO" and "Negotiate with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        // Kerberos" separately, so here they are all translated into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        // Negotiate. Read NegotiateAuthentication.java to see how they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        // were used later.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        if (authPref != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            authPref = authPref.toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            if(authPref.equals("spnego") || authPref.equals("kerberos")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                authPref = "negotiate";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    String hdrname; // Name of the header to look for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * parse a set of authentication headers and choose the preferred scheme
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * that we support for a given host
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public AuthenticationHeader (String hdrname, MessageHeader response,
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents: 2
diff changeset
   120
            HttpCallerInfo hci, boolean dontUseNegotiate) {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents: 2
diff changeset
   121
        this.hci = hci;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        this.dontUseNegotiate = dontUseNegotiate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        rsp = response;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        this.hdrname = hdrname;
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   125
        schemes = new HashMap<String,SchemeMapValue>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        parse();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents: 2
diff changeset
   129
    public HttpCallerInfo getHttpCallerInfo() {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents: 2
diff changeset
   130
        return hci;
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents: 2
diff changeset
   131
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /* we build up a map of scheme names mapped to SchemeMapValue objects */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    static class SchemeMapValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        SchemeMapValue (HeaderParser h, String r) {raw=r; parser=h;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        String raw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        HeaderParser parser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   139
    HashMap<String, SchemeMapValue> schemes;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /* Iterate through each header line, and then within each line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * If multiple entries exist for a particular scheme (unlikely)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * then the last one will be used. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * preferred scheme that we support will be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    private void parse () {
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   147
        Iterator<String> iter = rsp.multiValueIterator(hdrname);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        while (iter.hasNext()) {
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   149
            String raw = iter.next();
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   150
            HeaderParser hp = new HeaderParser(raw);
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   151
            Iterator<String> keys = hp.keys();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            int i, lastSchemeIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            for (i=0, lastSchemeIndex = -1; keys.hasNext(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                keys.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                if (hp.findValue(i) == null) { /* found a scheme name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                    if (lastSchemeIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                        HeaderParser hpn = hp.subsequence (lastSchemeIndex, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                        String scheme = hpn.findKey(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                        schemes.put (scheme, new SchemeMapValue (hpn, raw));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                    lastSchemeIndex = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            if (i > lastSchemeIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                HeaderParser hpn = hp.subsequence (lastSchemeIndex, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                String scheme = hpn.findKey(0);
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   167
                schemes.put(scheme, new SchemeMapValue (hpn, raw));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        /* choose the best of them, the order is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
         * negotiate -> kerberos -> digest -> ntlm -> basic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        SchemeMapValue v = null;
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   175
        if (authPref == null || (v=schemes.get (authPref)) == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            if(v == null && !dontUseNegotiate) {
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   178
                SchemeMapValue tmp = schemes.get("negotiate");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                if(tmp != null) {
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents: 2
diff changeset
   180
                    if(hci == null || !NegotiateAuthentication.isSupported(new HttpCallerInfo(hci, "Negotiate"))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                        tmp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                    v = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            if(v == null && !dontUseNegotiate) {
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   188
                SchemeMapValue tmp = schemes.get("kerberos");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                if(tmp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                    // the Kerberos scheme is only observed in MS ISA Server. In
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                    // fact i think it's a Kerberos-mechnism-only Negotiate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                    // Since the Kerberos scheme is always accompanied with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                    // Negotiate scheme, so it seems impossible to reach this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                    // line. Even if the user explicitly set http.auth.preference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                    // as Kerberos, it means Negotiate with Kerberos, and the code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                    // will still tried to use Negotiate at first.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                    // The only chance this line get executed is that the server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    // only suggest the Kerberos scheme.
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents: 2
diff changeset
   200
                    if(hci == null || !NegotiateAuthentication.isSupported(new HttpCallerInfo(hci, "Kerberos"))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                        tmp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    v = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            if(v == null) {
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   208
                if ((v=schemes.get ("digest")) == null) {
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   209
                    if (((v=schemes.get("ntlm"))==null)) {
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   210
                        v = schemes.get ("basic");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        } else {    // authPref != null && it's found in reponses'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            if (dontUseNegotiate && authPref.equals("negotiate")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                v = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            preferred = v.parser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            preferred_r = v.raw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * return a header parser containing the preferred authentication scheme (only).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * The preferred scheme is the strongest of the schemes proposed by the server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * The returned HeaderParser will contain the relevant parameters for that scheme
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public HeaderParser headerParser() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return preferred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * return the name of the preferred scheme
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public String scheme() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        if (preferred != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            return preferred.findKey(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    /* return the raw header field for the preferred/chosen scheme */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public String raw () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        return preferred_r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * returns true is the header exists and contains a recognised scheme
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    public boolean isPresent () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        return preferred != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
}