URLPermission class is used to represent the permission to access the resources of the given URL. The given URL acts as the name of the permission. The actions represent the request methods and headers.
Class declaration:
public final class URLPermission extends Permission
Constructors:
| Constructor | Description |
|---|---|
|
URLPermission(String url) |
This constructor is used to create a new instance of URLPermission class with the specified URL |
|
URLPermission(String url, String actions) |
This constructor is used to create a new instance of URLPermission class with the specified URL and actions |
Methods:
|
Methods |
Description |
|---|---|
|
equals(Object p) |
This method checks whether the two URLPermission objects are equal or not. |
|
getActions() |
This method returns the actions in String format, which is currently a normalized method list and sends a request for header list. |
|
hashCode() |
This method returns the hash value of this object. |
|
implies(Permission p) |
This method checks whether the given permission is implied by this object or not. |
Example 1:
Java
// Java program to illustrate working of hashCode() methodimport java.net.URLPermission;  public class URLpermission {      public static void main(String[] args)    {        // creating a new URLPermission object        URLPermission permission            = new URLPermission(url, "connect");        // printing the actions of this URLPermission object        System.out.println("Actions: "                           + permission.getActions());        // printing the hash value of this URLPermission        // object        System.out.println("Hashcode: "                           + permission.hashCode());    }} |
Actions: CONNECT: Hashcode: -1592744539
Example 2:
Java
// Java program to illustrate working of equals() methodimport java.net.URLPermission;Â Â public class URLpermission {Â Â Â Â Â Â public static void main(String[] args)Â Â Â Â {Â Â Â Â Â Â Â Â String url2Â Â Â Â Â Â Â Â URLPermission permission1 = new URLPermission(url1);Â Â Â Â Â Â Â Â URLPermission permission2 = new URLPermission(url2);Â Â Â Â Â Â Â Â Â Â if (permission1.equals(permission2)) {Â Â Â Â Â Â Â Â Â Â Â Â System.out.println("Both objects are equal");Â Â Â Â Â Â Â Â }Â Â Â Â Â Â Â Â else {Â Â Â Â Â Â Â Â Â Â Â Â System.out.println(Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "Both objects are not equal");Â Â Â Â Â Â Â Â }Â Â Â Â }} |
Both objects are not equal
