Serializable
, Guard
public final class URLPermission extends Permission
The url
The url string has the following expected structure.
scheme : // authority [ / path ] [ ignored-query-or-fragment ]scheme will typically be http or https, but is not restricted by this class. authority is specified as:
authority = [ userinfo @ ] hostrange [ : portrange ] portrange = portnumber | -portnumber | portnumber-[portnumber] | * hostrange = ([*.] dnsname) | IPv4address | IPv6addressdnsname is a standard DNS host or domain name, i.e. one or more labels separated by ".". IPv4address is a standard literal IPv4 address and IPv6address is as defined in RFC 2732. Literal IPv6 addresses must however, be enclosed in '[]' characters. The dnsname specification can be preceded by "*." which means the name will match any hostname whose right-most domain labels are the same as this name. For example, "*.example.com" matches "foo.bar.example.com"
portrange is used to specify a port number, or a bounded or unbounded range of ports that this permission applies to. If portrange is absent or invalid, then a default port number is assumed if the scheme is http
(default 80) or https
(default 443). No default is assumed for other schemes. A wildcard may be specified which means all ports.
userinfo is optional. A userinfo component if present, is ignored when creating a URLPermission, and has no effect on any other methods defined by this class.
The path component comprises a sequence of path segments, separated by '/' characters. path may also be empty. The path is specified in a similar way to the path in FilePermission
. There are three different ways as the following examples show:
Example url | Description |
---|---|
http://www.example.com/a/b/c.html | A url which identifies a specific (single) resource |
http://www.example.com/a/b/* | The '*' character refers to all resources in the same "directory" - in other words all resources with the same number of path components, and which only differ in the final path component, represented by the '*'. |
http://www.example.com/a/b/- | The '-' character refers to all resources recursively below the preceding path (e.g. http://www.example.com/a/b/c/d/e.html matches this example). |
The '*' and '-' may only be specified in the final segment of a path and must be the only character in that segment. Any query or fragment components of the url are ignored when constructing URLPermissions.
As a special case, urls of the form, "scheme:*" are accepted to mean any url of the given scheme.
The scheme and authority components of the url string are handled without regard to case. This means equals(Object)
, hashCode()
and implies(Permission)
are case insensitive with respect to these components. If the authority contains a literal IP address, then the address is normalized for comparison. The path component is case sensitive.
ignored-query-or-fragment refers to any query or fragment which appears after the path component, and which is ignored by the constructors of this class. It is defined as:
ignored-query-or-fragment = [ ? query ] [ # fragment ]where query and fragment are as defined in RFC2396.
getName()
therefore returns only the scheme, authority and path components of the url string that the permission was created with. The actions string
The actions string of a URLPermission is a concatenation of the method list and the request headers list. These are lists of the permitted request methods and permitted request headers of the permission (respectively). The two lists are separated by a colon ':' character and elements of each list are comma separated. Some examples are:
The first example specifies the methods: POST, GET and DELETE, but no request headers. The second example specifies one request method and two headers. The third example specifies two request methods, and two headers.
The colon separator need not be present if the request headers list is empty. No white-space is permitted in the actions string. The action strings supplied to the URLPermission constructors are case-insensitive and are normalized by converting method names to upper-case and header names to the form defines in RFC2616 (lower case with initial letter of each word capitalized). Either list can contain a wild-card '*' character which signifies all request methods or headers respectively.
Note. Depending on the context of use, some request methods and headers may be permitted at all times, and others may not be permitted at any time. For example, the HTTP protocol handler might disallow certain headers such as Content-Length from being set by application code, regardless of whether the security policy in force, permits it.
Constructor | Description |
---|---|
URLPermission |
Creates a URLPermission with the given url string and unrestricted methods and request headers by invoking the two argument constructor as follows: URLPermission(url, "*:*") |
URLPermission |
Creates a new URLPermission from a url string and which permits the given request methods and user-settable request headers. |
Modifier and Type | Method | Description |
---|---|---|
boolean |
equals |
Returns true if, this.getActions().equals(p.getActions()) and p's url equals this's url. |
String |
getActions() |
Returns the normalized method list and request header list, in the form: |
int |
hashCode() |
Returns a hashcode calculated from the hashcode of the actions String and the url string. |
boolean |
implies |
Checks if this URLPermission implies the given permission. |
checkGuard, getName, newPermissionCollection, toString
public URLPermission(String url, String actions)
url
- the url stringactions
- the actions stringIllegalArgumentException
- if url is invalid or if actions contains white-space.public URLPermission(String url)
url
- the url stringIllegalArgumentException
- if url does not result in a valid URI
public String getActions()
"method-names : header-names"
where method-names is the list of methods separated by commas and header-names is the list of permitted headers separated by commas. There is no white space in the returned String. If header-names is empty then the colon separator may not be present.
getActions
in class Permission
Permission
.public boolean implies(Permission p)
Some examples of how paths are matched are shown below:
this's path | p's path | match |
---|---|---|
/a/b | /a/b | yes |
/a/b/* | /a/b/c | yes |
/a/b/c/d | no | |
/a/b/c/- | no | |
/a/b/- | /a/b/c/d | yes |
/a/b/c/d/e | yes | |
/a/b/c/* | yes |
implies
in class Permission
p
- the permission to check against.true
if the specified permission is implied by this object, false
if not.public boolean equals(Object p)
equals
in class Permission
p
- the object we are testing for equality with this object.true
if both Permission
objects are equivalent.public int hashCode()
hashCode
in class Permission
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/net/URLPermission.html