SecurityManager類checkPropertiesAccess()方法
- checkPropertiesAccess() 方法在 java.lang 包中可用。
- checkPropertiesAccess() 方法使用 PropertyPermission("*", "read, write") 權限調用 checkPermission 以授予對屬性的訪問權限。
- checkPropertiesAccess() 方法是一個非靜態方法,它隻能通過類對象訪問,如果我們嘗試使用類名訪問方法,那麽我們將得到一個錯誤。
- checkPropertiesAccess() 方法可能在訪問屬性時拋出異常。
SecurityException– 當調用線程無權訪問或更新係統屬性時,可能會拋出此異常。
用法:
public void checkPropertiesAccess();
參數:
- 它不接受任何參數。
返回值:
這個方法的返回類型是void
,它什麽都不返回。
例:
// Java program to demonstrate the example
// of void checkPropertiesAccess ()
// method of SecurityManager
public class CheckPropertiesAccess extends SecurityManager {
public static void main(String[] args) {
// By using setProperty() method is to set the policy property
// with security manager
System.setProperty("java.security.policy", "file:/C:/java.policy");
// Instantiating a CheckPropertiesAccess object
CheckPropertiesAccess cpa = new CheckPropertiesAccess();
// By using setSecurityManager() method is to set the
// security manager
System.setSecurityManager(cpa);
// By using checkPropertiesAccess() method is to check
// accessing of system properties
cpa.checkPropertiesAccess();
// Display the message
System.out.println("Not Restricted..");
}
}
輸出
Exception in thread "main" java.security.AccessControlException:access denied ("java.util.PropertyPermission" "*" "read,write") at java.base/java.security.AccessControlContext.checkPermission(AccessControlContext.java:472) at java.base/java.security.AccessController.checkPermission(AccessController.java:897) at java.base/java.lang.SecurityManager.checkPermission(SecurityManager.java:322) at java.base/java.lang.SecurityManager.checkPropertiesAccess(SecurityManager.java:1034) at CheckPropertiesAccess.main(CheckPropertiesAccess.java:20)
相關用法
- Java SecurityManager checkPropertyAccess()用法及代碼示例
- Java SecurityManager checkPrintJobAccess()用法及代碼示例
- Java SecurityManager checkPackageAccess()用法及代碼示例
- Java SecurityManager checkPermission()用法及代碼示例
- Java SecurityManager checkPackageDefinition()用法及代碼示例
- Java SecurityManager checkSystemClipboardAccess()用法及代碼示例
- Java SecurityManager checkLink()用法及代碼示例
- Java SecurityManager checkWrite()用法及代碼示例
- Java SecurityManager checkAwtEventQueueAccess()用法及代碼示例
- Java SecurityManager checkSetFactory()用法及代碼示例
- Java SecurityManager checkSecurityAccess()用法及代碼示例
- Java SecurityManager checkRead()用法及代碼示例
- Java SecurityManager checkAccept()用法及代碼示例
- Java SecurityManager checkTopLevelWindow()用法及代碼示例
- Java SecurityManager checkDelete()用法及代碼示例
- Java SecurityManager checkAccess()用法及代碼示例
- Java SecurityManager checkConnect()用法及代碼示例
- Java SecurityManager checkMemberAccess()用法及代碼示例
- Java SecurityManager checkListen()用法及代碼示例
- Java SecurityManager checkMulticast()用法及代碼示例
注:本文由純淨天空篩選整理自Preeti Jain大神的英文原創作品 Java SecurityManager checkPropertiesAccess() method with example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。