當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java java.nio.file.LinkPermission用法及代碼示例


java.nio.file.LinkPermission 類處理鏈接創建操作的權限。這些類允許的權限如下:

權限名稱

什麽權限允許

授予此權限的風險

hard

此權限允許將現有文件添加到目錄中。此操作也稱為創建硬鏈接。

攻擊者可能有權訪問所有文件,因為此權限允許鏈接到文件係統中的任何文件。

symbolic

此權限允許創建文件指針。此操作也稱為創建軟/符號鏈接。

攻擊者可能有權訪問所有文件,因為此權限允許鏈接到文件係統中的任何文件。

類聲明:

public final class LinkPermission
extends BasicPermission

構造函數:

構造函數 說明
LinkPermission(String name) 此構造函數用於創建具有指定名稱的LinkPermission。
LinkPermission(String name, String actions) 此構造函數用於創建具有指定名稱和操作的LinkPermission。

從類 java.security.BasicPermission 繼承的方法:

方法 說明
equals(Object obj) 該方法檢查兩個BasicPermission對象是否相等
getActions() 該方法以字符串格式返回操作
hashCode() 該方法返回該對象的哈希碼值
implies(Permission permission) 此方法檢查該對象是否隱含給定的權限
newPermissionCollection() 此方法返回一個新的PermissionCollection對象

示例 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 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

示例 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 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

示例 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


相關用法


注:本文由純淨天空篩選整理自abhinavjain194大神的英文原創作品 java.nio.file.LinkPermission Class in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。