SecurityManager类的checkMemberAccess()方法 (SecurityManager Class checkMemberAccess() method)

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

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

  • In checkMemberAccess() method we access public members and classes that have similar class loaders like caller by default and in other cases, it calls checkPermission("accessDeclaredMembers") permission.

    checkMemberAccess()方法中 ,默认情况下,我们访问具有类似类加载器的公共成员和类,例如调用者,在其他情况下,它调用checkPermission(“ accessDeclaredMembers”)权限。

  • checkMemberAccess() 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.

    checkMemberAccess()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • checkMemberAccess() method may throw an exception at the time of accessing members.

    checkMemberAccess()方法在访问成员时可能会引发异常。

    • SecurityException – This exception may throw when the calling thread does not have the right to access members.
    • NullPointerException – This exception may throw when the given first parameter is null.

Syntax:

句法:

    public void checkMemberAccess(Class cl, int type);

Parameter(s):

参数:

  • Class cl – represents the class that indication is to be operated on.

    cl类 –表示要对其进行操作的类。

  • int type – represents the access type like PUBLIC OR DECLARED.

    int type –表示访问类型,例如PUBLIC或DECLARED。

Return value:

返回值:

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

此方法的返回类型为void ,不返回任何内容。

Example:

例:

// Java program to demonstrate the example
// of void checkMemberAccess(Class cl, int type)
// method of SecurityManager
import java.lang.reflect.*;
public class CheckMemberAccess extends SecurityManager {public void checkMemberAccess(Class cl, int type) {throw new SecurityException("Restricted..");
}
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 CheckMemberAccess object
CheckMemberAccess cma = new CheckMemberAccess();
// By using setSecurityManager() method is to set the
// security manager
System.setSecurityManager(cma);
// By using checkMemberAccess(Class,type) method is to check
// accessibility of the member
cma.checkMemberAccess(CheckMemberAccess.class, Member.DECLARED);
// Display the message
System.out.println("Not Restricted..");
}
}

Output

输出量

Exception in thread "main" java.lang.SecurityException: Restricted..at CheckMemberAccess.checkMemberAccess(CheckMemberAccess.java:9)at CheckMemberAccess.main(CheckMemberAccess.java:27)

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

Java SecurityManager checkMemberAccess()方法与示例相关推荐

  1. Java IOUtils.copy方法代码示例(亲测)

    本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...

  2. java user directory,Java ProcessBuilder directory()方法与示例

    语法:public File directory (); public ProcessBuilder directory (File dir); ProcessBuilder类directory()方 ...

  3. Java序列化魔术方法及其示例使用

    在上一篇文章中, 您需要了解有关Java序列化的所有知识 ,我们讨论了如何通过实现Java序列化来启用类的可序列化性. Serializable接口. 如果我们的类未实现Serializable接口, ...

  4. catalog java,Java Connection getCatalog()方法与示例

    通常,目录是一个目录,其中包含有关数据集,文件或数据库的信息.而数据库目录中包含所有数据库,基本表,视图(虚拟表),同义词,值范围,索引,用户和用户组的列表. Connection接口的getCata ...

  5. filepermission java,Java FilePermission getActions()方法与示例

    FilePermission类getActions()方法getActions()方法在java.io包中可用. getActions()方法用于检查此FilePermission和给定对象在路径名和 ...

  6. java方法参数Bundle,Java ResourceBundle keySet()方法及示例

    ResourceBundle类keySet()方法keySet()方法在java.util包中可用. keySet()方法用于从此ResourceBundle及其超级捆绑包中获取所有现有键,以在Set ...

  7. java exec waitfor,Java Process waitFor()方法与示例

    流程类waitFor()方法在java.lang包中提供了waitFor()方法. waitFor()方法用于使当前正在运行的线程在需要时等待,直到由该Process对象表示的进程完成其终止为止. 当 ...

  8. java arraylist.add(),Java ArrayList add()方法与示例

    ArrayList类add()方法 语法:public boolean add(T ele); public void add(int indices, T ele);add()方法在java.uti ...

  9. java rollback用法,Java Connection rollBack()方法与示例

    回滚操作将撤消当前事务所做的所有更改,即,如果调用Connection接口的rollBack()方法,则所有修改都将还原到最后一次提交. 您还可以通过将所需的Savepoint对象作为参数传递给此方法 ...

最新文章

  1. 丹妮在使用计算机计算,美国工程院院士丹妮拉•鲁斯:每个人都有自己的机器人...
  2. mysql centos7 默认密码忘记_centos7 mysql忘记密码解决办法
  3. 让执行程序引用特定目录下的Dll
  4. 转:VMware、微软等四种主要的网络IO虚拟化模型
  5. (SPFA+最短路变形+回路对起点的影响)Arbitrage
  6. jQuery实现checkbox的全选反选方法
  7. 【registry】registry An exception was thrown while processing request with message
  8. 微信小程序 环形进度条_微信小程序:实时圆形进度条实现
  9. 深入理解C语言系列之内存和地址的故事(虚拟内存分区、全局变量与静态变量、外部函数内部函数、选择性编译)
  10. 内存释放_把微信这两个开关关掉, 手机立马释放大量内存, 快去试试吧
  11. 书信要写标题吗_BEC作文写作格式:标题要写吗?首行是否要缩进?
  12. 阶段3 2.Spring_02.程序间耦合_4 曾经代码中的问题分析
  13. 前端开发技巧:网页切图图片格式选择GIF、JPEG 和 PNG区别和对比
  14. UA OPTI512R 傅立叶光学导论14 卷积定理
  15. 优化百度ueditor编辑器,增加秀米插件、手机端预览等功能,与egg-ueditor完美结合
  16. C# Unsafe code may only appear if compiling with /unsafe
  17. python自动读取短信_自动化测试-自动获取手机短信验证码
  18. 16.04编译android 7.0,[原创]使用ubuntu 16.04编译android-6.0.0_r1
  19. 如何在cmd命令行下切换目录(详细步骤)
  20. 如何在微信公众号上传PDF文件?

热门文章

  1. 安装squid_「首席推荐」设置Squid转发代理或者正向代理
  2. python 安装html,python安装glob
  3. 接口里面的方法都是抽象方法吗_大家都在讲高中学习的方法有哪些,那方法和技巧有什么异同的吗?...
  4. python批量跑plsql_python实现自动化报表(Oracle/plsql/Excel/多线程)
  5. python中dlib库_python 基于dlib库的人脸检测的实现
  6. 私钥经过哈希计算可以产生公钥_「区块链基础概念100」:公钥和私钥 | 027
  7. C++通过原子变量代替互斥量
  8. [转]资本经营董事长班告诉你:不只企业有商业模式,个人商业价值更重要
  9. Salesforce宣布5.82亿美元收购文件编辑公司Quip
  10. windosw7 Hosts文件的位置