author | dfuchs |
Thu, 22 Feb 2018 17:33:21 +0000 | |
branch | http-client-branch |
changeset 56165 | 8a6065d830b9 |
parent 56128 | 249a863b0aca |
child 56167 | 96fa4f49a9ff |
permissions | -rw-r--r-- |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
1 |
/* |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
4 |
* |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
8 |
* |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
13 |
* accompanied this code). |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
14 |
* |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
18 |
* |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
21 |
* questions. |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
22 |
*/ |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
23 |
|
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
24 |
import java.io.IOException; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
25 |
import java.io.UncheckedIOException; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
26 |
import java.math.BigInteger; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
27 |
import java.net.ProxySelector; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
28 |
import java.net.URI; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
29 |
import java.nio.charset.StandardCharsets; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
30 |
import java.security.NoSuchAlgorithmException; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
31 |
import java.util.Arrays; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
32 |
import java.util.Base64; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
33 |
import java.util.EnumSet; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
34 |
import java.util.List; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
35 |
import java.util.Optional; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
36 |
import java.util.Random; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
37 |
import java.util.concurrent.CompletableFuture; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
38 |
import java.util.concurrent.CompletionException; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
39 |
import java.util.concurrent.ConcurrentHashMap; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
40 |
import java.util.concurrent.ConcurrentMap; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
41 |
import java.util.concurrent.atomic.AtomicInteger; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
42 |
import java.util.concurrent.atomic.AtomicLong; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
43 |
import java.util.stream.Collectors; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
44 |
import java.util.stream.Stream; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
45 |
import javax.net.ssl.SSLContext; |
56089
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
56081
diff
changeset
|
46 |
import java.net.http.HttpClient; |
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
56081
diff
changeset
|
47 |
import java.net.http.HttpClient.Version; |
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
56081
diff
changeset
|
48 |
import java.net.http.HttpRequest; |
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
56081
diff
changeset
|
49 |
import java.net.http.HttpResponse; |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
50 |
import jdk.testlibrary.SimpleSSLContext; |
56054
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
51 |
import sun.net.NetProperties; |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
52 |
import sun.net.www.HeaderParser; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
53 |
import static java.lang.System.out; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
54 |
import static java.lang.String.format; |
56089
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
56081
diff
changeset
|
55 |
import static java.net.http.HttpResponse.BodyHandler.asLines; |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
56 |
|
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
57 |
/** |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
58 |
* @test |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
59 |
* @summary this test verifies that a client may provides authorization |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
60 |
* headers directly when connecting with a server. |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
61 |
* @bug 8087112 |
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
62 |
* @library /lib/testlibrary http2/server |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
63 |
* @build jdk.testlibrary.SimpleSSLContext HttpServerAdapters DigestEchoServer DigestEchoClient |
56092
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
64 |
* @modules java.net.http/jdk.internal.net.http.common |
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
65 |
* java.net.http/jdk.internal.net.http.frame |
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
66 |
* java.net.http/jdk.internal.net.http.hpack |
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
67 |
* java.logging |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
68 |
* java.base/sun.net.www.http |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
69 |
* java.base/sun.net.www |
56054
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
70 |
* java.base/sun.net |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
71 |
* @run main/othervm DigestEchoClient |
56054
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
72 |
* @run main/othervm -Djdk.http.auth.proxying.disabledSchemes= |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
73 |
* -Djdk.http.auth.tunneling.disabledSchemes= |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
74 |
* DigestEchoClient |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
75 |
*/ |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
76 |
|
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
77 |
public class DigestEchoClient { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
78 |
|
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
79 |
static final String data[] = { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
80 |
"Lorem ipsum", |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
81 |
"dolor sit amet", |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
82 |
"consectetur adipiscing elit, sed do eiusmod tempor", |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
83 |
"quis nostrud exercitation ullamco", |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
84 |
"laboris nisi", |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
85 |
"ut", |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
86 |
"aliquip ex ea commodo consequat." + |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
87 |
"Duis aute irure dolor in reprehenderit in voluptate velit esse" + |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
88 |
"cillum dolore eu fugiat nulla pariatur.", |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
89 |
"Excepteur sint occaecat cupidatat non proident." |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
90 |
}; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
91 |
|
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
92 |
static final AtomicLong serverCount = new AtomicLong(); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
93 |
static final class EchoServers { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
94 |
final DigestEchoServer.HttpAuthType authType; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
95 |
final DigestEchoServer.HttpAuthSchemeType authScheme; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
96 |
final String protocolScheme; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
97 |
final String key; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
98 |
final DigestEchoServer server; |
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
99 |
final Version serverVersion; |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
100 |
|
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
101 |
private EchoServers(DigestEchoServer server, |
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
102 |
Version version, |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
103 |
String protocolScheme, |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
104 |
DigestEchoServer.HttpAuthType authType, |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
105 |
DigestEchoServer.HttpAuthSchemeType authScheme) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
106 |
this.authType = authType; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
107 |
this.authScheme = authScheme; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
108 |
this.protocolScheme = protocolScheme; |
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
109 |
this.key = key(version, protocolScheme, authType, authScheme); |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
110 |
this.server = server; |
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
111 |
this.serverVersion = version; |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
112 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
113 |
|
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
114 |
static String key(Version version, |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
115 |
String protocolScheme, |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
116 |
DigestEchoServer.HttpAuthType authType, |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
117 |
DigestEchoServer.HttpAuthSchemeType authScheme) { |
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
118 |
return String.format("%s:%s:%s:%s", version, protocolScheme, authType, authScheme); |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
119 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
120 |
|
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
121 |
private static EchoServers create(Version version, |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
122 |
String protocolScheme, |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
123 |
DigestEchoServer.HttpAuthType authType, |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
124 |
DigestEchoServer.HttpAuthSchemeType authScheme) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
125 |
try { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
126 |
serverCount.incrementAndGet(); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
127 |
DigestEchoServer server = |
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
128 |
DigestEchoServer.create(version, protocolScheme, authType, authScheme); |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
129 |
return new EchoServers(server, version, protocolScheme, authType, authScheme); |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
130 |
} catch (IOException x) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
131 |
throw new UncheckedIOException(x); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
132 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
133 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
134 |
|
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
135 |
public static DigestEchoServer of(Version version, |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
136 |
String protocolScheme, |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
137 |
DigestEchoServer.HttpAuthType authType, |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
138 |
DigestEchoServer.HttpAuthSchemeType authScheme) { |
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
139 |
String key = key(version, protocolScheme, authType, authScheme); |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
140 |
return servers.computeIfAbsent(key, (k) -> |
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
141 |
create(version, protocolScheme, authType, authScheme)).server; |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
142 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
143 |
|
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
144 |
public static void stop() { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
145 |
for (EchoServers s : servers.values()) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
146 |
s.server.stop(); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
147 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
148 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
149 |
|
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
150 |
private static final ConcurrentMap<String, EchoServers> servers = new ConcurrentHashMap<>(); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
151 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
152 |
|
56054
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
153 |
final static String PROXY_DISABLED = NetProperties.get("jdk.http.auth.proxying.disabledSchemes"); |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
154 |
final static String TUNNEL_DISABLED = NetProperties.get("jdk.http.auth.tunneling.disabledSchemes"); |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
155 |
static { |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
156 |
System.out.println("jdk.http.auth.proxying.disabledSchemes=" + PROXY_DISABLED); |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
157 |
System.out.println("jdk.http.auth.tunneling.disabledSchemes=" + TUNNEL_DISABLED); |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
158 |
} |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
159 |
|
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
160 |
|
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
161 |
|
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
162 |
static final AtomicInteger NC = new AtomicInteger(); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
163 |
static final Random random = new Random(); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
164 |
static final SSLContext context; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
165 |
static { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
166 |
try { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
167 |
context = new SimpleSSLContext().get(); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
168 |
SSLContext.setDefault(context); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
169 |
} catch (Exception x) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
170 |
throw new ExceptionInInitializerError(x); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
171 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
172 |
} |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
173 |
static final List<Boolean> BOOLEANS = List.of(true, false); |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
174 |
|
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
175 |
final boolean useSSL; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
176 |
final DigestEchoServer.HttpAuthSchemeType authScheme; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
177 |
final DigestEchoServer.HttpAuthType authType; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
178 |
DigestEchoClient(boolean useSSL, |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
179 |
DigestEchoServer.HttpAuthSchemeType authScheme, |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
180 |
DigestEchoServer.HttpAuthType authType) |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
181 |
throws IOException { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
182 |
this.useSSL = useSSL; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
183 |
this.authScheme = authScheme; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
184 |
this.authType = authType; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
185 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
186 |
|
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
187 |
static final AtomicLong clientCount = new AtomicLong(); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
188 |
public HttpClient newHttpClient(DigestEchoServer server) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
189 |
clientCount.incrementAndGet(); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
190 |
HttpClient.Builder builder = HttpClient.newBuilder(); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
191 |
if (useSSL) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
192 |
builder.sslContext(context); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
193 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
194 |
switch (authScheme) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
195 |
case BASIC: |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
196 |
builder = builder.authenticator(DigestEchoServer.AUTHENTICATOR); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
197 |
break; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
198 |
case BASICSERVER: |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
199 |
// don't set the authenticator: we will handle the header ourselves. |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
200 |
// builder = builder.authenticator(DigestEchoServer.AUTHENTICATOR); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
201 |
break; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
202 |
default: |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
203 |
break; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
204 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
205 |
switch (authType) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
206 |
case PROXY: |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
207 |
builder = builder.proxy(ProxySelector.of(server.getProxyAddress())); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
208 |
break; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
209 |
case PROXY305: |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
210 |
builder = builder.proxy(ProxySelector.of(server.getProxyAddress())); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
211 |
builder = builder.followRedirects(HttpClient.Redirect.SAME_PROTOCOL); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
212 |
break; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
213 |
case SERVER307: |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
214 |
builder = builder.followRedirects(HttpClient.Redirect.SAME_PROTOCOL); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
215 |
break; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
216 |
default: |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
217 |
break; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
218 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
219 |
return builder.build(); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
220 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
221 |
|
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
222 |
public static List<Version> serverVersions(Version clientVersion) { |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
223 |
if (clientVersion == Version.HTTP_1_1) { |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
224 |
return List.of(clientVersion); |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
225 |
} else { |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
226 |
return List.of(Version.values()); |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
227 |
} |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
228 |
} |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
229 |
|
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
230 |
public static List<Version> clientVersions() { |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
231 |
return List.of(Version.values()); |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
232 |
} |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
233 |
|
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
234 |
public static List<Boolean> expectContinue(Version serverVersion) { |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
235 |
if (serverVersion == Version.HTTP_1_1) { |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
236 |
return BOOLEANS; |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
237 |
} else { |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
238 |
// our test HTTP/2 server does not support Expect: 100-Continue |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
239 |
return List.of(Boolean.FALSE); |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
240 |
} |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
241 |
} |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
242 |
|
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
243 |
public static void main(String[] args) throws Exception { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
244 |
boolean useSSL = false; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
245 |
EnumSet<DigestEchoServer.HttpAuthType> types = |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
246 |
EnumSet.complementOf(EnumSet.of(DigestEchoServer.HttpAuthType.PROXY305)); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
247 |
if (args != null && args.length >= 1) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
248 |
useSSL = "SSL".equals(args[0]); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
249 |
if (args.length > 1) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
250 |
List<DigestEchoServer.HttpAuthType> httpAuthTypes = |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
251 |
Stream.of(Arrays.copyOfRange(args, 1, args.length)) |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
252 |
.map(DigestEchoServer.HttpAuthType::valueOf) |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
253 |
.collect(Collectors.toList()); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
254 |
types = EnumSet.copyOf(httpAuthTypes); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
255 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
256 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
257 |
try { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
258 |
for (DigestEchoServer.HttpAuthType authType : types) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
259 |
// The test server does not support PROXY305 properly |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
260 |
if (authType == DigestEchoServer.HttpAuthType.PROXY305) continue; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
261 |
EnumSet<DigestEchoServer.HttpAuthSchemeType> basics = |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
262 |
EnumSet.of(DigestEchoServer.HttpAuthSchemeType.BASICSERVER, |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
263 |
DigestEchoServer.HttpAuthSchemeType.BASIC); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
264 |
for (DigestEchoServer.HttpAuthSchemeType authScheme : basics) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
265 |
DigestEchoClient dec = new DigestEchoClient(useSSL, |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
266 |
authScheme, |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
267 |
authType); |
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
268 |
for (Version clientVersion : clientVersions()) { |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
269 |
for (Version serverVersion : serverVersions(clientVersion)) { |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
270 |
for (boolean expectContinue : expectContinue(serverVersion)) { |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
271 |
for (boolean async : BOOLEANS) { |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
272 |
for (boolean preemptive : BOOLEANS) { |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
273 |
dec.testBasic(clientVersion, |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
274 |
serverVersion, async, |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
275 |
expectContinue, preemptive); |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
276 |
} |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
277 |
} |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
278 |
} |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
279 |
} |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
280 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
281 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
282 |
EnumSet<DigestEchoServer.HttpAuthSchemeType> digests = |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
283 |
EnumSet.of(DigestEchoServer.HttpAuthSchemeType.DIGEST); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
284 |
for (DigestEchoServer.HttpAuthSchemeType authScheme : digests) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
285 |
DigestEchoClient dec = new DigestEchoClient(useSSL, |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
286 |
authScheme, |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
287 |
authType); |
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
288 |
for (Version clientVersion : clientVersions()) { |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
289 |
for (Version serverVersion : serverVersions(clientVersion)) { |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
290 |
for (boolean expectContinue : expectContinue(serverVersion)) { |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
291 |
for (boolean async : BOOLEANS) { |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
292 |
dec.testDigest(clientVersion, serverVersion, |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
293 |
async, expectContinue); |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
294 |
} |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
295 |
} |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
296 |
} |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
297 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
298 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
299 |
} |
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
300 |
} catch(Throwable t) { |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
301 |
System.out.println("Unexpected exception: exiting: " + t); |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
302 |
t.printStackTrace(); |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
303 |
throw t; |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
304 |
} finally { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
305 |
EchoServers.stop(); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
306 |
System.out.println(" ---------------------------------------------------------- "); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
307 |
System.out.println(String.format("DigestEchoClient %s %s", useSSL ? "SSL" : "CLEAR", types)); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
308 |
System.out.println(String.format("Created %d clients and %d servers", |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
309 |
clientCount.get(), serverCount.get())); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
310 |
System.out.println(String.format("basics: %d requests sent, %d ns / req", |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
311 |
basicCount.get(), basics.get())); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
312 |
System.out.println(String.format("digests: %d requests sent, %d ns / req", |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
313 |
digestCount.get(), digests.get())); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
314 |
System.out.println(" ---------------------------------------------------------- "); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
315 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
316 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
317 |
|
56054
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
318 |
boolean isSchemeDisabled() { |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
319 |
String disabledSchemes; |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
320 |
if (isProxy(authType)) { |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
321 |
disabledSchemes = useSSL |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
322 |
? TUNNEL_DISABLED |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
323 |
: PROXY_DISABLED; |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
324 |
} else return false; |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
325 |
if (disabledSchemes == null |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
326 |
|| disabledSchemes.isEmpty()) { |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
327 |
return false; |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
328 |
} |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
329 |
String scheme; |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
330 |
switch (authScheme) { |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
331 |
case DIGEST: |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
332 |
scheme = "Digest"; |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
333 |
break; |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
334 |
case BASIC: |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
335 |
scheme = "Basic"; |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
336 |
break; |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
337 |
case BASICSERVER: |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
338 |
scheme = "Basic"; |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
339 |
break; |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
340 |
case NONE: |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
341 |
return false; |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
342 |
default: |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
343 |
throw new InternalError("Unknown auth scheme: " + authScheme); |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
344 |
} |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
345 |
return Stream.of(disabledSchemes.split(",")) |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
346 |
.map(String::trim) |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
347 |
.filter(scheme::equalsIgnoreCase) |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
348 |
.findAny() |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
349 |
.isPresent(); |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
350 |
} |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
351 |
|
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
352 |
final static AtomicLong basics = new AtomicLong(); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
353 |
final static AtomicLong basicCount = new AtomicLong(); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
354 |
// @Test |
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
355 |
void testBasic(Version clientVersion, Version serverVersion, boolean async, |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
356 |
boolean expectContinue, boolean preemptive) |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
357 |
throws Exception |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
358 |
{ |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
359 |
final boolean addHeaders = authScheme == DigestEchoServer.HttpAuthSchemeType.BASICSERVER; |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
360 |
// !preemptive has no meaning if we don't handle the authorization |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
361 |
// headers ourselves |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
362 |
if (!preemptive && !addHeaders) return; |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
363 |
|
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
364 |
out.println(format("*** testBasic: client: %s, server: %s, async: %s, useSSL: %s, " + |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
365 |
"authScheme: %s, authType: %s, expectContinue: %s preemptive: %s***", |
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
366 |
clientVersion, serverVersion, async, useSSL, authScheme, authType, |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
367 |
expectContinue, preemptive)); |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
368 |
|
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
369 |
DigestEchoServer server = EchoServers.of(serverVersion, |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
370 |
useSSL ? "https" : "http", authType, authScheme); |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
371 |
URI uri = DigestEchoServer.uri(useSSL ? "https" : "http", |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
372 |
server.getServerAddress(), "/foo/"); |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
373 |
|
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
374 |
HttpClient client = newHttpClient(server); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
375 |
HttpResponse<String> r; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
376 |
CompletableFuture<HttpResponse<String>> cf1; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
377 |
String auth = null; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
378 |
|
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
379 |
try { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
380 |
for (int i=0; i<data.length; i++) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
381 |
out.println(DigestEchoServer.now() + " ----- iteration " + i + " -----"); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
382 |
List<String> lines = List.of(Arrays.copyOfRange(data, 0, i+1)); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
383 |
assert lines.size() == i + 1; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
384 |
String body = lines.stream().collect(Collectors.joining("\r\n")); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
385 |
HttpRequest.BodyPublisher reqBody = HttpRequest.BodyPublisher.fromString(body); |
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
386 |
HttpRequest.Builder builder = HttpRequest.newBuilder(uri).version(clientVersion) |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
387 |
.POST(reqBody).expectContinue(expectContinue); |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
388 |
boolean isTunnel = isProxy(authType) && useSSL; |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
389 |
if (addHeaders) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
390 |
// handle authentication ourselves |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
391 |
assert !client.authenticator().isPresent(); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
392 |
if (auth == null) auth = "Basic " + getBasicAuth("arthur"); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
393 |
try { |
56054
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
394 |
if ((i > 0 || preemptive) |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
395 |
&& (!isTunnel || i == 0 || isSchemeDisabled())) { |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
396 |
// In case of a SSL tunnel through proxy then only the |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
397 |
// first request should require proxy authorization |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
398 |
// Though this might be invalidated if the server decides |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
399 |
// to close the connection... |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
400 |
out.println(String.format("%s adding %s: %s", |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
401 |
DigestEchoServer.now(), |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
402 |
authorizationKey(authType), |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
403 |
auth)); |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
404 |
builder = builder.header(authorizationKey(authType), auth); |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
405 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
406 |
} catch (IllegalArgumentException x) { |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
407 |
throw x; |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
408 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
409 |
} else { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
410 |
// let the stack do the authentication |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
411 |
assert client.authenticator().isPresent(); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
412 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
413 |
long start = System.nanoTime(); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
414 |
HttpRequest request = builder.build(); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
415 |
HttpResponse<Stream<String>> resp; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
416 |
try { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
417 |
if (async) { |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
418 |
resp = client.sendAsync(request, asLines()).join(); |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
419 |
} else { |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
420 |
resp = client.send(request, asLines()); |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
421 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
422 |
} catch (Throwable t) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
423 |
long stop = System.nanoTime(); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
424 |
synchronized (basicCount) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
425 |
long n = basicCount.getAndIncrement(); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
426 |
basics.set((basics.get() * n + (stop - start)) / (n + 1)); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
427 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
428 |
// unwrap CompletionException |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
429 |
if (t instanceof CompletionException) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
430 |
assert t.getCause() != null; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
431 |
t = t.getCause(); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
432 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
433 |
throw new RuntimeException("Unexpected exception: " + t, t); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
434 |
} |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
435 |
|
56054
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
436 |
if (addHeaders && !preemptive && (i==0 || isSchemeDisabled())) { |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
437 |
assert resp.statusCode() == 401 || resp.statusCode() == 407; |
56081
20c6742e5545
http-client-branch: 8196848: SplitResponseSSL test failing intermitently (but rarely) with HttpClientImpl shutting down.
dfuchs
parents:
56070
diff
changeset
|
438 |
Stream<String> respBody = resp.body(); |
20c6742e5545
http-client-branch: 8196848: SplitResponseSSL test failing intermitently (but rarely) with HttpClientImpl shutting down.
dfuchs
parents:
56070
diff
changeset
|
439 |
if (respBody != null) { |
20c6742e5545
http-client-branch: 8196848: SplitResponseSSL test failing intermitently (but rarely) with HttpClientImpl shutting down.
dfuchs
parents:
56070
diff
changeset
|
440 |
System.out.printf("Response body (%s):\n", resp.statusCode()); |
20c6742e5545
http-client-branch: 8196848: SplitResponseSSL test failing intermitently (but rarely) with HttpClientImpl shutting down.
dfuchs
parents:
56070
diff
changeset
|
441 |
respBody.forEach(System.out::println); |
20c6742e5545
http-client-branch: 8196848: SplitResponseSSL test failing intermitently (but rarely) with HttpClientImpl shutting down.
dfuchs
parents:
56070
diff
changeset
|
442 |
} |
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
443 |
System.out.println(String.format("%s received: adding header %s: %s", |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
444 |
resp.statusCode(), authorizationKey(authType), auth)); |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
445 |
request = HttpRequest.newBuilder(uri).version(clientVersion) |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
446 |
.POST(reqBody).header(authorizationKey(authType), auth).build(); |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
447 |
if (async) { |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
448 |
resp = client.sendAsync(request, asLines()).join(); |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
449 |
} else { |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
450 |
resp = client.send(request, asLines()); |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
451 |
} |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
452 |
} |
56054
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
453 |
final List<String> respLines; |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
454 |
try { |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
455 |
if (isSchemeDisabled()) { |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
456 |
if (resp.statusCode() != 407) { |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
457 |
throw new RuntimeException("expected 407 not received"); |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
458 |
} |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
459 |
System.out.println("Scheme disabled for [" + authType |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
460 |
+ ", " + authScheme |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
461 |
+ ", " + (useSSL ? "HTTP" : "HTTPS") |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
462 |
+ "]: Received expected " + resp.statusCode()); |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
463 |
continue; |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
464 |
} else { |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
465 |
System.out.println("Scheme enabled for [" + authType |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
466 |
+ ", " + authScheme |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
467 |
+ ", " + (useSSL ? "HTTPS" : "HTTP") |
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
468 |
+ "]: Expecting 200, response is: " + resp); |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
469 |
assert resp.statusCode() == 200 : "200 expected, received " + resp; |
56054
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
470 |
respLines = resp.body().collect(Collectors.toList()); |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
471 |
} |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
472 |
} finally { |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
473 |
long stop = System.nanoTime(); |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
474 |
synchronized (basicCount) { |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
475 |
long n = basicCount.getAndIncrement(); |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
476 |
basics.set((basics.get() * n + (stop - start)) / (n + 1)); |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
477 |
} |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
478 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
479 |
if (!lines.equals(respLines)) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
480 |
throw new RuntimeException("Unexpected response: " + respLines); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
481 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
482 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
483 |
} finally { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
484 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
485 |
System.out.println("OK"); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
486 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
487 |
|
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
488 |
String getBasicAuth(String username) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
489 |
StringBuilder builder = new StringBuilder(username); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
490 |
builder.append(':'); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
491 |
for (char c : DigestEchoServer.AUTHENTICATOR.getPassword(username)) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
492 |
builder.append(c); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
493 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
494 |
return Base64.getEncoder().encodeToString(builder.toString().getBytes(StandardCharsets.UTF_8)); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
495 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
496 |
|
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
497 |
final static AtomicLong digests = new AtomicLong(); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
498 |
final static AtomicLong digestCount = new AtomicLong(); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
499 |
// @Test |
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
500 |
void testDigest(Version clientVersion, Version serverVersion, |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
501 |
boolean async, boolean expectContinue) |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
502 |
throws Exception |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
503 |
{ |
56165
8a6065d830b9
http-client-branch: Add a test for BodySubscribers throwing in getBody() or returning exceptionally completed CFs
dfuchs
parents:
56128
diff
changeset
|
504 |
String test = format("testDigest: client: %s, server: %s, async: %s, useSSL: %s, " + |
8a6065d830b9
http-client-branch: Add a test for BodySubscribers throwing in getBody() or returning exceptionally completed CFs
dfuchs
parents:
56128
diff
changeset
|
505 |
"authScheme: %s, authType: %s, expectContinue: %s", |
8a6065d830b9
http-client-branch: Add a test for BodySubscribers throwing in getBody() or returning exceptionally completed CFs
dfuchs
parents:
56128
diff
changeset
|
506 |
clientVersion, serverVersion, async, useSSL, |
8a6065d830b9
http-client-branch: Add a test for BodySubscribers throwing in getBody() or returning exceptionally completed CFs
dfuchs
parents:
56128
diff
changeset
|
507 |
authScheme, authType, expectContinue); |
8a6065d830b9
http-client-branch: Add a test for BodySubscribers throwing in getBody() or returning exceptionally completed CFs
dfuchs
parents:
56128
diff
changeset
|
508 |
out.println("*** " + test + " ***"); |
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
509 |
DigestEchoServer server = EchoServers.of(serverVersion, |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
510 |
useSSL ? "https" : "http", authType, authScheme); |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
511 |
|
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
512 |
URI uri = DigestEchoServer.uri(useSSL ? "https" : "http", |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
513 |
server.getServerAddress(), "/foo/"); |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
514 |
|
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
515 |
HttpClient client = newHttpClient(server); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
516 |
HttpResponse<String> r; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
517 |
CompletableFuture<HttpResponse<String>> cf1; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
518 |
byte[] cnonce = new byte[16]; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
519 |
String cnonceStr = null; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
520 |
DigestEchoServer.DigestResponse challenge = null; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
521 |
|
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
522 |
try { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
523 |
for (int i=0; i<data.length; i++) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
524 |
out.println(DigestEchoServer.now() + "----- iteration " + i + " -----"); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
525 |
List<String> lines = List.of(Arrays.copyOfRange(data, 0, i+1)); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
526 |
assert lines.size() == i + 1; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
527 |
String body = lines.stream().collect(Collectors.joining("\r\n")); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
528 |
HttpRequest.BodyPublisher reqBody = HttpRequest.BodyPublisher.fromString(body); |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
529 |
HttpRequest.Builder reqBuilder = HttpRequest |
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
530 |
.newBuilder(uri).version(clientVersion).POST(reqBody) |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
531 |
.expectContinue(expectContinue); |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
532 |
|
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
533 |
boolean isTunnel = isProxy(authType) && useSSL; |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
534 |
String digestMethod = isTunnel ? "CONNECT" : "POST"; |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
535 |
|
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
536 |
// In case of a tunnel connection only the first request |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
537 |
// which establishes the tunnel needs to authenticate with |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
538 |
// the proxy. |
56054
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
539 |
if (challenge != null && (!isTunnel || isSchemeDisabled())) { |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
540 |
assert cnonceStr != null; |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
541 |
String auth = digestResponse(uri, digestMethod, challenge, cnonceStr); |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
542 |
try { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
543 |
reqBuilder = reqBuilder.header(authorizationKey(authType), auth); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
544 |
} catch (IllegalArgumentException x) { |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
545 |
throw x; |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
546 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
547 |
} |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
548 |
|
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
549 |
long start = System.nanoTime(); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
550 |
HttpRequest request = reqBuilder.build(); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
551 |
HttpResponse<Stream<String>> resp; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
552 |
if (async) { |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
553 |
resp = client.sendAsync(request, asLines()).join(); |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
554 |
} else { |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
555 |
resp = client.send(request, asLines()); |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
556 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
557 |
System.out.println(resp); |
56165
8a6065d830b9
http-client-branch: Add a test for BodySubscribers throwing in getBody() or returning exceptionally completed CFs
dfuchs
parents:
56128
diff
changeset
|
558 |
assert challenge != null || resp.statusCode() == 401 || resp.statusCode() == 407 |
8a6065d830b9
http-client-branch: Add a test for BodySubscribers throwing in getBody() or returning exceptionally completed CFs
dfuchs
parents:
56128
diff
changeset
|
559 |
: "challenge=" + challenge + ", resp=" + resp + ", test=[" + test + "]"; |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
560 |
if (resp.statusCode() == 401 || resp.statusCode() == 407) { |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
561 |
// This assert may need to be relaxed if our server happened to |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
562 |
// decide to close the tunnel connection, in which case we would |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
563 |
// receive 407 again... |
56054
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
564 |
assert challenge == null || !isTunnel || isSchemeDisabled() |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
565 |
: "No proxy auth should be required after establishing an SSL tunnel"; |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
566 |
|
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
567 |
System.out.println("Received " + resp.statusCode() + " answering challenge..."); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
568 |
random.nextBytes(cnonce); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
569 |
cnonceStr = new BigInteger(1, cnonce).toString(16); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
570 |
System.out.println("Response headers: " + resp.headers()); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
571 |
Optional<String> authenticateOpt = resp.headers().firstValue(authenticateKey(authType)); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
572 |
String authenticate = authenticateOpt.orElseThrow( |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
573 |
() -> new RuntimeException(authenticateKey(authType) + ": not found")); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
574 |
assert authenticate.startsWith("Digest "); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
575 |
HeaderParser hp = new HeaderParser(authenticate.substring("Digest ".length())); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
576 |
String qop = hp.findValue("qop"); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
577 |
String nonce = hp.findValue("nonce"); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
578 |
if (qop == null && nonce == null) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
579 |
throw new RuntimeException("QOP and NONCE not found"); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
580 |
} |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
581 |
challenge = DigestEchoServer.DigestResponse |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
582 |
.create(authenticate.substring("Digest ".length())); |
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
583 |
String auth = digestResponse(uri, digestMethod, challenge, cnonceStr); |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
584 |
try { |
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
585 |
request = HttpRequest.newBuilder(uri).version(clientVersion) |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
586 |
.POST(reqBody).header(authorizationKey(authType), auth).build(); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
587 |
} catch (IllegalArgumentException x) { |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
588 |
throw x; |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
589 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
590 |
|
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
591 |
if (async) { |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
592 |
resp = client.sendAsync(request, asLines()).join(); |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
593 |
} else { |
56041
b4b5e09ef3cc
http-client-branch: make it possible to supply proxy-authorization headers
dfuchs
parents:
56033
diff
changeset
|
594 |
resp = client.send(request, asLines()); |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
595 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
596 |
System.out.println(resp); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
597 |
} |
56054
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
598 |
final List<String> respLines; |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
599 |
try { |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
600 |
if (isSchemeDisabled()) { |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
601 |
if (resp.statusCode() != 407) { |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
602 |
throw new RuntimeException("expected 407 not received"); |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
603 |
} |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
604 |
System.out.println("Scheme disabled for [" + authType |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
605 |
+ ", " + authScheme + |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
606 |
", " + (useSSL ? "HTTP" : "HTTPS") |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
607 |
+ "]: Received expected " + resp.statusCode()); |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
608 |
continue; |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
609 |
} else { |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
610 |
assert resp.statusCode() == 200; |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
611 |
respLines = resp.body().collect(Collectors.toList()); |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
612 |
} |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
613 |
} finally { |
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
614 |
long stop = System.nanoTime(); |
56070
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
615 |
synchronized (digestCount) { |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
616 |
long n = digestCount.getAndIncrement(); |
66a9c3185028
http-client-branch: add tests with an HTTP/2 server for custom basic and digest authentication
dfuchs
parents:
56054
diff
changeset
|
617 |
digests.set((digests.get() * n + (stop - start)) / (n + 1)); |
56054
352e845ae744
http-client-branch: honor legacy jdk.http.auth.* property when handling proxy-authorization
dfuchs
parents:
56041
diff
changeset
|
618 |
} |
56033
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
619 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
620 |
if (!lines.equals(respLines)) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
621 |
throw new RuntimeException("Unexpected response: " + respLines); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
622 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
623 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
624 |
} finally { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
625 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
626 |
System.out.println("OK"); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
627 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
628 |
|
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
629 |
// WARNING: This is not a full fledged implementation of DIGEST. |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
630 |
// It does contain bugs and inaccuracy. |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
631 |
static String digestResponse(URI uri, String method, DigestEchoServer.DigestResponse challenge, String cnonce) |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
632 |
throws NoSuchAlgorithmException { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
633 |
int nc = NC.incrementAndGet(); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
634 |
DigestEchoServer.DigestResponse response1 = new DigestEchoServer.DigestResponse("earth", |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
635 |
"arthur", challenge.nonce, cnonce, String.valueOf(nc), uri.toASCIIString(), |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
636 |
challenge.algorithm, challenge.qop, challenge.opaque, null); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
637 |
String response = DigestEchoServer.DigestResponse.computeDigest(true, method, |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
638 |
DigestEchoServer.AUTHENTICATOR.getPassword("arthur"), response1); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
639 |
String auth = "Digest username=\"arthur\", realm=\"earth\"" |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
640 |
+ ", response=\"" + response + "\", uri=\""+uri.toASCIIString()+"\"" |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
641 |
+ ", qop=\"" + response1.qop + "\", cnonce=\"" + response1.cnonce |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
642 |
+ "\", nc=\"" + nc + "\", nonce=\"" + response1.nonce + "\""; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
643 |
if (response1.opaque != null) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
644 |
auth = auth + ", opaque=\"" + response1.opaque + "\""; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
645 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
646 |
return auth; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
647 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
648 |
|
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
649 |
static String authenticateKey(DigestEchoServer.HttpAuthType authType) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
650 |
switch (authType) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
651 |
case SERVER: return "www-authenticate"; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
652 |
case SERVER307: return "www-authenticate"; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
653 |
case PROXY: return "proxy-authenticate"; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
654 |
case PROXY305: return "proxy-authenticate"; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
655 |
default: throw new InternalError("authType: " + authType); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
656 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
657 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
658 |
|
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
659 |
static String authorizationKey(DigestEchoServer.HttpAuthType authType) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
660 |
switch (authType) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
661 |
case SERVER: return "authorization"; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
662 |
case SERVER307: return "Authorization"; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
663 |
case PROXY: return "Proxy-Authorization"; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
664 |
case PROXY305: return "proxy-Authorization"; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
665 |
default: throw new InternalError("authType: " + authType); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
666 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
667 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
668 |
|
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
669 |
static boolean isProxy(DigestEchoServer.HttpAuthType authType) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
670 |
switch (authType) { |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
671 |
case SERVER: return false; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
672 |
case SERVER307: return false; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
673 |
case PROXY: return true; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
674 |
case PROXY305: return true; |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
675 |
default: throw new InternalError("authType: " + authType); |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
676 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
677 |
} |
db102c5ca88a
http-client-branch: 8194729: Java 9's HttpClient doesn't allow custom 'Authorization' headers
dfuchs
parents:
diff
changeset
|
678 |
} |