author | vtewari |
Tue, 21 Jun 2016 16:52:16 +0100 | |
changeset 39132 | e9499c06e138 |
parent 37590 | 8501202dc35b |
child 39137 | 6cf0e983a1e1 |
permissions | -rw-r--r-- |
17473 | 1 |
/* |
39132
e9499c06e138
8114860: Behavior of java.net.URLPermission.getActions() contradicts spec
vtewari
parents:
37590
diff
changeset
|
2 |
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. |
17473 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package java.net; |
|
27 |
||
28 |
import java.io.ObjectInputStream; |
|
29 |
import java.io.IOException; |
|
30 |
import java.util.List; |
|
31 |
import java.util.ArrayList; |
|
32 |
import java.util.Collections; |
|
33 |
import java.security.Permission; |
|
34 |
||
35 |
/** |
|
36 |
* Represents permission to access a resource or set of resources defined by a |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
37 |
* given url, and for a given set of user-settable request methods |
17473 | 38 |
* and request headers. The <i>name</i> of the permission is the url string. |
39 |
* The <i>actions</i> string is a concatenation of the request methods and headers. |
|
40 |
* The range of method and header names is not restricted by this class. |
|
41 |
* <p><b>The url</b><p> |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
42 |
* The url string has the following expected structure. |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
43 |
* <pre> |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
44 |
* scheme : // authority [ / path ] |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
45 |
* </pre> |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
46 |
* <i>scheme</i> will typically be http or https, but is not restricted by this |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
47 |
* class. |
21334 | 48 |
* <i>authority</i> is specified as: |
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
49 |
* <pre> |
22105
09df5383d1df
8029354: URLPermission.<init> throws llegalArgumentException: Invalid characters in hostname
michaelm
parents:
21608
diff
changeset
|
50 |
* authority = [ userinfo @ ] hostrange [ : portrange ] |
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
51 |
* portrange = portnumber | -portnumber | portnumber-[portnumber] | * |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
52 |
* hostrange = ([*.] dnsname) | IPv4address | IPv6address |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
53 |
* </pre> |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
54 |
* <i>dnsname</i> is a standard DNS host or domain name, ie. one or more labels |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
55 |
* separated by ".". <i>IPv4address</i> is a standard literal IPv4 address and |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
56 |
* <i>IPv6address</i> is as defined in <a href="http://www.ietf.org/rfc/rfc2732.txt"> |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
57 |
* RFC 2732</a>. Literal IPv6 addresses must however, be enclosed in '[]' characters. |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
58 |
* The <i>dnsname</i> specification can be preceded by "*." which means |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
59 |
* the name will match any hostname whose right-most domain labels are the same as |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
60 |
* this name. For example, "*.oracle.com" matches "foo.bar.oracle.com" |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
61 |
* <p> |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
62 |
* <i>portrange</i> is used to specify a port number, or a bounded or unbounded range of ports |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
63 |
* that this permission applies to. If portrange is absent or invalid, then a default |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
64 |
* port number is assumed if the scheme is {@code http} (default 80) or {@code https} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
65 |
* (default 443). No default is assumed for other schemes. A wildcard may be specified |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
66 |
* which means all ports. |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
67 |
* <p> |
22105
09df5383d1df
8029354: URLPermission.<init> throws llegalArgumentException: Invalid characters in hostname
michaelm
parents:
21608
diff
changeset
|
68 |
* <i>userinfo</i> is optional. A userinfo component if present, is ignored when |
09df5383d1df
8029354: URLPermission.<init> throws llegalArgumentException: Invalid characters in hostname
michaelm
parents:
21608
diff
changeset
|
69 |
* creating a URLPermission, and has no effect on any other methods defined by this class. |
09df5383d1df
8029354: URLPermission.<init> throws llegalArgumentException: Invalid characters in hostname
michaelm
parents:
21608
diff
changeset
|
70 |
* <p> |
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
71 |
* The <i>path</i> component comprises a sequence of path segments, |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
72 |
* separated by '/' characters. <i>path</i> may also be empty. The path is specified |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
73 |
* in a similar way to the path in {@link java.io.FilePermission}. There are |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
74 |
* three different ways as the following examples show: |
17473 | 75 |
* <table border> |
18800 | 76 |
* <caption>URL Examples</caption> |
17473 | 77 |
* <tr><th>Example url</th><th>Description</th></tr> |
78 |
* <tr><td style="white-space:nowrap;">http://www.oracle.com/a/b/c.html</td> |
|
79 |
* <td>A url which identifies a specific (single) resource</td> |
|
80 |
* </tr> |
|
81 |
* <tr><td>http://www.oracle.com/a/b/*</td> |
|
82 |
* <td>The '*' character refers to all resources in the same "directory" - in |
|
83 |
* other words all resources with the same number of path components, and |
|
84 |
* which only differ in the final path component, represented by the '*'. |
|
85 |
* </td> |
|
86 |
* </tr> |
|
18800 | 87 |
* <tr><td>http://www.oracle.com/a/b/-</td> |
17473 | 88 |
* <td>The '-' character refers to all resources recursively below the |
89 |
* preceding path (eg. http://www.oracle.com/a/b/c/d/e.html matches this |
|
90 |
* example). |
|
91 |
* </td> |
|
92 |
* </tr> |
|
93 |
* </table> |
|
94 |
* <p> |
|
95 |
* The '*' and '-' may only be specified in the final segment of a path and must be |
|
96 |
* the only character in that segment. Any query or fragment components of the |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
97 |
* url are ignored when constructing URLPermissions. |
17473 | 98 |
* <p> |
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
99 |
* As a special case, urls of the form, "scheme:*" are accepted to |
17473 | 100 |
* mean any url of the given scheme. |
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
101 |
* <p> |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
102 |
* The <i>scheme</i> and <i>authority</i> components of the url string are handled |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
103 |
* without regard to case. This means {@link #equals(Object)}, |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
104 |
* {@link #hashCode()} and {@link #implies(Permission)} are case insensitive with respect |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
105 |
* to these components. If the <i>authority</i> contains a literal IP address, |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
106 |
* then the address is normalized for comparison. The path component is case sensitive. |
17473 | 107 |
* <p><b>The actions string</b><p> |
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
108 |
* The actions string of a URLPermission is a concatenation of the <i>method list</i> |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
109 |
* and the <i>request headers list</i>. These are lists of the permitted request |
17473 | 110 |
* methods and permitted request headers of the permission (respectively). The two lists |
111 |
* are separated by a colon ':' character and elements of each list are comma separated. |
|
112 |
* Some examples are: |
|
113 |
* <pre> |
|
114 |
* "POST,GET,DELETE" |
|
115 |
* "GET:X-Foo-Request,X-Bar-Request" |
|
116 |
* "POST,GET:Header1,Header2" |
|
117 |
* </pre> |
|
118 |
* The first example specifies the methods: POST, GET and DELETE, but no request headers. |
|
119 |
* The second example specifies one request method and two headers. The third |
|
120 |
* example specifies two request methods, and two headers. |
|
121 |
* <p> |
|
122 |
* The colon separator need not be present if the request headers list is empty. |
|
123 |
* No white-space is permitted in the actions string. The action strings supplied to |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
124 |
* the URLPermission constructors are case-insensitive and are normalized by converting |
17473 | 125 |
* method names to upper-case and header names to the form defines in RFC2616 (lower case |
126 |
* with initial letter of each word capitalized). Either list can contain a wild-card '*' |
|
127 |
* character which signifies all request methods or headers respectively. |
|
128 |
* <p> |
|
129 |
* Note. Depending on the context of use, some request methods and headers may be permitted |
|
130 |
* at all times, and others may not be permitted at any time. For example, the |
|
131 |
* HTTP protocol handler might disallow certain headers such as Content-Length |
|
132 |
* from being set by application code, regardless of whether the security policy |
|
133 |
* in force, permits it. |
|
134 |
* |
|
135 |
* @since 1.8 |
|
136 |
*/ |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
137 |
public final class URLPermission extends Permission { |
17473 | 138 |
|
139 |
private static final long serialVersionUID = -2702463814894478682L; |
|
140 |
||
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
141 |
private transient String scheme; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
142 |
private transient String ssp; // scheme specific part |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
143 |
private transient String path; |
17473 | 144 |
private transient List<String> methods; |
145 |
private transient List<String> requestHeaders; |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
146 |
private transient Authority authority; |
17473 | 147 |
|
148 |
// serialized field |
|
149 |
private String actions; |
|
150 |
||
151 |
/** |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
152 |
* Creates a new URLPermission from a url string and which permits the given |
17473 | 153 |
* request methods and user-settable request headers. |
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
154 |
* The name of the permission is the url string it was created with. Only the scheme, |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
155 |
* authority and path components of the url are used internally. Any fragment or query |
17473 | 156 |
* components are ignored. The permissions action string is as specified above. |
157 |
* |
|
158 |
* @param url the url string |
|
159 |
* |
|
160 |
* @param actions the actions string |
|
161 |
* |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
162 |
* @exception IllegalArgumentException if url is invalid or if actions contains white-space. |
17473 | 163 |
*/ |
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
164 |
public URLPermission(String url, String actions) { |
17473 | 165 |
super(url); |
166 |
init(actions); |
|
167 |
} |
|
168 |
||
169 |
private void init(String actions) { |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
170 |
parseURI(getName()); |
17473 | 171 |
int colon = actions.indexOf(':'); |
172 |
if (actions.lastIndexOf(':') != colon) { |
|
37590
8501202dc35b
8071125: Improve exception messages in URLPermission
coffeys
parents:
25859
diff
changeset
|
173 |
throw new IllegalArgumentException( |
8501202dc35b
8071125: Improve exception messages in URLPermission
coffeys
parents:
25859
diff
changeset
|
174 |
"Invalid actions string: \"" + actions + "\""); |
17473 | 175 |
} |
176 |
||
177 |
String methods, headers; |
|
178 |
if (colon == -1) { |
|
179 |
methods = actions; |
|
180 |
headers = ""; |
|
181 |
} else { |
|
182 |
methods = actions.substring(0, colon); |
|
183 |
headers = actions.substring(colon+1); |
|
184 |
} |
|
185 |
||
186 |
List<String> l = normalizeMethods(methods); |
|
187 |
Collections.sort(l); |
|
188 |
this.methods = Collections.unmodifiableList(l); |
|
189 |
||
190 |
l = normalizeHeaders(headers); |
|
191 |
Collections.sort(l); |
|
192 |
this.requestHeaders = Collections.unmodifiableList(l); |
|
193 |
||
194 |
this.actions = actions(); |
|
195 |
} |
|
196 |
||
197 |
/** |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
198 |
* Creates a URLPermission with the given url string and unrestricted |
17473 | 199 |
* methods and request headers by invoking the two argument |
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
200 |
* constructor as follows: URLPermission(url, "*:*") |
17473 | 201 |
* |
18800 | 202 |
* @param url the url string |
203 |
* |
|
17473 | 204 |
* @throws IllegalArgumentException if url does not result in a valid {@link URI} |
205 |
*/ |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
206 |
public URLPermission(String url) { |
17473 | 207 |
this(url, "*:*"); |
208 |
} |
|
209 |
||
210 |
/** |
|
211 |
* Returns the normalized method list and request |
|
212 |
* header list, in the form: |
|
213 |
* <pre> |
|
214 |
* "method-names : header-names" |
|
215 |
* </pre> |
|
216 |
* <p> |
|
217 |
* where method-names is the list of methods separated by commas |
|
218 |
* and header-names is the list of permitted headers separated by commas. |
|
219 |
* There is no white space in the returned String. If header-names is empty |
|
220 |
* then the colon separator will not be present. |
|
221 |
*/ |
|
222 |
public String getActions() { |
|
223 |
return actions; |
|
224 |
} |
|
225 |
||
226 |
/** |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
227 |
* Checks if this URLPermission implies the given permission. |
17473 | 228 |
* Specifically, the following checks are done as if in the |
229 |
* following sequence: |
|
21334 | 230 |
* <ul> |
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
231 |
* <li>if 'p' is not an instance of URLPermission return false</li> |
17473 | 232 |
* <li>if any of p's methods are not in this's method list, and if |
233 |
* this's method list is not equal to "*", then return false.</li> |
|
234 |
* <li>if any of p's headers are not in this's request header list, and if |
|
235 |
* this's request header list is not equal to "*", then return false.</li> |
|
236 |
* <li>if this's url scheme is not equal to p's url scheme return false</li> |
|
237 |
* <li>if the scheme specific part of this's url is '*' return true</li> |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
238 |
* <li>if the set of hosts defined by p's url hostrange is not a subset of |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
239 |
* this's url hostrange then return false. For example, "*.foo.oracle.com" |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
240 |
* is a subset of "*.oracle.com". "foo.bar.oracle.com" is not |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
241 |
* a subset of "*.foo.oracle.com"</li> |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
242 |
* <li>if the portrange defined by p's url is not a subset of the |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
243 |
* portrange defined by this's url then return false. |
17473 | 244 |
* <li>if the path or paths specified by p's url are contained in the |
245 |
* set of paths specified by this's url, then return true |
|
246 |
* <li>otherwise, return false</li> |
|
18800 | 247 |
* </ul> |
248 |
* <p>Some examples of how paths are matched are shown below: |
|
21334 | 249 |
* <table border> |
18800 | 250 |
* <caption>Examples of Path Matching</caption> |
17473 | 251 |
* <tr><th>this's path</th><th>p's path</th><th>match</th></tr> |
252 |
* <tr><td>/a/b</td><td>/a/b</td><td>yes</td></tr> |
|
253 |
* <tr><td>/a/b/*</td><td>/a/b/c</td><td>yes</td></tr> |
|
254 |
* <tr><td>/a/b/*</td><td>/a/b/c/d</td><td>no</td></tr> |
|
255 |
* <tr><td>/a/b/-</td><td>/a/b/c/d</td><td>yes</td></tr> |
|
256 |
* <tr><td>/a/b/-</td><td>/a/b/c/d/e</td><td>yes</td></tr> |
|
257 |
* <tr><td>/a/b/-</td><td>/a/b/c/*</td><td>yes</td></tr> |
|
258 |
* <tr><td>/a/b/*</td><td>/a/b/c/-</td><td>no</td></tr> |
|
259 |
* </table> |
|
260 |
*/ |
|
261 |
public boolean implies(Permission p) { |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
262 |
if (! (p instanceof URLPermission)) { |
17473 | 263 |
return false; |
264 |
} |
|
265 |
||
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
266 |
URLPermission that = (URLPermission)p; |
17473 | 267 |
|
268 |
if (!this.methods.get(0).equals("*") && |
|
269 |
Collections.indexOfSubList(this.methods, that.methods) == -1) { |
|
270 |
return false; |
|
271 |
} |
|
272 |
||
273 |
if (this.requestHeaders.isEmpty() && !that.requestHeaders.isEmpty()) { |
|
274 |
return false; |
|
275 |
} |
|
276 |
||
277 |
if (!this.requestHeaders.isEmpty() && |
|
278 |
!this.requestHeaders.get(0).equals("*") && |
|
279 |
Collections.indexOfSubList(this.requestHeaders, |
|
280 |
that.requestHeaders) == -1) { |
|
281 |
return false; |
|
282 |
} |
|
283 |
||
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
284 |
if (!this.scheme.equals(that.scheme)) { |
17473 | 285 |
return false; |
286 |
} |
|
287 |
||
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
288 |
if (this.ssp.equals("*")) { |
17473 | 289 |
return true; |
290 |
} |
|
291 |
||
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
292 |
if (!this.authority.implies(that.authority)) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
293 |
return false; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
294 |
} |
17473 | 295 |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
296 |
if (this.path == null) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
297 |
return that.path == null; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
298 |
} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
299 |
if (that.path == null) { |
17473 | 300 |
return false; |
301 |
} |
|
302 |
||
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
303 |
if (this.path.endsWith("/-")) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
304 |
String thisprefix = this.path.substring(0, this.path.length() - 1); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
305 |
return that.path.startsWith(thisprefix); |
17473 | 306 |
} |
307 |
||
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
308 |
if (this.path.endsWith("/*")) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
309 |
String thisprefix = this.path.substring(0, this.path.length() - 1); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
310 |
if (!that.path.startsWith(thisprefix)) { |
17473 | 311 |
return false; |
312 |
} |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
313 |
String thatsuffix = that.path.substring(thisprefix.length()); |
17473 | 314 |
// suffix must not contain '/' chars |
315 |
if (thatsuffix.indexOf('/') != -1) { |
|
316 |
return false; |
|
317 |
} |
|
318 |
if (thatsuffix.equals("-")) { |
|
319 |
return false; |
|
320 |
} |
|
321 |
return true; |
|
322 |
} |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
323 |
return this.path.equals(that.path); |
17473 | 324 |
} |
325 |
||
326 |
||
327 |
/** |
|
328 |
* Returns true if, this.getActions().equals(p.getActions()) |
|
329 |
* and p's url equals this's url. Returns false otherwise. |
|
330 |
*/ |
|
331 |
public boolean equals(Object p) { |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
332 |
if (!(p instanceof URLPermission)) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
333 |
return false; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
334 |
} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
335 |
URLPermission that = (URLPermission)p; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
336 |
if (!this.scheme.equals(that.scheme)) { |
17473 | 337 |
return false; |
338 |
} |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
339 |
if (!this.getActions().equals(that.getActions())) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
340 |
return false; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
341 |
} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
342 |
if (!this.authority.equals(that.authority)) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
343 |
return false; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
344 |
} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
345 |
if (this.path != null) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
346 |
return this.path.equals(that.path); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
347 |
} else { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
348 |
return that.path == null; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
349 |
} |
17473 | 350 |
} |
351 |
||
352 |
/** |
|
353 |
* Returns a hashcode calculated from the hashcode of the |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
354 |
* actions String and the url string. |
17473 | 355 |
*/ |
356 |
public int hashCode() { |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
357 |
return getActions().hashCode() |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
358 |
+ scheme.hashCode() |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
359 |
+ authority.hashCode() |
21414
a3ddb94a50c8
8027570: NullPointerException in URLPermission.hashCode()
michaelm
parents:
20787
diff
changeset
|
360 |
+ (path == null ? 0 : path.hashCode()); |
17473 | 361 |
} |
362 |
||
363 |
||
364 |
private List<String> normalizeMethods(String methods) { |
|
365 |
List<String> l = new ArrayList<>(); |
|
366 |
StringBuilder b = new StringBuilder(); |
|
367 |
for (int i=0; i<methods.length(); i++) { |
|
368 |
char c = methods.charAt(i); |
|
369 |
if (c == ',') { |
|
370 |
String s = b.toString(); |
|
371 |
if (s.length() > 0) |
|
372 |
l.add(s); |
|
373 |
b = new StringBuilder(); |
|
374 |
} else if (c == ' ' || c == '\t') { |
|
37590
8501202dc35b
8071125: Improve exception messages in URLPermission
coffeys
parents:
25859
diff
changeset
|
375 |
throw new IllegalArgumentException( |
8501202dc35b
8071125: Improve exception messages in URLPermission
coffeys
parents:
25859
diff
changeset
|
376 |
"White space not allowed in methods: \"" + methods + "\""); |
17473 | 377 |
} else { |
378 |
if (c >= 'a' && c <= 'z') { |
|
379 |
c += 'A' - 'a'; |
|
380 |
} |
|
381 |
b.append(c); |
|
382 |
} |
|
383 |
} |
|
384 |
String s = b.toString(); |
|
385 |
if (s.length() > 0) |
|
386 |
l.add(s); |
|
387 |
return l; |
|
388 |
} |
|
389 |
||
390 |
private List<String> normalizeHeaders(String headers) { |
|
391 |
List<String> l = new ArrayList<>(); |
|
392 |
StringBuilder b = new StringBuilder(); |
|
393 |
boolean capitalizeNext = true; |
|
394 |
for (int i=0; i<headers.length(); i++) { |
|
395 |
char c = headers.charAt(i); |
|
396 |
if (c >= 'a' && c <= 'z') { |
|
397 |
if (capitalizeNext) { |
|
398 |
c += 'A' - 'a'; |
|
399 |
capitalizeNext = false; |
|
400 |
} |
|
401 |
b.append(c); |
|
402 |
} else if (c == ' ' || c == '\t') { |
|
37590
8501202dc35b
8071125: Improve exception messages in URLPermission
coffeys
parents:
25859
diff
changeset
|
403 |
throw new IllegalArgumentException( |
8501202dc35b
8071125: Improve exception messages in URLPermission
coffeys
parents:
25859
diff
changeset
|
404 |
"White space not allowed in headers: \"" + headers + "\""); |
17473 | 405 |
} else if (c == '-') { |
406 |
capitalizeNext = true; |
|
407 |
b.append(c); |
|
408 |
} else if (c == ',') { |
|
409 |
String s = b.toString(); |
|
410 |
if (s.length() > 0) |
|
411 |
l.add(s); |
|
412 |
b = new StringBuilder(); |
|
413 |
capitalizeNext = true; |
|
414 |
} else { |
|
415 |
capitalizeNext = false; |
|
416 |
b.append(c); |
|
417 |
} |
|
418 |
} |
|
419 |
String s = b.toString(); |
|
420 |
if (s.length() > 0) |
|
421 |
l.add(s); |
|
422 |
return l; |
|
423 |
} |
|
424 |
||
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
425 |
private void parseURI(String url) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
426 |
int len = url.length(); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
427 |
int delim = url.indexOf(':'); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
428 |
if (delim == -1 || delim + 1 == len) { |
37590
8501202dc35b
8071125: Improve exception messages in URLPermission
coffeys
parents:
25859
diff
changeset
|
429 |
throw new IllegalArgumentException( |
8501202dc35b
8071125: Improve exception messages in URLPermission
coffeys
parents:
25859
diff
changeset
|
430 |
"Invalid URL string: \"" + url + "\""); |
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
431 |
} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
432 |
scheme = url.substring(0, delim).toLowerCase(); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
433 |
this.ssp = url.substring(delim + 1); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
434 |
|
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
435 |
if (!ssp.startsWith("//")) { |
21608
73c4bf75786c
8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents:
21415
diff
changeset
|
436 |
if (!ssp.equals("*")) { |
37590
8501202dc35b
8071125: Improve exception messages in URLPermission
coffeys
parents:
25859
diff
changeset
|
437 |
throw new IllegalArgumentException( |
8501202dc35b
8071125: Improve exception messages in URLPermission
coffeys
parents:
25859
diff
changeset
|
438 |
"Invalid URL string: \"" + url + "\""); |
21608
73c4bf75786c
8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents:
21415
diff
changeset
|
439 |
} |
73c4bf75786c
8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents:
21415
diff
changeset
|
440 |
this.authority = new Authority(scheme, "*"); |
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
441 |
return; |
17473 | 442 |
} |
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
443 |
String authpath = ssp.substring(2); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
444 |
|
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
445 |
delim = authpath.indexOf('/'); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
446 |
String auth; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
447 |
if (delim == -1) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
448 |
this.path = ""; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
449 |
auth = authpath; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
450 |
} else { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
451 |
auth = authpath.substring(0, delim); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
452 |
this.path = authpath.substring(delim); |
17473 | 453 |
} |
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
454 |
this.authority = new Authority(scheme, auth.toLowerCase()); |
17473 | 455 |
} |
456 |
||
457 |
private String actions() { |
|
39132
e9499c06e138
8114860: Behavior of java.net.URLPermission.getActions() contradicts spec
vtewari
parents:
37590
diff
changeset
|
458 |
String b = String.join(",", methods); |
e9499c06e138
8114860: Behavior of java.net.URLPermission.getActions() contradicts spec
vtewari
parents:
37590
diff
changeset
|
459 |
if (!requestHeaders.isEmpty()) { |
e9499c06e138
8114860: Behavior of java.net.URLPermission.getActions() contradicts spec
vtewari
parents:
37590
diff
changeset
|
460 |
b += ":" + String.join(",", requestHeaders); |
17473 | 461 |
} |
39132
e9499c06e138
8114860: Behavior of java.net.URLPermission.getActions() contradicts spec
vtewari
parents:
37590
diff
changeset
|
462 |
return b; |
17473 | 463 |
} |
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
464 |
|
17473 | 465 |
/** |
466 |
* restore the state of this object from stream |
|
467 |
*/ |
|
468 |
private void readObject(ObjectInputStream s) |
|
469 |
throws IOException, ClassNotFoundException { |
|
470 |
ObjectInputStream.GetField fields = s.readFields(); |
|
471 |
String actions = (String)fields.get("actions", null); |
|
472 |
||
473 |
init(actions); |
|
474 |
} |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
475 |
|
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
476 |
static class Authority { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
477 |
HostPortrange p; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
478 |
|
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
479 |
Authority(String scheme, String authority) { |
22105
09df5383d1df
8029354: URLPermission.<init> throws llegalArgumentException: Invalid characters in hostname
michaelm
parents:
21608
diff
changeset
|
480 |
int at = authority.indexOf('@'); |
09df5383d1df
8029354: URLPermission.<init> throws llegalArgumentException: Invalid characters in hostname
michaelm
parents:
21608
diff
changeset
|
481 |
if (at == -1) { |
09df5383d1df
8029354: URLPermission.<init> throws llegalArgumentException: Invalid characters in hostname
michaelm
parents:
21608
diff
changeset
|
482 |
p = new HostPortrange(scheme, authority); |
09df5383d1df
8029354: URLPermission.<init> throws llegalArgumentException: Invalid characters in hostname
michaelm
parents:
21608
diff
changeset
|
483 |
} else { |
09df5383d1df
8029354: URLPermission.<init> throws llegalArgumentException: Invalid characters in hostname
michaelm
parents:
21608
diff
changeset
|
484 |
p = new HostPortrange(scheme, authority.substring(at+1)); |
09df5383d1df
8029354: URLPermission.<init> throws llegalArgumentException: Invalid characters in hostname
michaelm
parents:
21608
diff
changeset
|
485 |
} |
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
486 |
} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
487 |
|
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
488 |
boolean implies(Authority other) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
489 |
return impliesHostrange(other) && impliesPortrange(other); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
490 |
} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
491 |
|
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
492 |
private boolean impliesHostrange(Authority that) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
493 |
String thishost = this.p.hostname(); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
494 |
String thathost = that.p.hostname(); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
495 |
|
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
496 |
if (p.wildcard() && thishost.equals("")) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
497 |
// this "*" implies all others |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
498 |
return true; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
499 |
} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
500 |
if (that.p.wildcard() && thathost.equals("")) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
501 |
// that "*" can only be implied by this "*" |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
502 |
return false; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
503 |
} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
504 |
if (thishost.equals(thathost)) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
505 |
// covers all cases of literal IP addresses and fixed |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
506 |
// domain names. |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
507 |
return true; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
508 |
} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
509 |
if (this.p.wildcard()) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
510 |
// this "*.foo.com" implies "bub.bar.foo.com" |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
511 |
return thathost.endsWith(thishost); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
512 |
} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
513 |
return false; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
514 |
} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
515 |
|
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
516 |
private boolean impliesPortrange(Authority that) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
517 |
int[] thisrange = this.p.portrange(); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
518 |
int[] thatrange = that.p.portrange(); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
519 |
if (thisrange[0] == -1) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
520 |
/* port not specified non http/s URL */ |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
521 |
return true; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
522 |
} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
523 |
return thisrange[0] <= thatrange[0] && |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
524 |
thisrange[1] >= thatrange[1]; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
525 |
} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
526 |
|
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
527 |
boolean equals(Authority that) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
528 |
return this.p.equals(that.p); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
529 |
} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
530 |
|
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
531 |
public int hashCode() { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
532 |
return p.hashCode(); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
533 |
} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
534 |
} |
17473 | 535 |
} |