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
import java.nio.file.LinkPermission;
import java.security.Permission;
public class GFG {
public static void main(String[] args)
{
try {
Permission permission
= new LinkPermission( "hard" );
System.out.println(permission.getName());
System.out.println(permission.getClass());
System.out.println(permission.hashCode());
}
catch (Exception e) {
e.printStackTrace();
}
}
}
|
Outputhard
class java.nio.file.LinkPermission
3195115
Example 2: Java program to create a new symbolic LinkPermission
Java
import java.nio.file.LinkPermission;
import java.security.Permission;
public class GFG {
public static void main(String[] args)
{
try {
Permission permission
= new LinkPermission( "symbolic" );
System.out.println(permission.getName());
System.out.println(permission.getClass());
System.out.println(permission.hashCode());
}
catch (Exception e) {
e.printStackTrace();
}
}
}
|
Outputsymbolic
class java.nio.file.LinkPermission
1787985074
Example 3: Java program to compare two LinkPermission objects
Java
import java.nio.file.LinkPermission;
import java.security.Permission;
public class GFG {
public static void main(String[] args)
{
try {
Permission hardPermission
= new LinkPermission( "hard" );
Permission softPermission
= new LinkPermission( "symbolic" );
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();
}
}
}
|
OutputBoth permission are not equal