Syntax:

句法:

    public void checkAccess (Thread th);
public void checkAccess (ThreadGroup tg);

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

  • checkAccess(Thread th) method is called for the current security manager by these methods of Thread class stop(), suspend(), resume(), setName() and setDaemon().

    当前安全管理器的Thread类stop()suspend()resume()setName()setDaemon()这些方法将调用checkAccess(Thread th)方法

  • checkAccess(ThreadGroup tg) method is called for the current security manager to create new child thread on thread group by using these methods of ThreadGroup class like setDaemon(), stop(), resume(), suspend() and destroy().

    当前的安全管理器将调用checkAccess(ThreadGroup tg)方法 ,以通过使用ThreadGroup类的这些方法(例如setDaemon()stop()resume()suspend()destroy())在线程组上创建新的子线程。

  • checkAccess(Thread th), checkAccess (ThreadGroup tg) methods may throw an exception at the time modification.

    checkAccess(Thread th)checkAccess(ThreadGroup tg)方法在修改时可能会引发异常。

    SecurityException: This exception may throw when the calling thread is not allowed to modify Thread or ThreadGroup.

    SecurityException :当不允许调用线程修改Thread或ThreadGroup时,可能引发此异常。

  • These methods are non-static methods, it is accessible with the class object only and, if we try to access these methods with the class name then we will get an error.

    这些方法是非静态方法,只能通过类对象访问,如果尝试使用类名访问这些方法,则会收到错误消息。

Parameter(s):

参数:

  • In the first case, Thread th - This parameter represents the thread to be examined.

    在第一种情况下, Thread th-此参数表示要检查的线程。

  • In the second case, ThreadGroup tg - This parameter represents the thread group to be examined.

    在第二种情况下, ThreadGroup tg-此参数表示要检查的线程组。

Return value:

返回值:

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

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

Example:

例:

// Java program to demonstrate the example
// of checkAccess () method of SecurityManager class
public class CheckAccess extends SecurityManager {// Override checkAcess(Thread th) of SecurityManager class
public void checkAccess(Thread th) {throw new SecurityException("Restricted...");
}
// Override checkAcess(ThreadGroup tg) of SecurityManager //class
public void checkAccess(ThreadGroup tg) {throw new SecurityException("Restricted...");
}
public static void main(String[] args) {ThreadGroup tg1 = new ThreadGroup("New Thread Group");
// By using setProperty() method is to set the policy property
// with security manager
System.setProperty("java.security.policy", "file:/C:/java.policy");
// Instantiating a CheckAccept object
CheckAccess ca = new CheckAccess();
// By using setSecurityManager() method is to set the
// security manager
System.setSecurityManager(ca);
// By using checkAccess(Thread th) method is to check that
// current thread is enabled for access or not
ca.checkAccess(Thread.currentThread());
// By using checkAccess(ThreadGroup tg) method is to check
// that current thread group is enabled for access or not
ca.checkAccess(tg1);
// Display the message when thread is enabled
System.out.println("Not Restricted..");
}
}

Output

输出量

Exception in thread "main" java.lang.SecurityException: Restricted...
at CheckAccess.checkAccess(CheckAccess.java:5)
at CheckAccess.main(CheckAccess.java:30)

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

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

  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. shell脚本自动化部署服务
  2. Meet in the middle
  3. mysql事务隔离级别与锁_mysql事务隔离级别与锁
  4. 可变与不可变数据类型详解
  5. [信息安全] 1.密码工具箱
  6. MySql、PowerDesigner、JDBC 的关系
  7. Jenkins自动部署SpringCloud项目
  8. 错误契约(FaultContract)与异常处理(转)
  9. 2D纹理与3D模型共存时的渲染问题
  10. aix errpt输出详解
  11. SAP系统中资产的分类规则
  12. PopWindow的使用
  13. 车载以太网网络中的时间同步
  14. 上古计算机语言,微软开源其上古编程语言GW-BASIC
  15. Ext.Net配色方案
  16. Java中 … 三个点是什么意思?
  17. 批量下载邮件附件 可筛选和分类 直接跑、稳定版 Python完整代码
  18. net::ERR_FILE_NOT_FOUND报错
  19. python signal模块作用_Python中的signal模块和Ctrl+C操作
  20. 如何下载淘宝视频-淘宝视频下载详细以及注意

热门文章

  1. Docker挂了,数据如何找回
  2. Flume监听端口,输出端口数据案例
  3. Nginx(一):概念基础
  4. U-Net++粗略解释
  5. PHP-Manual的学习----【语言参考】----【类型】-----【对象】
  6. CentOS7下的AIDE***检测配置
  7. 怎样在fastboot 里面加入新的命令
  8. UIScrollView的简单使用
  9. 代理服务器Tengine的研究与测试
  10. WCF Data Services 基础