jdk/src/java.base/share/classes/java/net/URLPermission.java
author vtewari
Tue, 21 Jun 2016 16:52:16 +0100
changeset 39132 e9499c06e138
parent 37590 8501202dc35b
child 39137 6cf0e983a1e1
permissions -rw-r--r--
8114860: Behavior of java.net.URLPermission.getActions() contradicts spec Reviewed-by: chegar, prappo
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17473
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
     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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
     4
 *
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    10
 *
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    15
 * accompanied this code).
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    16
 *
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    20
 *
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    23
 * questions.
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    24
 */
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    25
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    26
package java.net;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    27
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    28
import java.io.ObjectInputStream;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    29
import java.io.IOException;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    30
import java.util.List;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    31
import java.util.ArrayList;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    32
import java.util.Collections;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    33
import java.security.Permission;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    34
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    35
/**
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    38
 * and request headers. The <i>name</i> of the permission is the url string.
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    39
 * The <i>actions</i> string is a concatenation of the request methods and headers.
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    40
 * The range of method and header names is not restricted by this class.
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    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
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 20787
diff changeset
    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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    75
 * <table border>
18800
e7fa560afcfb 8020318: Fix doclint issues in java.net
juh
parents: 17941
diff changeset
    76
 * <caption>URL Examples</caption>
17473
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    77
 * <tr><th>Example url</th><th>Description</th></tr>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    78
 * <tr><td style="white-space:nowrap;">http://www.oracle.com/a/b/c.html</td>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    79
 *   <td>A url which identifies a specific (single) resource</td>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    80
 * </tr>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    81
 * <tr><td>http://www.oracle.com/a/b/*</td>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    82
 *   <td>The '*' character refers to all resources in the same "directory" - in
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    83
 *       other words all resources with the same number of path components, and
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    84
 *       which only differ in the final path component, represented by the '*'.
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    85
 *   </td>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    86
 * </tr>
18800
e7fa560afcfb 8020318: Fix doclint issues in java.net
juh
parents: 17941
diff changeset
    87
 * <tr><td>http://www.oracle.com/a/b/-</td>
17473
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    88
 *   <td>The '-' character refers to all resources recursively below the
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    89
 *       preceding path (eg. http://www.oracle.com/a/b/c/d/e.html matches this
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    90
 *       example).
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    91
 *   </td>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    92
 * </tr>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    93
 * </table>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    94
 * <p>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    95
 * The '*' and '-' may only be specified in the final segment of a path and must be
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
    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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   110
 * methods and permitted request headers of the permission (respectively). The two lists
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   111
 * are separated by a colon ':' character and elements of each list are comma separated.
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   112
 * Some examples are:
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   113
 * <pre>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   114
 *         "POST,GET,DELETE"
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   115
 *         "GET:X-Foo-Request,X-Bar-Request"
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   116
 *         "POST,GET:Header1,Header2"
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   117
 * </pre>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   118
 * The first example specifies the methods: POST, GET and DELETE, but no request headers.
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   119
 * The second example specifies one request method and two headers. The third
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   120
 * example specifies two request methods, and two headers.
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   121
 * <p>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   122
 * The colon separator need not be present if the request headers list is empty.
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   125
 * method names to upper-case and header names to the form defines in RFC2616 (lower case
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   126
 * with initial letter of each word capitalized). Either list can contain a wild-card '*'
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   127
 * character which signifies all request methods or headers respectively.
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   128
 * <p>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   129
 * Note. Depending on the context of use, some request methods and headers may be permitted
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   130
 * at all times, and others may not be permitted at any time. For example, the
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   131
 * HTTP protocol handler might disallow certain headers such as Content-Length
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   132
 * from being set by application code, regardless of whether the security policy
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   133
 * in force, permits it.
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   134
 *
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   135
 * @since 1.8
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   138
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   139
    private static final long serialVersionUID = -2702463814894478682L;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   144
    private transient List<String> methods;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   147
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   148
    // serialized field
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   149
    private String actions;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   150
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   156
     * components are ignored. The permissions action string is as specified above.
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   157
     *
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   158
     * @param url the url string
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   159
     *
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   160
     * @param actions the actions string
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   165
        super(url);
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   166
        init(actions);
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   167
    }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   168
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   171
        int colon = actions.indexOf(':');
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   175
        }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   176
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   177
        String methods, headers;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   178
        if (colon == -1) {
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   179
            methods = actions;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   180
            headers = "";
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   181
        } else {
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   182
            methods = actions.substring(0, colon);
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   183
            headers = actions.substring(colon+1);
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   184
        }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   185
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   186
        List<String> l = normalizeMethods(methods);
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   187
        Collections.sort(l);
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   188
        this.methods = Collections.unmodifiableList(l);
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   189
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   190
        l = normalizeHeaders(headers);
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   191
        Collections.sort(l);
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   192
        this.requestHeaders = Collections.unmodifiableList(l);
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   193
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   194
        this.actions = actions();
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   195
    }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   196
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   201
     *
18800
e7fa560afcfb 8020318: Fix doclint issues in java.net
juh
parents: 17941
diff changeset
   202
     * @param url the url string
e7fa560afcfb 8020318: Fix doclint issues in java.net
juh
parents: 17941
diff changeset
   203
     *
17473
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   204
     * @throws    IllegalArgumentException if url does not result in a valid {@link URI}
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   205
     */
20787
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents: 18800
diff changeset
   206
    public URLPermission(String url) {
17473
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   207
        this(url, "*:*");
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   208
    }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   209
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   210
    /**
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   211
     * Returns the normalized method list and request
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   212
     * header list, in the form:
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   213
     * <pre>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   214
     *      "method-names : header-names"
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   215
     * </pre>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   216
     * <p>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   217
     * where method-names is the list of methods separated by commas
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   218
     * and header-names is the list of permitted headers separated by commas.
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   219
     * There is no white space in the returned String. If header-names is empty
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   220
     * then the colon separator will not be present.
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   221
     */
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   222
    public String getActions() {
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   223
        return actions;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   224
    }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   225
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   228
     * Specifically, the following checks are done as if in the
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   229
     * following sequence:
21334
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 20787
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   232
     * <li>if any of p's methods are not in this's method list, and if
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   233
     *     this's method list is not equal to "*", then return false.</li>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   234
     * <li>if any of p's headers are not in this's request header list, and if
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   235
     *     this's request header list is not equal to "*", then return false.</li>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   236
     * <li>if this's url scheme is not equal to p's url scheme return false</li>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   244
     * <li>if the path or paths specified by p's url are contained in the
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   245
     *     set of paths specified by this's url, then return true
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   246
     * <li>otherwise, return false</li>
18800
e7fa560afcfb 8020318: Fix doclint issues in java.net
juh
parents: 17941
diff changeset
   247
     * </ul>
e7fa560afcfb 8020318: Fix doclint issues in java.net
juh
parents: 17941
diff changeset
   248
     * <p>Some examples of how paths are matched are shown below:
21334
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 20787
diff changeset
   249
     * <table border>
18800
e7fa560afcfb 8020318: Fix doclint issues in java.net
juh
parents: 17941
diff changeset
   250
     * <caption>Examples of Path Matching</caption>
17473
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   251
     * <tr><th>this's path</th><th>p's path</th><th>match</th></tr>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   252
     * <tr><td>/a/b</td><td>/a/b</td><td>yes</td></tr>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   253
     * <tr><td>/a/b/*</td><td>/a/b/c</td><td>yes</td></tr>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   254
     * <tr><td>/a/b/*</td><td>/a/b/c/d</td><td>no</td></tr>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   255
     * <tr><td>/a/b/-</td><td>/a/b/c/d</td><td>yes</td></tr>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   256
     * <tr><td>/a/b/-</td><td>/a/b/c/d/e</td><td>yes</td></tr>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   257
     * <tr><td>/a/b/-</td><td>/a/b/c/*</td><td>yes</td></tr>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   258
     * <tr><td>/a/b/*</td><td>/a/b/c/-</td><td>no</td></tr>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   259
     * </table>
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   260
     */
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   263
            return false;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   264
        }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   265
20787
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents: 18800
diff changeset
   266
        URLPermission that = (URLPermission)p;
17473
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   267
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   268
        if (!this.methods.get(0).equals("*") &&
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   269
                Collections.indexOfSubList(this.methods, that.methods) == -1) {
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   270
            return false;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   271
        }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   272
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   273
        if (this.requestHeaders.isEmpty() && !that.requestHeaders.isEmpty()) {
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   274
            return false;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   275
        }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   276
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   277
        if (!this.requestHeaders.isEmpty() &&
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   278
            !this.requestHeaders.get(0).equals("*") &&
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   279
             Collections.indexOfSubList(this.requestHeaders,
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   280
                                        that.requestHeaders) == -1) {
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   281
            return false;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   282
        }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   285
            return false;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   286
        }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   287
20787
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents: 18800
diff changeset
   288
        if (this.ssp.equals("*")) {
17473
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   289
            return true;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   290
        }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   300
            return false;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   301
        }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   306
            }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   311
                return false;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   314
            // suffix must not contain '/' chars
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   315
            if (thatsuffix.indexOf('/') != -1) {
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   316
                return false;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   317
            }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   318
            if (thatsuffix.equals("-")) {
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   319
                return false;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   320
            }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   321
            return true;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   324
    }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   325
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   326
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   327
    /**
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   328
     * Returns true if, this.getActions().equals(p.getActions())
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   329
     * and p's url equals this's url.  Returns false otherwise.
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   330
     */
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   337
            return false;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   350
    }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   351
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   352
    /**
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   355
     */
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   361
    }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   362
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   363
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   364
    private List<String> normalizeMethods(String methods) {
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   365
        List<String> l = new ArrayList<>();
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   366
        StringBuilder b = new StringBuilder();
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   367
        for (int i=0; i<methods.length(); i++) {
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   368
            char c = methods.charAt(i);
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   369
            if (c == ',') {
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   370
                String s = b.toString();
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   371
                if (s.length() > 0)
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   372
                    l.add(s);
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   373
                b = new StringBuilder();
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   377
            } else {
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   378
                if (c >= 'a' && c <= 'z') {
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   379
                    c += 'A' - 'a';
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   380
                }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   381
                b.append(c);
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   382
            }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   383
        }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   384
        String s = b.toString();
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   385
        if (s.length() > 0)
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   386
            l.add(s);
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   387
        return l;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   388
    }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   389
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   390
    private List<String> normalizeHeaders(String headers) {
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   391
        List<String> l = new ArrayList<>();
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   392
        StringBuilder b = new StringBuilder();
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   393
        boolean capitalizeNext = true;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   394
        for (int i=0; i<headers.length(); i++) {
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   395
            char c = headers.charAt(i);
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   396
            if (c >= 'a' && c <= 'z') {
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   397
                if (capitalizeNext) {
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   398
                    c += 'A' - 'a';
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   399
                    capitalizeNext = false;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   400
                }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   401
                b.append(c);
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   405
            } else if (c == '-') {
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   406
                    capitalizeNext = true;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   407
                b.append(c);
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   408
            } else if (c == ',') {
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   409
                String s = b.toString();
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   410
                if (s.length() > 0)
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   411
                    l.add(s);
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   412
                b = new StringBuilder();
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   413
                capitalizeNext = true;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   414
            } else {
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   415
                capitalizeNext = false;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   416
                b.append(c);
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   417
            }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   418
        }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   419
        String s = b.toString();
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   420
        if (s.length() > 0)
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   421
            l.add(s);
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   422
        return l;
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   423
    }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   455
    }
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   456
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   461
        }
39132
e9499c06e138 8114860: Behavior of java.net.URLPermission.getActions() contradicts spec
vtewari
parents: 37590
diff changeset
   462
        return b;
17473
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   463
    }
20787
ab071ce90368 8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents: 18800
diff changeset
   464
17473
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   465
    /**
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   466
     * restore the state of this object from stream
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   467
     */
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   468
    private void readObject(ObjectInputStream s)
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   469
        throws IOException, ClassNotFoundException {
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   470
        ObjectInputStream.GetField fields = s.readFields();
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   471
        String actions = (String)fields.get("actions", null);
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   472
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   473
        init(actions);
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   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
35cd9b3a98ff 8010464: Evolve java networking same origin policy
michaelm
parents:
diff changeset
   535
}