jdk/src/java.base/share/classes/sun/net/www/protocol/http/AuthenticationInfo.java
author chegar
Sun, 17 Aug 2014 15:54:13 +0100
changeset 25859 3317bb8137f4
parent 23010 jdk/src/share/classes/sun/net/www/protocol/http/AuthenticationInfo.java@6dadb192ad81
child 32649 2ee9017c7597
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
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: 19219
diff changeset
     2
 * Copyright (c) 1995, 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: 5199
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: 5199
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: 5199
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5199
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5199
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
4157
558590fb3b49 6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents: 3952
diff changeset
    28
import java.io.IOException;
558590fb3b49 6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents: 3952
diff changeset
    29
import java.io.ObjectInputStream;
558590fb3b49 6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents: 3952
diff changeset
    30
import java.net.PasswordAuthentication;
558590fb3b49 6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents: 3952
diff changeset
    31
import java.net.URL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.net.www.HeaderParser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * AuthenticationInfo: Encapsulate the information needed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * authenticate a user to a server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @author Jon Payne
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @author Herb Jellinek
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @author Bill Foote
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
// REMIND:  It would be nice if this class understood about partial matching.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
//      If you're authorized for foo.com, chances are high you're also
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
//      authorized for baz.foo.com.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
// NB:  When this gets implemented, be careful about the uncaching
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
//      policy in HttpURLConnection.  A failure on baz.foo.com shouldn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
//      uncache foo.com!
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
4157
558590fb3b49 6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents: 3952
diff changeset
    52
public abstract class AuthenticationInfo extends AuthCacheValue implements Cloneable {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
19219
0d4231d25a29 8022478: Fix Warnings In sun.net.www.protocol.http Package
dxu
parents: 7668
diff changeset
    54
    static final long serialVersionUID = -2588378268010453259L;
0d4231d25a29 8022478: Fix Warnings In sun.net.www.protocol.http Package
dxu
parents: 7668
diff changeset
    55
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    // Constants saying what kind of authroization this is.  This determines
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    // the namespace in the hash table lookup.
4157
558590fb3b49 6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents: 3952
diff changeset
    58
    public static final char SERVER_AUTHENTICATION = 's';
558590fb3b49 6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents: 3952
diff changeset
    59
    public static final char PROXY_AUTHENTICATION = 'p';
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * If true, then simultaneous authentication requests to the same realm/proxy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * are serialized, in order to avoid a user having to type the same username/passwords
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * repeatedly, via the Authenticator. Default is false, which means that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * behavior is switched off.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    static boolean serializeAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        serializeAuth = java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            new sun.security.action.GetBooleanAction(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                "http.auth.serializeRequests")).booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /* AuthCacheValue: */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    transient protected PasswordAuthentication pw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public PasswordAuthentication credentials() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        return pw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public AuthCacheValue.Type getAuthType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        return type == SERVER_AUTHENTICATION ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            AuthCacheValue.Type.Server:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            AuthCacheValue.Type.Proxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
3859
8b82336dedb3 6882594: Remove static dependancy on NTLM authentication
chegar
parents: 2
diff changeset
    88
8b82336dedb3 6882594: Remove static dependancy on NTLM authentication
chegar
parents: 2
diff changeset
    89
    AuthScheme getAuthScheme() {
8b82336dedb3 6882594: Remove static dependancy on NTLM authentication
chegar
parents: 2
diff changeset
    90
        return authScheme;
8b82336dedb3 6882594: Remove static dependancy on NTLM authentication
chegar
parents: 2
diff changeset
    91
    }
8b82336dedb3 6882594: Remove static dependancy on NTLM authentication
chegar
parents: 2
diff changeset
    92
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public String getHost() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        return host;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public int getPort() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        return port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public String getRealm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        return realm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public String getPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        return path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public String getProtocolScheme() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        return protocol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * requests is used to ensure that interaction with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Authenticator for a particular realm is single threaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * ie. if multiple threads need to get credentials from the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * at the same time, then all but the first will block until
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * the first completes its authentication.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
4916
de44744708a2 6693244: Java Web Start app fails on 6u10 beta w/ AssertionError in AuthenticationInfo.requestCompleted
chegar
parents: 4157
diff changeset
   116
    static private HashMap<String,Thread> requests = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /* check if a request for this destination is in progress
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * return false immediately if not. Otherwise block until
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * request is finished and return true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    static private boolean requestIsInProgress (String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        if (!serializeAuth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            /* behavior is disabled. Revert to concurrent requests */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        synchronized (requests) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            Thread t, c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            c = Thread.currentThread();
4916
de44744708a2 6693244: Java Web Start app fails on 6u10 beta w/ AssertionError in AuthenticationInfo.requestCompleted
chegar
parents: 4157
diff changeset
   130
            if ((t = requests.get(key)) == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                requests.put (key, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            if (t == c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            while (requests.containsKey(key)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                    requests.wait ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                } catch (InterruptedException e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        /* entry may be in cache now. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /* signal completion of an authentication (whether it succeeded or not)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * so that other threads can continue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    static private void requestCompleted (String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        synchronized (requests) {
4916
de44744708a2 6693244: Java Web Start app fails on 6u10 beta w/ AssertionError in AuthenticationInfo.requestCompleted
chegar
parents: 4157
diff changeset
   152
            Thread thread = requests.get(key);
de44744708a2 6693244: Java Web Start app fails on 6u10 beta w/ AssertionError in AuthenticationInfo.requestCompleted
chegar
parents: 4157
diff changeset
   153
            if (thread != null && thread == Thread.currentThread()) {
de44744708a2 6693244: Java Web Start app fails on 6u10 beta w/ AssertionError in AuthenticationInfo.requestCompleted
chegar
parents: 4157
diff changeset
   154
                boolean waspresent = requests.remove(key) != null;
de44744708a2 6693244: Java Web Start app fails on 6u10 beta w/ AssertionError in AuthenticationInfo.requestCompleted
chegar
parents: 4157
diff changeset
   155
                assert waspresent;
de44744708a2 6693244: Java Web Start app fails on 6u10 beta w/ AssertionError in AuthenticationInfo.requestCompleted
chegar
parents: 4157
diff changeset
   156
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            requests.notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    //public String toString () {
3859
8b82336dedb3 6882594: Remove static dependancy on NTLM authentication
chegar
parents: 2
diff changeset
   162
        //return ("{"+type+":"+authScheme+":"+protocol+":"+host+":"+port+":"+realm+":"+path+"}");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    //}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    // REMIND:  This cache just grows forever.  We should put in a bounded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    //          cache, or maybe something using WeakRef's.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /** The type (server/proxy) of authentication this is.  Used for key lookup */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    char type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
3859
8b82336dedb3 6882594: Remove static dependancy on NTLM authentication
chegar
parents: 2
diff changeset
   171
    /** The authentication scheme (basic/digest). Also used for key lookup */
8b82336dedb3 6882594: Remove static dependancy on NTLM authentication
chegar
parents: 2
diff changeset
   172
    AuthScheme authScheme;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /** The protocol/scheme (i.e. http or https ). Need to keep the caches
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *  logically separate for the two protocols. This field is only used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *  when constructed with a URL (the normal case for server authentication)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *  For proxy authentication the protocol is not relevant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    String protocol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /** The host we're authenticating against. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    String host;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /** The port on the host we're authenticating against. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    int port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /** The realm we're authenticating against. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    String realm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /** The shortest path from the URL we authenticated against. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    String path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /** Use this constructor only for proxy entries */
4157
558590fb3b49 6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents: 3952
diff changeset
   194
    public AuthenticationInfo(char type, AuthScheme authScheme, String host, int port, String realm) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        this.type = type;
3859
8b82336dedb3 6882594: Remove static dependancy on NTLM authentication
chegar
parents: 2
diff changeset
   196
        this.authScheme = authScheme;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        this.protocol = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        this.host = host.toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        this.port = port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        this.realm = realm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        this.path = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            return super.clone ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        } catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            // Cannot happen because Cloneable implemented by AuthenticationInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
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
     * Constructor used to limit the authorization to the path within
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * the URL. Use this constructor for origin server entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
4157
558590fb3b49 6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents: 3952
diff changeset
   217
    public AuthenticationInfo(char type, AuthScheme authScheme, URL url, String realm) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        this.type = type;
3859
8b82336dedb3 6882594: Remove static dependancy on NTLM authentication
chegar
parents: 2
diff changeset
   219
        this.authScheme = authScheme;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        this.protocol = url.getProtocol().toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        this.host = url.getHost().toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        this.port = url.getPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (this.port == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            this.port = url.getDefaultPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        this.realm = realm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        String urlPath = url.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        if (urlPath.length() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            this.path = urlPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            this.path = reducePath (urlPath);
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * reduce the path to the root of where we think the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * authorization begins. This could get shorter as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * the url is traversed up following a successful challenge.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    static String reducePath (String urlPath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        int sepIndex = urlPath.lastIndexOf('/');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        int targetSuffixIndex = urlPath.lastIndexOf('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (sepIndex != -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            if (sepIndex < targetSuffixIndex)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                return urlPath.substring(0, sepIndex+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                return urlPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            return urlPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Returns info for the URL, for an HTTP server auth.  Used when we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * don't yet know the realm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * (i.e. when we're preemptively setting the auth).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    static AuthenticationInfo getServerAuth(URL url) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        int port = url.getPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        if (port == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            port = url.getDefaultPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        String key = SERVER_AUTHENTICATION + ":" + url.getProtocol().toLowerCase()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                + ":" + url.getHost().toLowerCase() + ":" + port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        return getAuth(key, url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * Returns info for the URL, for an HTTP server auth.  Used when we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * do know the realm (i.e. when we're responding to a challenge).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * In this case we do not use the path because the protection space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * is identified by the host:port:realm only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     */
5199
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents: 4916
diff changeset
   275
    static String getServerAuthKey(URL url, String realm, AuthScheme scheme) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        int port = url.getPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        if (port == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            port = url.getDefaultPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
3859
8b82336dedb3 6882594: Remove static dependancy on NTLM authentication
chegar
parents: 2
diff changeset
   280
        String key = SERVER_AUTHENTICATION + ":" + scheme + ":" + url.getProtocol().toLowerCase()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                     + ":" + url.getHost().toLowerCase() + ":" + port + ":" + realm;
5199
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents: 4916
diff changeset
   282
        return key;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents: 4916
diff changeset
   283
    }
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents: 4916
diff changeset
   284
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents: 4916
diff changeset
   285
    static AuthenticationInfo getServerAuth(String key) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        AuthenticationInfo cached = getAuth(key, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        if ((cached == null) && requestIsInProgress (key)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            /* check the cache again, it might contain an entry */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            cached = getAuth(key, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        return cached;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * Return the AuthenticationInfo object from the cache if it's path is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * a substring of the supplied URLs path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    static AuthenticationInfo getAuth(String key, URL url) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        if (url == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            return (AuthenticationInfo)cache.get (key, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            return (AuthenticationInfo)cache.get (key, url.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * Returns a firewall authentication, for the given host/port.  Used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * for preemptive header-setting. Note, the protocol field is always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * blank for proxies.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    static AuthenticationInfo getProxyAuth(String host, int port) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        String key = PROXY_AUTHENTICATION + "::" + host.toLowerCase() + ":" + port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        AuthenticationInfo result = (AuthenticationInfo) cache.get(key, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * Returns a firewall authentication, for the given host/port and realm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * Used in response to a challenge. Note, the protocol field is always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * blank for proxies.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     */
5199
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents: 4916
diff changeset
   323
    static String getProxyAuthKey(String host, int port, String realm, AuthScheme scheme) {
3859
8b82336dedb3 6882594: Remove static dependancy on NTLM authentication
chegar
parents: 2
diff changeset
   324
        String key = PROXY_AUTHENTICATION + ":" + scheme + "::" + host.toLowerCase()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                        + ":" + port + ":" + realm;
5199
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents: 4916
diff changeset
   326
        return key;
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents: 4916
diff changeset
   327
    }
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents: 4916
diff changeset
   328
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents: 4916
diff changeset
   329
    static AuthenticationInfo getProxyAuth(String key) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        AuthenticationInfo cached = (AuthenticationInfo) cache.get(key, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        if ((cached == null) && requestIsInProgress (key)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            /* check the cache again, it might contain an entry */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            cached = (AuthenticationInfo) cache.get(key, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        return cached;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * Add this authentication to the cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    void addToCache() {
5199
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents: 4916
diff changeset
   343
        String key = cacheKey(true);
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents: 4916
diff changeset
   344
        cache.put(key, this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        if (supportsPreemptiveAuthorization()) {
5199
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents: 4916
diff changeset
   346
            cache.put(cacheKey(false), this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        }
5199
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents: 4916
diff changeset
   348
        endAuthRequest(key);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
5199
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents: 4916
diff changeset
   351
    static void endAuthRequest (String key) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        if (!serializeAuth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        synchronized (requests) {
5199
98b1778f0fd1 6648001: Cancelling HTTP authentication causes subsequent deadlocks
chegar
parents: 4916
diff changeset
   356
            requestCompleted(key);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * Remove this authentication from the cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    void removeFromCache() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        cache.remove(cacheKey(true), this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        if (supportsPreemptiveAuthorization()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            cache.remove(cacheKey(false), this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @return true if this authentication supports preemptive authorization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     */
4157
558590fb3b49 6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents: 3952
diff changeset
   373
    public abstract boolean supportsPreemptiveAuthorization();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @return the name of the HTTP header this authentication wants set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *          This is used for preemptive authorization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     */
4157
558590fb3b49 6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents: 3952
diff changeset
   379
    public String getHeaderName() {
558590fb3b49 6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents: 3952
diff changeset
   380
        if (type == SERVER_AUTHENTICATION) {
558590fb3b49 6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents: 3952
diff changeset
   381
            return "Authorization";
558590fb3b49 6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents: 3952
diff changeset
   382
        } else {
558590fb3b49 6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents: 3952
diff changeset
   383
            return "Proxy-authorization";
558590fb3b49 6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents: 3952
diff changeset
   384
        }
558590fb3b49 6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents: 3952
diff changeset
   385
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * Calculates and returns the authentication header value based
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * on the stored authentication parameters. If the calculation does not depend
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * on the URL or the request method then these parameters are ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @param url The URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @param method The request method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @return the value of the HTTP header this authentication wants set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     *          Used for preemptive authorization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     */
4157
558590fb3b49 6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents: 3952
diff changeset
   396
    public abstract String getHeaderValue(URL url, String method);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * Set header(s) on the given connection.  Subclasses must override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * This will only be called for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * definitive (i.e. non-preemptive) authorization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @param conn The connection to apply the header(s) to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @param p A source of header values for this connection, if needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * @param raw The raw header field (if needed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * @return true if all goes well, false if no headers were set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     */
4157
558590fb3b49 6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents: 3952
diff changeset
   407
    public abstract boolean setHeaders(HttpURLConnection conn, HeaderParser p, String raw);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * Check if the header indicates that the current auth. parameters are stale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * If so, then replace the relevant field with the new value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * and return true. Otherwise return false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * returning true means the request can be retried with the same userid/password
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * returning false means we have to go back to the user to ask for a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * username password.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     */
4157
558590fb3b49 6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents: 3952
diff changeset
   417
    public abstract boolean isAuthorizationStale (String header);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * Give a key for hash table lookups.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @param includeRealm if you want the realm considered.  Preemptively
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     *          setting an authorization is done before the realm is known.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    String cacheKey(boolean includeRealm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        // This must be kept in sync with the getXXXAuth() methods in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        // class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        if (includeRealm) {
3859
8b82336dedb3 6882594: Remove static dependancy on NTLM authentication
chegar
parents: 2
diff changeset
   428
            return type + ":" + authScheme + ":" + protocol + ":"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                        + host + ":" + port + ":" + realm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            return type + ":" + protocol + ":" + host + ":" + port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    String s1, s2;  /* used for serialization of pw */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        s.defaultReadObject ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        pw = new PasswordAuthentication (s1, s2.toCharArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        s1 = null; s2= null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    private synchronized void writeObject(java.io.ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        s1 = pw.getUserName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        s2 = new String (pw.getPassword());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        s.defaultWriteObject ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
}