jdk/src/java.base/share/classes/sun/net/www/protocol/http/AuthenticationHeader.java
author redestad
Tue, 03 May 2016 15:50:54 +0200
changeset 37781 71ed5645f17c
parent 37593 824750ada3d6
child 41579 c0fe2e6364d9
permissions -rw-r--r--
8155775: Re-examine naming of privileged methods to access System properties Reviewed-by: mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 15000
diff changeset
     2
 * Copyright (c) 2002, 2013, 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 java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.HashMap;
37593
824750ada3d6 8154231: Simplify access to System properties from JDK code
redestad
parents: 29986
diff changeset
    30
import sun.net.www.*;
824750ada3d6 8154231: Simplify access to System properties from JDK code
redestad
parents: 29986
diff changeset
    31
import sun.security.action.GetPropertyAction;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * This class is used to parse the information in WWW-Authenticate: and Proxy-Authenticate:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * headers. It searches among multiple header lines and within each header line
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * for the best currently supported scheme. It can also return a HeaderParser
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * containing the challenge data for that particular scheme.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Some examples:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * WWW-Authenticate: Basic realm="foo" Digest realm="bar" NTLM
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *  Note the realm parameter must be associated with the particular scheme.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * WWW-Authenticate: Basic realm="foo"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * WWW-Authenticate: Digest realm="foo",qop="auth",nonce="thisisanunlikelynonce"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * WWW-Authenticate: NTLM
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * WWW-Authenticate: Basic realm="foo"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * WWW-Authenticate: NTLM ASKAJK9893289889QWQIOIONMNMN
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * The last example shows how NTLM breaks the rules of rfc2617 for the structure of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * the authentication header. This is the reason why the raw header field is used for ntlm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * At present, the class chooses schemes in following order :
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *      1. Negotiate (if supported)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *      2. Kerberos (if supported)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *      3. Digest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *      4. NTLM (if supported)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *      5. Basic
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * This choice can be modified by setting a system property:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *      -Dhttp.auth.preference="scheme"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * which in this case, specifies that "scheme" should be used as the auth scheme when offered
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * disregarding the default prioritisation. If scheme is not offered then the default priority
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * Attention: when http.auth.preference is set as SPNEGO or Kerberos, it's actually "Negotiate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * with SPNEGO" or "Negotiate with Kerberos", which means the user will prefer the Negotiate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * scheme with GSS/SPNEGO or GSS/Kerberos mechanism.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * This also means that the real "Kerberos" scheme can never be set as a preference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
public class AuthenticationHeader {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    MessageHeader rsp; // the response to be parsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    HeaderParser preferred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    String preferred_r; // raw Strings
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents: 2
diff changeset
    85
    private final HttpCallerInfo hci;   // un-schemed, need check
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    // When set true, do not use Negotiate even if the response
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    // headers suggest so.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    boolean dontUseNegotiate = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    static String authPref=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        return "AuthenticationHeader: prefer " + preferred_r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    static {
37781
71ed5645f17c 8155775: Re-examine naming of privileged methods to access System properties
redestad
parents: 37593
diff changeset
    97
        authPref = GetPropertyAction.privilegedGetProperty("http.auth.preference");
2
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;
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
   125
        schemes = new HashMap<>();
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) {
15000
8a1bb7eb6307 8005638: Less secure Authentication schemes should work when more secure schemes are not available
chegar
parents: 10596
diff changeset
   209
                    if (!NTLMAuthenticationProxy.supported
8a1bb7eb6307 8005638: Less secure Authentication schemes should work when more secure schemes are not available
chegar
parents: 10596
diff changeset
   210
                        || ((v=schemes.get("ntlm"))==null)) {
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   211
                        v = schemes.get ("basic");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        } else {    // authPref != null && it's found in reponses'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            if (dontUseNegotiate && authPref.equals("negotiate")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                v = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            preferred = v.parser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            preferred_r = v.raw;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * return a header parser containing the preferred authentication scheme (only).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * The preferred scheme is the strongest of the schemes proposed by the server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * The returned HeaderParser will contain the relevant parameters for that scheme
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public HeaderParser headerParser() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        return preferred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * return the name of the preferred scheme
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public String scheme() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (preferred != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            return preferred.findKey(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /* return the raw header field for the preferred/chosen scheme */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    public String raw () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        return preferred_r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * returns true is the header exists and contains a recognised scheme
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public boolean isPresent () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return preferred != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
}