Java的.nio.file.LinkPermission类在Java中
Java.nio.file.LinkPermission 类处理链接创建操作的权限。这些类允许的权限如下: 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.
类声明:
public final class LinkPermission
extends BasicPermission
构造函数: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.
从类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 |
示例1: Java程序创建新的硬LinkPermission
Java
// Java program to create a new hard LinkPermission
import java.nio.file.LinkPermission;
import java.security.Permission;
// Driver class
public class GFG {
// Main method
public static void main(String[] args)
{
try {
// Creating a new LinkPermisson 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();
}
}
}
Java
// Java program to create a new symbolic LinkPermission
import java.nio.file.LinkPermission;
import java.security.Permission;
// Driver class
public class GFG {
// Main method
public static void main(String[] args)
{
try {
// Creating a new LinkPermisson 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();
}
}
}
Java
// Java program to compare two LinkPermission objects
import java.nio.file.LinkPermission;
import java.security.Permission;
// Driver class
public 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();
}
}
}
hard
class java.nio.file.LinkPermission
3195115
示例 2: Java程序创建新的符号 LinkPermission
Java
// Java program to create a new symbolic LinkPermission
import java.nio.file.LinkPermission;
import java.security.Permission;
// Driver class
public class GFG {
// Main method
public static void main(String[] args)
{
try {
// Creating a new LinkPermisson 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
示例 3:比较两个 LinkPermission 对象的Java程序
Java
// Java program to compare two LinkPermission objects
import java.nio.file.LinkPermission;
import java.security.Permission;
// Driver class
public 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