jdk/test/java/net/Authenticator/B8034170.java
author michaelm
Wed, 14 May 2014 11:16:41 +0100
changeset 24372 2ff88b15e82e
permissions -rw-r--r--
8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java Reviewed-by: chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24372
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
     1
/*
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
     4
 *
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
     8
 *
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    13
 * accompanied this code).
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    14
 *
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    18
 *
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    21
 * questions.
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    22
 */
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    23
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    24
import java.io.*;
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    25
import java.net.*;
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    26
import java.util.*;
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    27
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    28
/**
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    29
 * @test
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    30
 * @bug 8034170
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    31
 * @summary Digest authentication interop issue
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    32
 * @run main/othervm B8034170 unquoted
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    33
 * @run main/othervm -Dhttp.auth.digest.quoteParameters=true B8034170 quoted
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    34
 */
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    35
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    36
public class B8034170 {
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    37
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    38
    static boolean expectQuotes;
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    39
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    40
    static class BasicServer extends Thread {
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    41
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    42
        ServerSocket server;
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    43
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    44
        Socket s;
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    45
        InputStream is;
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    46
        OutputStream os;
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    47
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    48
        static final String realm = "wallyworld";
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    49
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    50
        String reply1 = "HTTP/1.1 401 Unauthorized\r\n"+
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    51
            "WWW-Authenticate: Digest realm=\""+realm+"\", qop=\"auth\"" +
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    52
            ", nonce=\"8989de95ea2402b64d73cecdb15da255\"" +
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    53
            ", opaque=\"bbfb4c9ee92ddccc73521c3e6e841ba2\"\r\n\r\n";
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    54
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    55
        String OKreply = "HTTP/1.1 200 OK\r\n"+
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    56
            "Date: Mon, 15 Jan 2001 12:18:21 GMT\r\n" +
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    57
            "Server: Apache/1.3.14 (Unix)\r\n" +
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    58
            "Connection: close\r\n" +
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    59
            "Content-Type: text/plain; charset=iso-8859-1\r\n" +
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    60
            "Content-Length: 10\r\n\r\n";
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    61
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    62
        String ERRreply = "HTTP/1.1 500 Internal server error\r\n"+
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    63
            "Date: Mon, 15 Jan 2001 12:18:21 GMT\r\n" +
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    64
            "Server: Apache/1.3.14 (Unix)\r\n" +
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    65
            "Connection: close\r\n" +
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    66
            "Content-Length: 0\r\n\r\n";
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    67
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    68
        BasicServer (ServerSocket s) {
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    69
            server = s;
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    70
        }
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    71
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    72
        int readAll (Socket s, byte[] buf) throws IOException {
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    73
            int pos = 0;
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    74
            InputStream is = s.getInputStream ();
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    75
            // wait two seconds for request, as client doesn't close
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    76
            // the connection
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    77
            s.setSoTimeout(2000);
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    78
            try {
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    79
                int n;
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    80
                while ((n=is.read(buf, pos, buf.length-pos)) > 0)
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    81
                    pos +=n;
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    82
            } catch (SocketTimeoutException x) { }
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    83
            return pos;
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    84
        }
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    85
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    86
        public void run () {
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    87
            byte[] buf = new byte[5000];
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    88
            try {
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    89
                System.out.println ("Server 1: accept");
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    90
                s = server.accept ();
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    91
                System.out.println ("accepted");
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    92
                os = s.getOutputStream();
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    93
                os.write (reply1.getBytes());
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    94
                readAll (s, buf);
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    95
                s.close ();
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    96
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    97
                System.out.println ("Server 2: accept");
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    98
                s = server.accept ();
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
    99
                System.out.println ("accepted");
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   100
                os = s.getOutputStream();
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   101
                int count = readAll (s, buf);
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   102
                String reply = new String(buf, 0, count);
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   103
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   104
                boolean error;
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   105
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   106
                if (expectQuotes) {
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   107
                    error = false;
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   108
                    if (!reply.contains("qop=\"auth\"")) {
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   109
                        System.out.println ("Expecting quoted qop. Not found");
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   110
                        error = true;
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   111
                    }
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   112
                    if (!reply.contains("algorithm=\"MD5\"")) {
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   113
                        System.out.println ("Expecting quoted algorithm. Not found");
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   114
                        error = true;
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   115
                    }
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   116
                } else {
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   117
                    error = false;
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   118
                    if (!reply.contains("qop=auth")) {
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   119
                        System.out.println ("Expecting unquoted qop. Not found");
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   120
                        error = true;
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   121
                    }
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   122
                    if (!reply.contains("algorithm=MD5")) {
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   123
                        System.out.println ("Expecting unquoted algorithm. Not found");
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   124
                        error = true;
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   125
                    }
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   126
                }
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   127
                if (error) {
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   128
                    os.write(ERRreply.getBytes());
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   129
                    os.flush();
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   130
                    s.close();
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   131
                } else {
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   132
                    os.write((OKreply+"HelloWorld").getBytes());
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   133
                    os.flush();
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   134
                    s.close();
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   135
                }
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   136
            }
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   137
            catch (Exception e) {
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   138
                System.out.println (e);
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   139
            }
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   140
            finished ();
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   141
        }
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   142
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   143
        public synchronized void finished () {
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   144
            notifyAll();
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   145
        }
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   146
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   147
    }
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   148
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   149
    static class MyAuthenticator3 extends Authenticator {
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   150
        PasswordAuthentication pw;
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   151
        MyAuthenticator3 () {
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   152
            super ();
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   153
            pw = new PasswordAuthentication ("user", "passwordNotCheckedAnyway".toCharArray());
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   154
        }
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   155
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   156
        public PasswordAuthentication getPasswordAuthentication ()
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   157
            {
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   158
            System.out.println ("Auth called");
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   159
            return pw;
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   160
        }
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   161
    }
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   162
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   163
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   164
    static void read (InputStream is) throws IOException {
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   165
        int c;
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   166
        System.out.println ("reading");
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   167
        while ((c=is.read()) != -1) {
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   168
            System.out.write (c);
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   169
        }
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   170
        System.out.println ("");
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   171
        System.out.println ("finished reading");
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   172
    }
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   173
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   174
    public static void main (String args[]) throws Exception {
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   175
        expectQuotes = args[0].equals("quoted");
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   176
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   177
        MyAuthenticator3 auth = new MyAuthenticator3 ();
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   178
        Authenticator.setDefault (auth);
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   179
        ServerSocket ss = new ServerSocket (0);
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   180
        int port = ss.getLocalPort ();
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   181
        BasicServer server = new BasicServer (ss);
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   182
        synchronized (server) {
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   183
            server.start();
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   184
            System.out.println ("client 1");
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   185
            URL url = new URL ("http://localhost:"+port+"/d1/d2/d3/foo.html");
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   186
            URLConnection urlc = url.openConnection ();
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   187
            InputStream is = urlc.getInputStream ();
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   188
            read (is);
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   189
            is.close ();
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   190
        }
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   191
    }
2ff88b15e82e 8034170: src/share/classes/sun/net/www/protocol/http/DigestAuthentication.java
michaelm
parents:
diff changeset
   192
}