src/share/classes/java/net/URLPermission.java

Print this page




  55  * separated by ".". <i>IPv4address</i> is a standard literal IPv4 address and
  56  * <i>IPv6address</i> is as defined in <a href="http://www.ietf.org/rfc/rfc2732.txt">
  57  * RFC 2732</a>. Literal IPv6 addresses must however, be enclosed in '[]' characters.
  58  * The <i>dnsname</i> specification can be preceded by "*." which means
  59  * the name will match any hostname whose right-most domain labels are the same as
  60  * this name. For example, "*.oracle.com" matches "foo.bar.oracle.com"
  61  * <p>
  62  * <i>portrange</i> is used to specify a port number, or a bounded or unbounded range of ports
  63  * that this permission applies to. If portrange is absent or invalid, then a default
  64  * port number is assumed if the scheme is {@code http} (default 80) or {@code https}
  65  * (default 443). No default is assumed for other schemes. A wildcard may be specified
  66  * which means all ports.
  67  * <p>
  68  * <i>userinfo</i> is optional. A userinfo component if present, is ignored when
  69  * creating a URLPermission, and has no effect on any other methods defined by this class.
  70  * <p>
  71  * The <i>path</i> component comprises a sequence of path segments,
  72  * separated by '/' characters. <i>path</i> may also be empty. The path is specified
  73  * in a similar way to the path in {@link java.io.FilePermission}. There are
  74  * three different ways as the following examples show:
  75  * <table border>
  76  * <caption>URL Examples</caption>
  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>
  87  * <tr><td>http://www.oracle.com/a/b/-</td>
  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


 228      * following sequence:
 229      * <ul>
 230      * <li>if 'p' is not an instance of URLPermission return false</li>
 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>
 237      * <li>if the set of hosts defined by p's url hostrange is not a subset of
 238      *     this's url hostrange then return false. For example, "*.foo.oracle.com"
 239      *     is a subset of "*.oracle.com". "foo.bar.oracle.com" is not
 240      *     a subset of "*.foo.oracle.com"</li>
 241      * <li>if the portrange defined by p's url is not a subset of the
 242      *     portrange defined by this's url then return false.
 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>
 246      * </ul>
 247      * <p>Some examples of how paths are matched are shown below:
 248      * <table border>
 249      * <caption>Examples of Path Matching</caption>
 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) {
 261         if (! (p instanceof URLPermission)) {
 262             return false;
 263         }
 264 
 265         URLPermission that = (URLPermission)p;
 266 
 267         if (!this.methods.get(0).equals("*") &&
 268                 Collections.indexOfSubList(this.methods, that.methods) == -1) {




  55  * separated by ".". <i>IPv4address</i> is a standard literal IPv4 address and
  56  * <i>IPv6address</i> is as defined in <a href="http://www.ietf.org/rfc/rfc2732.txt">
  57  * RFC 2732</a>. Literal IPv6 addresses must however, be enclosed in '[]' characters.
  58  * The <i>dnsname</i> specification can be preceded by "*." which means
  59  * the name will match any hostname whose right-most domain labels are the same as
  60  * this name. For example, "*.oracle.com" matches "foo.bar.oracle.com"
  61  * <p>
  62  * <i>portrange</i> is used to specify a port number, or a bounded or unbounded range of ports
  63  * that this permission applies to. If portrange is absent or invalid, then a default
  64  * port number is assumed if the scheme is {@code http} (default 80) or {@code https}
  65  * (default 443). No default is assumed for other schemes. A wildcard may be specified
  66  * which means all ports.
  67  * <p>
  68  * <i>userinfo</i> is optional. A userinfo component if present, is ignored when
  69  * creating a URLPermission, and has no effect on any other methods defined by this class.
  70  * <p>
  71  * The <i>path</i> component comprises a sequence of path segments,
  72  * separated by '/' characters. <i>path</i> may also be empty. The path is specified
  73  * in a similar way to the path in {@link java.io.FilePermission}. There are
  74  * three different ways as the following examples show:
  75  * <table border summary="URL examples">
  76  * <caption>URL Examples</caption>
  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>
  87  * <tr><td>http://www.oracle.com/a/b/-</td>
  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


 228      * following sequence:
 229      * <ul>
 230      * <li>if 'p' is not an instance of URLPermission return false</li>
 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>
 237      * <li>if the set of hosts defined by p's url hostrange is not a subset of
 238      *     this's url hostrange then return false. For example, "*.foo.oracle.com"
 239      *     is a subset of "*.oracle.com". "foo.bar.oracle.com" is not
 240      *     a subset of "*.foo.oracle.com"</li>
 241      * <li>if the portrange defined by p's url is not a subset of the
 242      *     portrange defined by this's url then return false.
 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>
 246      * </ul>
 247      * <p>Some examples of how paths are matched are shown below:
 248      * <table border summary="Path Matching examples">
 249      * <caption>Examples of Path Matching</caption>
 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) {
 261         if (! (p instanceof URLPermission)) {
 262             return false;
 263         }
 264 
 265         URLPermission that = (URLPermission)p;
 266 
 267         if (!this.methods.get(0).equals("*") &&
 268                 Collections.indexOfSubList(this.methods, that.methods) == -1) {