author | michaelm |
Thu, 11 Sep 2014 15:51:46 +0100 | |
changeset 26487 | 605e2ffaec14 |
parent 25859 | 3317bb8137f4 |
child 37590 | 8501202dc35b |
permissions | -rw-r--r-- |
17473 | 1 |
/* |
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
|
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) { |
|
173 |
throw new IllegalArgumentException("invalid actions string"); |
|
174 |
} |
|
175 |
||
176 |
String methods, headers; |
|
177 |
if (colon == -1) { |
|
178 |
methods = actions; |
|
179 |
headers = ""; |
|
180 |
} else { |
|
181 |
methods = actions.substring(0, colon); |
|
182 |
headers = actions.substring(colon+1); |
|
183 |
} |
|
184 |
||
185 |
List<String> l = normalizeMethods(methods); |
|
186 |
Collections.sort(l); |
|
187 |
this.methods = Collections.unmodifiableList(l); |
|
188 |
||
189 |
l = normalizeHeaders(headers); |
|
190 |
Collections.sort(l); |
|
191 |
this.requestHeaders = Collections.unmodifiableList(l); |
|
192 |
||
193 |
this.actions = actions(); |
|
194 |
} |
|
195 |
||
196 |
/** |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
197 |
* Creates a URLPermission with the given url string and unrestricted |
17473 | 198 |
* 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
|
199 |
* constructor as follows: URLPermission(url, "*:*") |
17473 | 200 |
* |
18800 | 201 |
* @param url the url string |
202 |
* |
|
17473 | 203 |
* @throws IllegalArgumentException if url does not result in a valid {@link URI} |
204 |
*/ |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
205 |
public URLPermission(String url) { |
17473 | 206 |
this(url, "*:*"); |
207 |
} |
|
208 |
||
209 |
/** |
|
210 |
* Returns the normalized method list and request |
|
211 |
* header list, in the form: |
|
212 |
* <pre> |
|
213 |
* "method-names : header-names" |
|
214 |
* </pre> |
|
215 |
* <p> |
|
216 |
* where method-names is the list of methods separated by commas |
|
217 |
* and header-names is the list of permitted headers separated by commas. |
|
218 |
* There is no white space in the returned String. If header-names is empty |
|
219 |
* then the colon separator will not be present. |
|
220 |
*/ |
|
221 |
public String getActions() { |
|
222 |
return actions; |
|
223 |
} |
|
224 |
||
225 |
/** |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
226 |
* Checks if this URLPermission implies the given permission. |
17473 | 227 |
* Specifically, the following checks are done as if in the |
228 |
* following sequence: |
|
21334 | 229 |
* <ul> |
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
230 |
* <li>if 'p' is not an instance of URLPermission return false</li> |
17473 | 231 |
* <li>if any of p's methods are not in this's method list, and if |
232 |
* this's method list is not equal to "*", then return false.</li> |
|
233 |
* <li>if any of p's headers are not in this's request header list, and if |
|
234 |
* this's request header list is not equal to "*", then return false.</li> |
|
235 |
* <li>if this's url scheme is not equal to p's url scheme return false</li> |
|
236 |
* <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
|
237 |
* <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
|
238 |
* 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
|
239 |
* 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
|
240 |
* a subset of "*.foo.oracle.com"</li> |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
241 |
* <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
|
242 |
* portrange defined by this's url then return false. |
17473 | 243 |
* <li>if the path or paths specified by p's url are contained in the |
244 |
* set of paths specified by this's url, then return true |
|
245 |
* <li>otherwise, return false</li> |
|
18800 | 246 |
* </ul> |
247 |
* <p>Some examples of how paths are matched are shown below: |
|
21334 | 248 |
* <table border> |
18800 | 249 |
* <caption>Examples of Path Matching</caption> |
17473 | 250 |
* <tr><th>this's path</th><th>p's path</th><th>match</th></tr> |
251 |
* <tr><td>/a/b</td><td>/a/b</td><td>yes</td></tr> |
|
252 |
* <tr><td>/a/b/*</td><td>/a/b/c</td><td>yes</td></tr> |
|
253 |
* <tr><td>/a/b/*</td><td>/a/b/c/d</td><td>no</td></tr> |
|
254 |
* <tr><td>/a/b/-</td><td>/a/b/c/d</td><td>yes</td></tr> |
|
255 |
* <tr><td>/a/b/-</td><td>/a/b/c/d/e</td><td>yes</td></tr> |
|
256 |
* <tr><td>/a/b/-</td><td>/a/b/c/*</td><td>yes</td></tr> |
|
257 |
* <tr><td>/a/b/*</td><td>/a/b/c/-</td><td>no</td></tr> |
|
258 |
* </table> |
|
259 |
*/ |
|
260 |
public boolean implies(Permission p) { |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
261 |
if (! (p instanceof URLPermission)) { |
17473 | 262 |
return false; |
263 |
} |
|
264 |
||
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
265 |
URLPermission that = (URLPermission)p; |
17473 | 266 |
|
267 |
if (!this.methods.get(0).equals("*") && |
|
268 |
Collections.indexOfSubList(this.methods, that.methods) == -1) { |
|
269 |
return false; |
|
270 |
} |
|
271 |
||
272 |
if (this.requestHeaders.isEmpty() && !that.requestHeaders.isEmpty()) { |
|
273 |
return false; |
|
274 |
} |
|
275 |
||
276 |
if (!this.requestHeaders.isEmpty() && |
|
277 |
!this.requestHeaders.get(0).equals("*") && |
|
278 |
Collections.indexOfSubList(this.requestHeaders, |
|
279 |
that.requestHeaders) == -1) { |
|
280 |
return false; |
|
281 |
} |
|
282 |
||
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
283 |
if (!this.scheme.equals(that.scheme)) { |
17473 | 284 |
return false; |
285 |
} |
|
286 |
||
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
287 |
if (this.ssp.equals("*")) { |
17473 | 288 |
return true; |
289 |
} |
|
290 |
||
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
291 |
if (!this.authority.implies(that.authority)) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
292 |
return false; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
293 |
} |
17473 | 294 |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
295 |
if (this.path == null) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
296 |
return that.path == null; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
297 |
} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
298 |
if (that.path == null) { |
17473 | 299 |
return false; |
300 |
} |
|
301 |
||
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
302 |
if (this.path.endsWith("/-")) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
303 |
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
|
304 |
return that.path.startsWith(thisprefix); |
17473 | 305 |
} |
306 |
||
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
307 |
if (this.path.endsWith("/*")) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
308 |
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
|
309 |
if (!that.path.startsWith(thisprefix)) { |
17473 | 310 |
return false; |
311 |
} |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
312 |
String thatsuffix = that.path.substring(thisprefix.length()); |
17473 | 313 |
// suffix must not contain '/' chars |
314 |
if (thatsuffix.indexOf('/') != -1) { |
|
315 |
return false; |
|
316 |
} |
|
317 |
if (thatsuffix.equals("-")) { |
|
318 |
return false; |
|
319 |
} |
|
320 |
return true; |
|
321 |
} |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
322 |
return this.path.equals(that.path); |
17473 | 323 |
} |
324 |
||
325 |
||
326 |
/** |
|
327 |
* Returns true if, this.getActions().equals(p.getActions()) |
|
328 |
* and p's url equals this's url. Returns false otherwise. |
|
329 |
*/ |
|
330 |
public boolean equals(Object p) { |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
331 |
if (!(p instanceof URLPermission)) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
332 |
return false; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
333 |
} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
334 |
URLPermission that = (URLPermission)p; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
335 |
if (!this.scheme.equals(that.scheme)) { |
17473 | 336 |
return false; |
337 |
} |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
338 |
if (!this.getActions().equals(that.getActions())) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
339 |
return false; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
340 |
} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
341 |
if (!this.authority.equals(that.authority)) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
342 |
return false; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
343 |
} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
344 |
if (this.path != null) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
345 |
return this.path.equals(that.path); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
346 |
} else { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
347 |
return that.path == null; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
348 |
} |
17473 | 349 |
} |
350 |
||
351 |
/** |
|
352 |
* 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
|
353 |
* actions String and the url string. |
17473 | 354 |
*/ |
355 |
public int hashCode() { |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
356 |
return getActions().hashCode() |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
357 |
+ scheme.hashCode() |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
358 |
+ authority.hashCode() |
21414
a3ddb94a50c8
8027570: NullPointerException in URLPermission.hashCode()
michaelm
parents:
20787
diff
changeset
|
359 |
+ (path == null ? 0 : path.hashCode()); |
17473 | 360 |
} |
361 |
||
362 |
||
363 |
private List<String> normalizeMethods(String methods) { |
|
364 |
List<String> l = new ArrayList<>(); |
|
365 |
StringBuilder b = new StringBuilder(); |
|
366 |
for (int i=0; i<methods.length(); i++) { |
|
367 |
char c = methods.charAt(i); |
|
368 |
if (c == ',') { |
|
369 |
String s = b.toString(); |
|
370 |
if (s.length() > 0) |
|
371 |
l.add(s); |
|
372 |
b = new StringBuilder(); |
|
373 |
} else if (c == ' ' || c == '\t') { |
|
374 |
throw new IllegalArgumentException("white space not allowed"); |
|
375 |
} else { |
|
376 |
if (c >= 'a' && c <= 'z') { |
|
377 |
c += 'A' - 'a'; |
|
378 |
} |
|
379 |
b.append(c); |
|
380 |
} |
|
381 |
} |
|
382 |
String s = b.toString(); |
|
383 |
if (s.length() > 0) |
|
384 |
l.add(s); |
|
385 |
return l; |
|
386 |
} |
|
387 |
||
388 |
private List<String> normalizeHeaders(String headers) { |
|
389 |
List<String> l = new ArrayList<>(); |
|
390 |
StringBuilder b = new StringBuilder(); |
|
391 |
boolean capitalizeNext = true; |
|
392 |
for (int i=0; i<headers.length(); i++) { |
|
393 |
char c = headers.charAt(i); |
|
394 |
if (c >= 'a' && c <= 'z') { |
|
395 |
if (capitalizeNext) { |
|
396 |
c += 'A' - 'a'; |
|
397 |
capitalizeNext = false; |
|
398 |
} |
|
399 |
b.append(c); |
|
400 |
} else if (c == ' ' || c == '\t') { |
|
401 |
throw new IllegalArgumentException("white space not allowed"); |
|
402 |
} else if (c == '-') { |
|
403 |
capitalizeNext = true; |
|
404 |
b.append(c); |
|
405 |
} else if (c == ',') { |
|
406 |
String s = b.toString(); |
|
407 |
if (s.length() > 0) |
|
408 |
l.add(s); |
|
409 |
b = new StringBuilder(); |
|
410 |
capitalizeNext = true; |
|
411 |
} else { |
|
412 |
capitalizeNext = false; |
|
413 |
b.append(c); |
|
414 |
} |
|
415 |
} |
|
416 |
String s = b.toString(); |
|
417 |
if (s.length() > 0) |
|
418 |
l.add(s); |
|
419 |
return l; |
|
420 |
} |
|
421 |
||
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
422 |
private void parseURI(String url) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
423 |
int len = url.length(); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
424 |
int delim = url.indexOf(':'); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
425 |
if (delim == -1 || delim + 1 == len) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
426 |
throw new IllegalArgumentException("invalid URL string"); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
427 |
} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
428 |
scheme = url.substring(0, delim).toLowerCase(); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
429 |
this.ssp = url.substring(delim + 1); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
430 |
|
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
431 |
if (!ssp.startsWith("//")) { |
21608
73c4bf75786c
8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents:
21415
diff
changeset
|
432 |
if (!ssp.equals("*")) { |
73c4bf75786c
8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents:
21415
diff
changeset
|
433 |
throw new IllegalArgumentException("invalid URL string"); |
73c4bf75786c
8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents:
21415
diff
changeset
|
434 |
} |
73c4bf75786c
8027687: The constructors of URLPermission class do not behave as described in javad
michaelm
parents:
21415
diff
changeset
|
435 |
this.authority = new Authority(scheme, "*"); |
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
436 |
return; |
17473 | 437 |
} |
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
438 |
String authpath = ssp.substring(2); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
439 |
|
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
440 |
delim = authpath.indexOf('/'); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
441 |
String auth; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
442 |
if (delim == -1) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
443 |
this.path = ""; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
444 |
auth = authpath; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
445 |
} else { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
446 |
auth = authpath.substring(0, delim); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
447 |
this.path = authpath.substring(delim); |
17473 | 448 |
} |
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
449 |
this.authority = new Authority(scheme, auth.toLowerCase()); |
17473 | 450 |
} |
451 |
||
452 |
private String actions() { |
|
453 |
StringBuilder b = new StringBuilder(); |
|
454 |
for (String s : methods) { |
|
455 |
b.append(s); |
|
456 |
} |
|
457 |
b.append(":"); |
|
458 |
for (String s : requestHeaders) { |
|
459 |
b.append(s); |
|
460 |
} |
|
461 |
return b.toString(); |
|
462 |
} |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
463 |
|
17473 | 464 |
/** |
465 |
* restore the state of this object from stream |
|
466 |
*/ |
|
467 |
private void readObject(ObjectInputStream s) |
|
468 |
throws IOException, ClassNotFoundException { |
|
469 |
ObjectInputStream.GetField fields = s.readFields(); |
|
470 |
String actions = (String)fields.get("actions", null); |
|
471 |
||
472 |
init(actions); |
|
473 |
} |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
474 |
|
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
475 |
static class Authority { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
476 |
HostPortrange p; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
477 |
|
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
478 |
Authority(String scheme, String authority) { |
22105
09df5383d1df
8029354: URLPermission.<init> throws llegalArgumentException: Invalid characters in hostname
michaelm
parents:
21608
diff
changeset
|
479 |
int at = authority.indexOf('@'); |
09df5383d1df
8029354: URLPermission.<init> throws llegalArgumentException: Invalid characters in hostname
michaelm
parents:
21608
diff
changeset
|
480 |
if (at == -1) { |
09df5383d1df
8029354: URLPermission.<init> throws llegalArgumentException: Invalid characters in hostname
michaelm
parents:
21608
diff
changeset
|
481 |
p = new HostPortrange(scheme, authority); |
09df5383d1df
8029354: URLPermission.<init> throws llegalArgumentException: Invalid characters in hostname
michaelm
parents:
21608
diff
changeset
|
482 |
} else { |
09df5383d1df
8029354: URLPermission.<init> throws llegalArgumentException: Invalid characters in hostname
michaelm
parents:
21608
diff
changeset
|
483 |
p = new HostPortrange(scheme, authority.substring(at+1)); |
09df5383d1df
8029354: URLPermission.<init> throws llegalArgumentException: Invalid characters in hostname
michaelm
parents:
21608
diff
changeset
|
484 |
} |
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
485 |
} |
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 |
boolean implies(Authority other) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
488 |
return impliesHostrange(other) && impliesPortrange(other); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
489 |
} |
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 |
private boolean impliesHostrange(Authority that) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
492 |
String thishost = this.p.hostname(); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
493 |
String thathost = that.p.hostname(); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
494 |
|
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
495 |
if (p.wildcard() && thishost.equals("")) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
496 |
// this "*" implies all others |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
497 |
return true; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
498 |
} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
499 |
if (that.p.wildcard() && thathost.equals("")) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
500 |
// that "*" can only be implied by this "*" |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
501 |
return false; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
502 |
} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
503 |
if (thishost.equals(thathost)) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
504 |
// covers all cases of literal IP addresses and fixed |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
505 |
// domain names. |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
506 |
return true; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
507 |
} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
508 |
if (this.p.wildcard()) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
509 |
// this "*.foo.com" implies "bub.bar.foo.com" |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
510 |
return thathost.endsWith(thishost); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
511 |
} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
512 |
return false; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
513 |
} |
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 |
private boolean impliesPortrange(Authority that) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
516 |
int[] thisrange = this.p.portrange(); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
517 |
int[] thatrange = that.p.portrange(); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
518 |
if (thisrange[0] == -1) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
519 |
/* port not specified non http/s URL */ |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
520 |
return true; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
521 |
} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
522 |
return thisrange[0] <= thatrange[0] && |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
523 |
thisrange[1] >= thatrange[1]; |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
524 |
} |
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 |
boolean equals(Authority that) { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
527 |
return this.p.equals(that.p); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
528 |
} |
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 |
public int hashCode() { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
531 |
return p.hashCode(); |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
532 |
} |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
18800
diff
changeset
|
533 |
} |
17473 | 534 |
} |