Java SecurityManager checkPackageDefinition()方法與示例

SecurityManager類的checkPackageDefinition()方法 (SecurityManager Class checkPackageDefinition() method)

  • checkPackageDefinition() method is available in java.lang package.

    checkPackageDefinition()方法在java.lang包中可用。

  • We call getProperty("package.definition") to get a list of restricted packages and it checks when our pkg_name starts with or similar to any of the list of restricted packages and when it matches then it calls checkPermission with the RuntimePermission("defineClassInPackage."+pkg_name).

    我們調用getProperty(“ package.definition”)來獲取受限程序包列表,它會檢查何時pkg_name以任何受限程序包列表開頭或相似,并且何時匹配,然后使用RuntimePermission(“ defineClassInPackage)調用checkPermission。 “ + pkg_name)。

  • checkPackageDefinition() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    checkPackageDefinition()方法是一種非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。

  • checkPackageDefinition() method may throw an exception at the time of defining the class in the given package.

    在給定包中定義類時, checkPackageDefinition()方法可能會引發異常。

    SecurityException – This exception may throw when the calling thread does not have the right to define classes in the given package.

    SecurityException-當調用線程無權在給定包中定義類時,可能引發此異常。

Syntax:

句法:

    public void checkPackageDefinition(String pkg_def);

Parameter(s):

參數:

  • String pkg_def – represents the name of the package.

    字符串pkg_def –表示軟件包的名稱。

Return value:

返回值:

The return type of this method is void, it returns nothing.

此方法的返回類型為void ,不返回任何內容。

Example:

例:

// Java program to demonstrate the example 
// of void checkPackageDefinition(String pkg_def)
// method of SecurityManager 
public class checkPackageDefinition extends SecurityManager {
// override checkPackageDefinition() method of SecurityManager
public void checkPackageDefinition(String pkg_def) {
throw new SecurityException("Restricted...");
}
public static void main(String[] args) throws Exception {
// By using setProperty() method is to set the policy property 
// with security manager
System.setProperty("java.security.policy", "file:/C:/java.policy");
// Instantiating a checkPackageDefinition object
checkPackageDefinition cpd = new checkPackageDefinition();
// By using setSecurityManager() method is to set the
// security manager
System.setSecurityManager(cpd);
// By using checkPackageDefinition(pkg_def) method is to check 
// that package is defined or not
cpd.checkPackageDefinition("java.lang");
// Display the message
System.out.println("Not Restricted..");
}
}

Output

輸出量

Exception in thread "main" java.lang.SecurityException: Restricted...at checkPackageDefinition.checkPackageDefinition(checkPackageDefinition.java:8)at checkPackageDefinition.main(checkPackageDefinition.java:25)

翻譯自: https://www.includehelp.com/java/securitymanager-checkpackagedefinition-method-with-example.aspx

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/542638.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/542638.shtml
英文地址,請注明出處:http://en.pswp.cn/news/542638.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

java容器詳解_詳解Java 容器(第①篇)——概覽

![](http://img.blog.itpub.net/blog/2020/04/02/9d89d3008962c127.png?x-oss-processstyle/bb)容器主要包括 Collection 和 Map 兩種,Collection 存儲著對象的集合,而 Map 存儲著鍵值對(兩個對象)的映射表。# 一、Collection![](https://upload-images…

python圖形界面庫哪個好_8個必備的Python GUI庫

Python GUI 庫有很多,下面給大家羅列常用的幾種 GUI庫。下面介紹的這些GUI框架,能滿足大部分開發人員的需要,你可以根據自己的需求,選擇合適的GUI庫。1. wxPython wxPython 是一個跨平臺的 GUI 工具集,是 Python 語言的…

為什么在Python中使用string.join(list)而不是list.join(string)?

join() is a string method and while using it the separator string iterates over an arbitrary sequence, forming string representations of each of the elements, inserting itself between the elements. join()是一個字符串方法,使用它時,分隔…

js的client、scroll、offset詳解與兼容性

clientWidth:可視區寬說明:樣式寬padding參考:js的client詳解 scrollTop : 滾動條滾動距離說明:chrome下他會以為滾動條是文檔元素的,所以需要做兼容:var scrollTop document.documentElement.scrollTop |…

88是python語言的整數類型_Python基礎數據類型題

Python基礎數據類型 題 考試時間:三個小時 滿分100分(80分以上包含80分及格) 1,簡述變量命名規范(3分)1.必須是字母,數字,下劃線的任意組合。 2.不能是數字開頭 3.不能是python中的關…

[轉載]使用awk進行數字計算,保留指定位小數

對于在Shell中進行數字的計算,其實方法有很多,但是常用的方法都有其弱點: 1、bc bc應該是最常用的Linux中計算器了,簡單方便,支持浮點。 [wangdongcentos715-node1 ~]$ echo 12 |bc 3 [wangdongcentos715-node1 ~]$ ec…

dcom配置_spring cloud 二代架構依賴組件 全配置放送

一 背景介紹先來看一下我們熟悉的第一代 spring cloud 的組件spring cloud 現在已經是一種標準了,各公司可以基于它的編程模型編寫自己的組件 ,比如Netflix、阿里巴巴都有自己的一套通過spring cloud 編程模型開發的分布式服務組件 。Spring Cloud 二代組…

olap 多維分析_OLAP(在線分析處理)| OLAP多維數據集和操作

olap 多維分析In the previous article of OLAP, we have seen various applications of OLAP, Various types of OLAP, advantages, and disadvantages of OLAP. In this article, we will learn about the, 在OLAP的上一篇文章中,我們了解了OLAP的各種應用&#x…

dede mysql語句_讓dede運行php代碼和mysql語句

一、dede運行php代碼舉例1:{dede:name runphpyes}$str "hello ";me $str;me . "world";{/dede:name}結果:hello world說明:"name"為任意定義的名字,me 表示當前的值,也就是要輸出最后…

每周一書-2016年8月28日到9月4日獲獎讀者公布

每周一書-2016年8月28日到9月4日獲獎讀者公布 上次送出的《Bootstrap基礎教程》,已經被幸運者收到了。我們先來回顧下《改善C程序代碼的125個建議》活動文章下的精彩留言。 這是一段高屋建瓴的評述,足見作者對C語言的了解和熱愛層度,當然也得…

c構造函數和析構函數_C ++構造函數和析構函數| 查找輸出程序| 套裝2

c構造函數和析構函數Program 1: 程序1&#xff1a; #include<iostream>using namespace std;class Sample{private:int X;int Y;public:Sample(int x, int y){X x;Y y;}void set(int x, int y){X x;Y y;}void print(){cout<<X<<" "<<Y&…

python map函數的作用_Python的map函數

map()是 Python 內置的高階函數&#xff0c;它接收一個函數 f 和一個 list&#xff0c;并通過把函數 f 依次作用在 list 的每個元素上&#xff0c;得到一個新的 list 并返回。 例如&#xff0c;對于list [1, 2, 3, 4, 5, 6, 7, 8, 9] 如果希望把list的每個元素都作平方&#xf…

idea java no sdk_java - intelliJ IDEA 13錯誤:請選擇Android SDK

java - intelliJ IDEA 13錯誤&#xff1a;請選擇Android SDK我已經在Error: Cannot find any configured Android SDK上安裝了intelliJ 12.1.2和Error: Cannot find any configured Android SDK。現在我使用intelliJ 13.0.1創建了一個空的android應用程序項目(也使用模擬器作為…

該怎樣在KeyShot中進行貼圖

2019獨角獸企業重金招聘Python工程師標準>>> 在渲染物體的時候&#xff0c;貼圖常常是不可缺少的部分&#xff0c;貼圖主要用于描述對象表面的物質形態&#xff0c;構造真實世界中自然物質表面的視覺表象。不同的貼圖能給人帶來不同的視覺感受&#xff0c;KeyShot3D…

python淘寶cookies搶購_Python實現淘寶秒殺聚劃算搶購自動提醒源碼

說明 本實例能夠監控聚劃算的搶購按鈕&#xff0c;在聚劃算整點聚的時間到達時發出提醒&#xff08;音頻文件自己定義位置&#xff09;并自動彈開頁面&#xff08;URL自己定義&#xff09;。 同時還可以通過命令行參數自定義刷新間隔時間&#xff08;默認0.1s&#xff09;和監控…

kadane算法_使用KADANE的算法求最大子陣列和

kadane算法What is a sub-array? 什么是子陣列&#xff1f; A sub-array is basically an arrays contiguous part. For example, if we have an array of integers [1,2,3] so the sub-arrays that we can form from the given array are [1], [2] , [3] , [1,2] , [2,3] , …

java汽車油耗計算_轉發一個手機油耗計算器 (java)

今天在一個汽車論壇上看見的&#xff0c;試了試&#xff0c;還真不錯。比以前那個Fuel Consumption 功能要強大,雖然都是JAVA軟件。小羅盤手機計算器是作者獨自產品策劃、美術設計、程序開發、測試發布的手機應用軟件&#xff0c;是為作者的一個朋友寫的&#xff0c;當然我們用…

6.dubbo常用的xml配置有哪些_【面試篇】必須掌握的Spring 常用注解

閱讀文本大概需要5分鐘。注解本身沒有功能的&#xff0c;就和 xml 一樣。注解和 xml 都是一種元數據&#xff0c;元數據即解釋數據的數據&#xff0c;這就是所謂配置。本文主要羅列 Spring|Spring MVC相關注解的簡介。Spring部分1、聲明bean的注解Component 組件&#xff0c;沒…

Linux的iptables常用配置范例(2)

iptables -F #清除所有規則 iptables -X #清除所有自定義規則 iptables -Z #各項計數歸零 iptables -P INPUT DROP #將input鏈默認規則設置為丟棄 iptables -P OUTPUT DROP #將output鏈默認規則設置為丟棄 iptables -A INPUT -i lo -j ACCEPT iptables -A OUTPUT -o lo …

aptitude 命令_C-命令行參數Aptitude問題與解答

aptitude 命令C programming Command Line Arguments Aptitude Questions and Answers: In this section you will find C Aptitude Questions and Answers on Command Line Arguments – Passing values with running programs, separate argument values, number of argument…