java.nio.file.LinkPermission Class in Java

The java.nio.file.LinkPermission class handles permissions for link creation operations. The permission allowed by these class are as follows:
|
Permission name |
What permission allows |
Risk of granting this permission |
|---|---|---|
|
hard |
This permission allows adding an existing file to a directory. This operation is also known as creating a hard link. |
The attacker may have access to all files because this permission allows linking to any file in the file system. |
|
symbolic |
This permission allows creating file pointers. This operation is also known as creating soft/symbolic link. |
The attacker may have access to all files because this permission allows linking to any file in the file system. |
Class declaration:
public final class LinkPermission extends BasicPermission
Constructor:
| Constructor | Description |
|---|---|
| LinkPermission(String name) | This constructor is used to create a LinkPermission with the specified name. |
| LinkPermission(String name, String actions) | This constructor is used to create a LinkPermission with the specified name and action. |
Methods inherited from class java.security.BasicPermission:
| Method | Description |
|---|---|
| equals(Object obj) | This method checks whether the two BasicPermission objects are equal or not |
| getActions() | This method returns the actions in String format |
| hashCode() | This method returns the hash code value for this object |
| implies(Permission permission) | This method checks whether the given permission is implied by this object or not |
| newPermissionCollection() | This method returns a new PermissionCollection object |
Example 1: Java program to create a new hard LinkPermission
Java
// Java program to create a new hard LinkPermissionimport java.nio.file.LinkPermission;import java.security.Permission;// Driver classpublic class GFG { // Main method public static void main(String[] args) { try { // Creating a new LinkPermission object Permission permission = new LinkPermission("hard"); // Printing name of the permission System.out.println(permission.getName()); // Printing class of the permission object System.out.println(permission.getClass()); // Printing hash value of the permission object System.out.println(permission.hashCode()); } catch (Exception e) { e.printStackTrace(); } }} |
hard class java.nio.file.LinkPermission 3195115
Example 2: Java program to create a new symbolic LinkPermission
Java
// Java program to create a new symbolic LinkPermissionimport java.nio.file.LinkPermission;import java.security.Permission;// Driver classpublic class GFG { // Main method public static void main(String[] args) { try { // Creating a new LinkPermission object Permission permission = new LinkPermission("symbolic"); // Printing name of the permission System.out.println(permission.getName()); // Printing class of the permission object System.out.println(permission.getClass()); // Printing hash value of the permission object System.out.println(permission.hashCode()); } catch (Exception e) { e.printStackTrace(); } }} |
symbolic class java.nio.file.LinkPermission 1787985074
Example 3: Java program to compare two LinkPermission objects
Java
// Java program to compare two LinkPermission objectsimport java.nio.file.LinkPermission;import java.security.Permission;// Driver classpublic class GFG { // Main method public static void main(String[] args) { try { Permission hardPermission = new LinkPermission("hard"); Permission softPermission = new LinkPermission("symbolic"); // Checking is both permissions are equal or not if (hardPermission.equals(softPermission)) { System.out.println( "Both permission are equal"); } else { System.out.println( "Both permission are not equal"); } } catch (Exception e) { e.printStackTrace(); } }} |
Both permission are not equal



