test/jdk/sun/security/krb5/auto/HttpNegotiateServer.java
author ssahoo
Thu, 25 Jan 2018 05:57:22 -0800
changeset 48668 2da4a52715d8
parent 47227 8052fa06e1b7
permissions -rw-r--r--
8194486: Several krb5 tests failed in Mac. Summary: Several tests failed due to improper host service Reviewed-by: weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
     1
/*
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47227
diff changeset
     2
 * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
     4
 *
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
     8
 *
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    13
 * accompanied this code).
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    14
 *
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5154
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5154
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5154
diff changeset
    21
 * questions.
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    22
 */
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    23
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    24
/*
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    25
 * @test
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47227
diff changeset
    26
 * @bug 6578647 6829283 8171340 8194486
44045
8102155116c6 8176213: 78 sun/security/krb5/auto tests failing due to undeclared dependecies
skovalev
parents: 42705
diff changeset
    27
 * @modules java.base/sun.security.util
8102155116c6 8176213: 78 sun/security/krb5/auto tests failing due to undeclared dependecies
skovalev
parents: 42705
diff changeset
    28
 *          java.security.jgss/sun.security.krb5.internal:+open
8102155116c6 8176213: 78 sun/security/krb5/auto tests failing due to undeclared dependecies
skovalev
parents: 42705
diff changeset
    29
 *          java.security.jgss/sun.security.jgss
8102155116c6 8176213: 78 sun/security/krb5/auto tests failing due to undeclared dependecies
skovalev
parents: 42705
diff changeset
    30
 *          java.security.jgss/sun.security.krb5:+open
47227
8052fa06e1b7 8186884: Test native KDC, Java krb5 lib, and native krb5 lib in one test
weijun
parents: 47216
diff changeset
    31
 *          java.security.jgss/sun.security.jgss.krb5
44248
90d510618f6c 8176715: sun/security/krb5/auto/HttpNegotiateServer.java does not compile
weijun
parents: 44045
diff changeset
    32
 *          java.security.jgss/sun.security.krb5.internal.ccache
44045
8102155116c6 8176213: 78 sun/security/krb5/auto tests failing due to undeclared dependecies
skovalev
parents: 42705
diff changeset
    33
 *          java.security.jgss/sun.security.krb5.internal.crypto
8102155116c6 8176213: 78 sun/security/krb5/auto tests failing due to undeclared dependecies
skovalev
parents: 42705
diff changeset
    34
 *          java.security.jgss/sun.security.krb5.internal.ktab
8102155116c6 8176213: 78 sun/security/krb5/auto tests failing due to undeclared dependecies
skovalev
parents: 42705
diff changeset
    35
 *          jdk.security.auth
8102155116c6 8176213: 78 sun/security/krb5/auto tests failing due to undeclared dependecies
skovalev
parents: 42705
diff changeset
    36
 *          jdk.security.jgss
8102155116c6 8176213: 78 sun/security/krb5/auto tests failing due to undeclared dependecies
skovalev
parents: 42705
diff changeset
    37
 *          jdk.httpserver
42705
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
    38
 * @summary Undefined requesting URL in java.net.Authenticator
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
    39
 *          .getPasswordAuthentication()
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
    40
 * @summary HTTP/Negotiate: Authenticator triggered again when
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
    41
 *          user cancels the first one
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47227
diff changeset
    42
 * @library /test/lib
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47227
diff changeset
    43
 * @run main jdk.test.lib.FileInstaller TestHosts TestHosts
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47227
diff changeset
    44
 * @run main/othervm -Djdk.net.hosts.file=TestHosts HttpNegotiateServer
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    45
 */
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    46
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    47
import com.sun.net.httpserver.Headers;
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    48
import com.sun.net.httpserver.HttpContext;
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    49
import com.sun.net.httpserver.HttpExchange;
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    50
import com.sun.net.httpserver.HttpHandler;
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    51
import com.sun.net.httpserver.HttpServer;
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    52
import com.sun.net.httpserver.HttpPrincipal;
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    53
import com.sun.security.auth.module.Krb5LoginModule;
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    54
import java.io.BufferedReader;
5154
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
    55
import java.io.File;
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
    56
import java.io.FileOutputStream;
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    57
import java.io.IOException;
30685
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
    58
import java.io.InputStream;
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    59
import java.io.InputStreamReader;
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    60
import java.net.HttpURLConnection;
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    61
import java.net.InetSocketAddress;
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    62
import java.net.PasswordAuthentication;
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    63
import java.net.Proxy;
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    64
import java.net.URL;
30685
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
    65
import java.net.URLConnection;
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
    66
import java.security.*;
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    67
import java.util.HashMap;
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    68
import java.util.Map;
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    69
import javax.security.auth.Subject;
30685
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
    70
import javax.security.auth.callback.Callback;
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
    71
import javax.security.auth.callback.CallbackHandler;
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
    72
import javax.security.auth.callback.NameCallback;
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
    73
import javax.security.auth.callback.PasswordCallback;
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
    74
import javax.security.auth.callback.UnsupportedCallbackException;
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
    75
import javax.security.auth.login.AppConfigurationEntry;
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
    76
import javax.security.auth.login.Configuration;
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
    77
import javax.security.auth.login.LoginContext;
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
    78
import javax.security.auth.login.LoginException;
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
    79
import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag;
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    80
import org.ietf.jgss.GSSContext;
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    81
import org.ietf.jgss.GSSCredential;
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    82
import org.ietf.jgss.GSSManager;
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    83
import sun.security.jgss.GSSUtil;
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    84
import sun.security.krb5.Config;
30685
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
    85
import java.util.Base64;
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    86
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    87
/**
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    88
 * Basic JGSS/krb5 test with 3 parties: client, server, backend server. Each
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    89
 * party uses JAAS login to get subjects and executes JGSS calls using
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    90
 * Subject.doAs.
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    91
 */
3046
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
    92
public class HttpNegotiateServer {
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    93
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    94
    // Two realm, web server in one, proxy server in another
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    95
    final static String REALM_WEB = "WEB.DOMAIN";
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    96
    final static String REALM_PROXY = "PROXY.DOMAIN";
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    97
    final static String KRB5_CONF = "web.conf";
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    98
    final static String KRB5_TAB = "web.ktab";
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
    99
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   100
    // user principals
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   101
    final static String WEB_USER = "web";
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   102
    final static char[] WEB_PASS = "webby".toCharArray();
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   103
    final static String PROXY_USER = "pro";
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   104
    final static char[] PROXY_PASS = "proxy".toCharArray();
9008
1c23e333dd76 7031536: test/sun/security/krb5/auto/HttpNegotiateServer.java should not use static ports
weijun
parents: 8396
diff changeset
   105
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   106
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   107
    final static String WEB_HOST = "host.web.domain";
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   108
    final static String PROXY_HOST = "host.proxy.domain";
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   109
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   110
    // web page content
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   111
    final static String CONTENT = "Hello, World!";
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   112
5154
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   113
    // For 6829283, count how many times the Authenticator is called.
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   114
    static int count = 0;
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   115
9008
1c23e333dd76 7031536: test/sun/security/krb5/auto/HttpNegotiateServer.java should not use static ports
weijun
parents: 8396
diff changeset
   116
    static int webPort, proxyPort;
1c23e333dd76 7031536: test/sun/security/krb5/auto/HttpNegotiateServer.java should not use static ports
weijun
parents: 8396
diff changeset
   117
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   118
    // URLs for web test, proxy test. The proxy server is not a real proxy
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   119
    // since it fakes the same content for any URL. :)
9008
1c23e333dd76 7031536: test/sun/security/krb5/auto/HttpNegotiateServer.java should not use static ports
weijun
parents: 8396
diff changeset
   120
    static URL webUrl, proxyUrl;
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   121
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   122
    /**
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   123
     * This Authenticator checks everything:
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   124
     * scheme, protocol, requestor type, host, port, and url
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   125
     */
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   126
    static class KnowAllAuthenticator extends java.net.Authenticator {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   127
        public PasswordAuthentication getPasswordAuthentication () {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   128
            if (!getRequestingScheme().equalsIgnoreCase("Negotiate")) {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   129
                throw new RuntimeException("Bad scheme");
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   130
            }
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   131
            if (!getRequestingProtocol().equalsIgnoreCase("HTTP")) {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   132
                throw new RuntimeException("Bad protocol");
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   133
            }
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   134
            if (getRequestorType() == RequestorType.SERVER) {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   135
                if (!this.getRequestingHost().equalsIgnoreCase(webUrl.getHost())) {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   136
                    throw new RuntimeException("Bad host");
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   137
                }
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   138
                if (this.getRequestingPort() != webUrl.getPort()) {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   139
                    throw new RuntimeException("Bad port");
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   140
                }
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   141
                if (!this.getRequestingURL().equals(webUrl)) {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   142
                    throw new RuntimeException("Bad url");
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   143
                }
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   144
                return new PasswordAuthentication(
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   145
                        WEB_USER+"@"+REALM_WEB, WEB_PASS);
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   146
            } else if (getRequestorType() == RequestorType.PROXY) {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   147
                if (!this.getRequestingHost().equalsIgnoreCase(PROXY_HOST)) {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   148
                    throw new RuntimeException("Bad host");
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   149
                }
9008
1c23e333dd76 7031536: test/sun/security/krb5/auto/HttpNegotiateServer.java should not use static ports
weijun
parents: 8396
diff changeset
   150
                if (this.getRequestingPort() != proxyPort) {
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   151
                    throw new RuntimeException("Bad port");
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   152
                }
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   153
                if (!this.getRequestingURL().equals(proxyUrl)) {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   154
                    throw new RuntimeException("Bad url");
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   155
                }
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   156
                return new PasswordAuthentication(
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   157
                        PROXY_USER+"@"+REALM_PROXY, PROXY_PASS);
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   158
            } else  {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   159
                throw new RuntimeException("Bad requster type");
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   160
            }
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   161
        }
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   162
    }
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   163
5154
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   164
    /**
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   165
     * This Authenticator knows nothing
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   166
     */
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   167
    static class KnowNothingAuthenticator extends java.net.Authenticator {
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   168
        @Override
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   169
        public PasswordAuthentication getPasswordAuthentication () {
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   170
            HttpNegotiateServer.count++;
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   171
            return null;
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   172
        }
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   173
    }
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   174
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   175
    public static void main(String[] args)
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   176
            throws Exception {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   177
25151
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23010
diff changeset
   178
        System.setProperty("sun.security.krb5.debug", "true");
7a670121602e 8029994: Support "include" and "includedir" in krb5.conf
weijun
parents: 23010
diff changeset
   179
3046
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   180
        KDC kdcw = KDC.create(REALM_WEB);
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   181
        kdcw.addPrincipal(WEB_USER, WEB_PASS);
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   182
        kdcw.addPrincipalRandKey("krbtgt/" + REALM_WEB);
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   183
        kdcw.addPrincipalRandKey("HTTP/" + WEB_HOST);
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   184
3046
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   185
        KDC kdcp = KDC.create(REALM_PROXY);
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   186
        kdcp.addPrincipal(PROXY_USER, PROXY_PASS);
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   187
        kdcp.addPrincipalRandKey("krbtgt/" + REALM_PROXY);
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   188
        kdcp.addPrincipalRandKey("HTTP/" + PROXY_HOST);
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   189
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   190
        KDC.saveConfig(KRB5_CONF, kdcw, kdcp,
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   191
                "default_keytab_name = " + KRB5_TAB,
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   192
                "[domain_realm]",
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   193
                "",
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   194
                ".web.domain="+REALM_WEB,
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   195
                ".proxy.domain="+REALM_PROXY);
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   196
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   197
        System.setProperty("java.security.krb5.conf", KRB5_CONF);
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   198
        Config.refresh();
5154
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   199
        KDC.writeMultiKtab(KRB5_TAB, kdcw, kdcp);
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   200
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   201
        // Write a customized JAAS conf file, so that any kinit cache
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   202
        // will be ignored.
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   203
        System.setProperty("java.security.auth.login.config", OneKDC.JAAS_CONF);
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   204
        File f = new File(OneKDC.JAAS_CONF);
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   205
        FileOutputStream fos = new FileOutputStream(f);
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   206
        fos.write((
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   207
                "com.sun.security.jgss.krb5.initiate {\n" +
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   208
                "    com.sun.security.auth.module.Krb5LoginModule required;\n};\n"
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   209
                ).getBytes());
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   210
        fos.close();
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   211
9008
1c23e333dd76 7031536: test/sun/security/krb5/auto/HttpNegotiateServer.java should not use static ports
weijun
parents: 8396
diff changeset
   212
        HttpServer h1 = httpd("Negotiate", false,
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   213
                "HTTP/" + WEB_HOST + "@" + REALM_WEB, KRB5_TAB);
9008
1c23e333dd76 7031536: test/sun/security/krb5/auto/HttpNegotiateServer.java should not use static ports
weijun
parents: 8396
diff changeset
   214
        webPort = h1.getAddress().getPort();
1c23e333dd76 7031536: test/sun/security/krb5/auto/HttpNegotiateServer.java should not use static ports
weijun
parents: 8396
diff changeset
   215
        HttpServer h2 = httpd("Negotiate", true,
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   216
                "HTTP/" + PROXY_HOST + "@" + REALM_PROXY, KRB5_TAB);
9008
1c23e333dd76 7031536: test/sun/security/krb5/auto/HttpNegotiateServer.java should not use static ports
weijun
parents: 8396
diff changeset
   217
        proxyPort = h2.getAddress().getPort();
1c23e333dd76 7031536: test/sun/security/krb5/auto/HttpNegotiateServer.java should not use static ports
weijun
parents: 8396
diff changeset
   218
1c23e333dd76 7031536: test/sun/security/krb5/auto/HttpNegotiateServer.java should not use static ports
weijun
parents: 8396
diff changeset
   219
        webUrl = new URL("http://" + WEB_HOST +":" + webPort + "/a/b/c");
1c23e333dd76 7031536: test/sun/security/krb5/auto/HttpNegotiateServer.java should not use static ports
weijun
parents: 8396
diff changeset
   220
        proxyUrl = new URL("http://nosuchplace/a/b/c");
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   221
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   222
        try {
30685
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   223
            Exception e1 = null, e2 = null, e3 = null;
5154
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   224
            try {
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   225
                test6578647();
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   226
            } catch (Exception e) {
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   227
                e1 = e;
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   228
                e.printStackTrace();
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   229
            }
5154
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   230
            try {
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   231
                test6829283();
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   232
            } catch (Exception e) {
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   233
                e2 = e;
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   234
                e.printStackTrace();
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   235
            }
30685
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   236
            try {
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   237
                test8077155();
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   238
            } catch (Exception e) {
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   239
                e3 = e;
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   240
                e.printStackTrace();
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   241
            }
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   242
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   243
            if (e1 != null || e2 != null || e3 != null) {
5154
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   244
                throw new RuntimeException("Test error");
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   245
            }
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   246
        } finally {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   247
            // Must stop. Seems there's no HttpServer.startAsDaemon()
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   248
            if (h1 != null) h1.stop(0);
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   249
            if (h2 != null) h2.stop(0);
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   250
        }
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   251
    }
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   252
5154
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   253
    static void test6578647() throws Exception {
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   254
        BufferedReader reader;
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   255
        java.net.Authenticator.setDefault(new KnowAllAuthenticator());
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   256
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   257
        reader = new BufferedReader(new InputStreamReader(
42705
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   258
                webUrl.openConnection(Proxy.NO_PROXY).getInputStream()));
5154
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   259
        if (!reader.readLine().equals(CONTENT)) {
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   260
            throw new RuntimeException("Bad content");
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   261
        }
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   262
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   263
        reader = new BufferedReader(new InputStreamReader(
42705
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   264
                proxyUrl.openConnection(new Proxy(Proxy.Type.HTTP,
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   265
                                new InetSocketAddress(PROXY_HOST, proxyPort)))
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   266
                        .getInputStream()));
5154
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   267
        if (!reader.readLine().equals(CONTENT)) {
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   268
            throw new RuntimeException("Bad content");
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   269
        }
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   270
    }
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   271
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   272
    static void test6829283() throws Exception {
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   273
        BufferedReader reader;
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   274
        java.net.Authenticator.setDefault(new KnowNothingAuthenticator());
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   275
        try {
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   276
            new BufferedReader(new InputStreamReader(
42705
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   277
                    webUrl.openConnection(Proxy.NO_PROXY).getInputStream()));
5154
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   278
        } catch (IOException ioe) {
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   279
            // Will fail since no username and password is provided.
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   280
        }
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   281
        if (count > 1) {
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   282
            throw new RuntimeException("Authenticator called twice");
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   283
        }
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   284
    }
07af3c279166 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one
weijun
parents: 4236
diff changeset
   285
30685
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   286
    static void testConnect() {
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   287
        InputStream inputStream = null;
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   288
        try {
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   289
            URL url = webUrl;
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   290
42705
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   291
            URLConnection conn = url.openConnection(Proxy.NO_PROXY);
30685
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   292
            conn.connect();
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   293
            inputStream = conn.getInputStream();
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   294
            byte[] b = new byte[inputStream.available()];
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   295
            for (int j = 0; j < b.length; j++) {
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   296
                b[j] = (byte) inputStream.read();
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   297
            }
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   298
            String s = new String(b);
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   299
            System.out.println("Length: " + s.length());
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   300
            System.out.println(s);
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   301
        } catch (Exception ex) {
42705
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   302
            throw new RuntimeException(ex);
30685
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   303
        } finally {
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   304
            if (inputStream != null) {
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   305
                try {
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   306
                    inputStream.close();
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   307
                } catch (IOException e) {
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   308
                    e.printStackTrace();
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   309
                }
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   310
            }
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   311
        }
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   312
    }
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   313
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   314
    static void test8077155() throws Exception {
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   315
        final String username = WEB_USER;
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   316
        final char[] password = WEB_PASS;
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   317
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   318
        SecurityManager security = new SecurityManager();
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   319
        Policy.setPolicy(new SecurityPolicy());
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   320
        System.setSecurityManager(security);
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   321
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   322
        CallbackHandler callback = new CallbackHandler() {
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   323
            @Override
42705
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   324
            public void handle(Callback[] pCallbacks)
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   325
                    throws IOException, UnsupportedCallbackException {
30685
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   326
                for (Callback cb : pCallbacks) {
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   327
                    if (cb instanceof NameCallback) {
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   328
                        NameCallback ncb = (NameCallback)cb;
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   329
                        ncb.setName(username);
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   330
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   331
                    } else  if (cb instanceof PasswordCallback) {
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   332
                        PasswordCallback pwdcb = (PasswordCallback) cb;
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   333
                        pwdcb.setPassword(password);
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   334
                    }
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   335
                }
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   336
            }
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   337
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   338
        };
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   339
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   340
        final String jaasConfigName = "oracle.test.kerberos.login";
42705
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   341
        final String krb5LoginModule
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   342
                = "com.sun.security.auth.module.Krb5LoginModule";
30685
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   343
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   344
        Configuration loginConfig = new Configuration() {
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   345
            @Override
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   346
            public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   347
                if (! jaasConfigName.equals(name)) {
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   348
                    return new AppConfigurationEntry[0];
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   349
                }
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   350
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   351
                Map<String, String> options = new HashMap<String, String>();
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   352
                options.put("useTicketCache", Boolean.FALSE.toString());
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   353
                options.put("useKeyTab", Boolean.FALSE.toString());
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   354
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   355
                return new AppConfigurationEntry[] {
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   356
                        new AppConfigurationEntry(krb5LoginModule,
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   357
                                LoginModuleControlFlag.REQUIRED,
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   358
                                options)
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   359
                        };
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   360
            }
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   361
        };
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   362
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   363
        // oracle context/subject/login
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   364
        LoginContext context = null;
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   365
        try {
42705
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   366
            context = new LoginContext(
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   367
                    "oracle.test.kerberos.login", null, callback, loginConfig);
30685
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   368
            context.login();
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   369
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   370
        } catch (LoginException ex) {
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   371
            ex.printStackTrace();
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   372
            throw new RuntimeException(ex);
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   373
        }
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   374
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   375
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   376
        Subject subject = context.getSubject();
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   377
42705
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   378
        final PrivilegedExceptionAction<Object> test_action
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   379
                = new PrivilegedExceptionAction<Object>() {
30685
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   380
            public Object run() throws Exception {
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   381
                testConnect();
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   382
                return null;
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   383
            }
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   384
        };
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   385
42705
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   386
        System.err.println("\n\nExpecting to succeed when executing " +
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   387
                "with the the logged in subject.");
30685
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   388
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   389
        try {
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   390
            Subject.doAs(subject, test_action);
42705
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   391
            System.err.println("\n\nConnection succeed when executing " +
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   392
                    "with the the logged in subject.");
30685
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   393
        } catch (PrivilegedActionException e) {
42705
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   394
            System.err.println("\n\nFailure unexpected when executing " +
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   395
                    "with the the logged in subject.");
30685
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   396
            e.printStackTrace();
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   397
            throw new RuntimeException("Failed to login as subject");
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   398
        }
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   399
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   400
        try {
42705
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   401
            System.err.println("\n\nExpecting to fail when running " +
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   402
                    "with the current user's login.");
30685
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   403
            testConnect();
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   404
        } catch (Exception ex) {
42705
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   405
            System.err.println("\nConnect failed when running " +
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   406
                    "with the current user's login:\n" + ex.getMessage());
30685
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   407
        }
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   408
    }
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   409
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   410
    /**
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   411
     * Creates and starts an HTTP or proxy server that requires
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   412
     * Negotiate authentication.
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   413
     * @param scheme "Negotiate" or "Kerberos"
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   414
     * @param principal the krb5 service principal the server runs with
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   415
     * @return the server
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   416
     */
9008
1c23e333dd76 7031536: test/sun/security/krb5/auto/HttpNegotiateServer.java should not use static ports
weijun
parents: 8396
diff changeset
   417
    public static HttpServer httpd(String scheme, boolean proxy,
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   418
            String principal, String ktab) throws Exception {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   419
        MyHttpHandler h = new MyHttpHandler();
9008
1c23e333dd76 7031536: test/sun/security/krb5/auto/HttpNegotiateServer.java should not use static ports
weijun
parents: 8396
diff changeset
   420
        HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   421
        HttpContext hc = server.createContext("/", h);
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   422
        hc.setAuthenticator(new MyServerAuthenticator(
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   423
                proxy, scheme, principal, ktab));
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   424
        server.start();
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   425
        return server;
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   426
    }
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   427
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   428
    static class MyHttpHandler implements HttpHandler {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   429
        public void handle(HttpExchange t) throws IOException {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   430
            t.sendResponseHeaders(200, 0);
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   431
            t.getResponseBody().write(CONTENT.getBytes());
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   432
            t.close();
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   433
        }
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   434
    }
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   435
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   436
    static class MyServerAuthenticator
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   437
            extends com.sun.net.httpserver.Authenticator {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   438
        Subject s = new Subject();
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   439
        GSSManager m = null;
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   440
        GSSCredential cred = null;
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   441
        String scheme = null;
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   442
        String reqHdr = "WWW-Authenticate";
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   443
        String respHdr = "Authorization";
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   444
        int err = HttpURLConnection.HTTP_UNAUTHORIZED;
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   445
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   446
        public MyServerAuthenticator(boolean proxy, String scheme,
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   447
                String principal, String ktab) throws Exception {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   448
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   449
            this.scheme = scheme;
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   450
            if (proxy) {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   451
                reqHdr = "Proxy-Authenticate";
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   452
                respHdr = "Proxy-Authorization";
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   453
                err = HttpURLConnection.HTTP_PROXY_AUTH;
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   454
            }
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   455
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   456
            Krb5LoginModule krb5 = new Krb5LoginModule();
7977
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 5506
diff changeset
   457
            Map<String, String> map = new HashMap<>();
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 5506
diff changeset
   458
            Map<String, Object> shared = new HashMap<>();
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   459
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   460
            map.put("storeKey", "true");
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   461
            map.put("isInitiator", "false");
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   462
            map.put("useKeyTab", "true");
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   463
            map.put("keyTab", ktab);
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   464
            map.put("principal", principal);
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   465
            krb5.initialize(s, null, shared, map);
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   466
            krb5.login();
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   467
            krb5.commit();
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   468
            m = GSSManager.getInstance();
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   469
            cred = Subject.doAs(s, new PrivilegedExceptionAction<GSSCredential>() {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   470
                @Override
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   471
                public GSSCredential run() throws Exception {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   472
                    System.err.println("Creating GSSCredential");
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   473
                    return m.createCredential(
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   474
                            null,
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   475
                            GSSCredential.INDEFINITE_LIFETIME,
42705
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   476
                            MyServerAuthenticator.this.scheme
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   477
                                        .equalsIgnoreCase("Negotiate") ?
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   478
                                    GSSUtil.GSS_SPNEGO_MECH_OID :
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   479
                                    GSSUtil.GSS_KRB5_MECH_OID,
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   480
                            GSSCredential.ACCEPT_ONLY);
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   481
                }
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   482
            });
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   483
        }
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   484
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   485
        @Override
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   486
        public Result authenticate(HttpExchange exch) {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   487
            // The GSContext is stored in an HttpContext attribute named
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   488
            // "GSSContext" and is created at the first request.
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   489
            GSSContext c = null;
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   490
            String auth = exch.getRequestHeaders().getFirst(respHdr);
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   491
            try {
42705
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   492
                c = (GSSContext)exch.getHttpContext()
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   493
                        .getAttributes().get("GSSContext");
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   494
                if (auth == null) {                 // First request
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   495
                    Headers map = exch.getResponseHeaders();
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   496
                    map.set (reqHdr, scheme);        // Challenge!
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   497
                    c = Subject.doAs(s, new PrivilegedExceptionAction<GSSContext>() {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   498
                        @Override
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   499
                        public GSSContext run() throws Exception {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   500
                            return m.createContext(cred);
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   501
                        }
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   502
                    });
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   503
                    exch.getHttpContext().getAttributes().put("GSSContext", c);
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   504
                    return new com.sun.net.httpserver.Authenticator.Retry(err);
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   505
                } else {                            // Later requests
42705
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   506
                    byte[] token = Base64.getMimeDecoder()
5163a5964bd7 8171340: HttpNegotiateServer/java test should not use system proxy on Mac
weijun
parents: 42688
diff changeset
   507
                            .decode(auth.split(" ")[1]);
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   508
                    token = c.acceptSecContext(token, 0, token.length);
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   509
                    Headers map = exch.getResponseHeaders();
16020
b57c48f16179 8006182: cleanup to use java.util.Base64 in java security component, providers, and regression tests
msheppar
parents: 11107
diff changeset
   510
                    map.set (reqHdr, scheme + " " + Base64.getMimeEncoder()
b57c48f16179 8006182: cleanup to use java.util.Base64 in java security component, providers, and regression tests
msheppar
parents: 11107
diff changeset
   511
                            .encodeToString(token).replaceAll("\\s", ""));
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   512
                    if (c.isEstablished()) {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   513
                        return new com.sun.net.httpserver.Authenticator.Success(
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   514
                                new HttpPrincipal(c.getSrcName().toString(), ""));
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   515
                    } else {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   516
                        return new com.sun.net.httpserver.Authenticator.Retry(err);
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   517
                    }
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   518
                }
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   519
            } catch (Exception e) {
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   520
                throw new RuntimeException(e);
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   521
            }
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   522
        }
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   523
    }
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
diff changeset
   524
}
30685
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   525
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   526
class SecurityPolicy extends Policy {
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   527
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   528
    private static Permissions perms;
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   529
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   530
    public SecurityPolicy() {
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   531
        super();
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   532
        if (perms == null) {
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   533
            perms = new Permissions();
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   534
            perms.add(new AllPermission());
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   535
        }
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   536
    }
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   537
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   538
    @Override
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   539
    public PermissionCollection getPermissions(CodeSource codesource) {
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   540
        return perms;
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   541
    }
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   542
5806d3adbd6b 8077155: LoginContext Subject ignored by jdk8 sun.net.www.protocol.http.HttpURLConnection
robm
parents: 25151
diff changeset
   543
}