且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

java.security.AccessControlException:运行小程序时发生

更新时间:2022-02-14 00:05:50

由于安全原因,小程序默认情况下在具有受限权限的沙箱环境中运行.小程序没有运行时权限来创建或修改线程组,因此您将获得异常.不要创建新的线程组.否则,通过授予运行时创建或修改线程组的权限,覆盖您的安全策略以明确允许您的applet创建一个applet.要覆盖默认权限,请在用户主目录的.java.policy文件中定义适当的策略.建议您编辑用户特定的策略文件,而不是JRE安全目录下的全局策略文件.

Applets, by default, run in a sandbox environment with restricted permissions because of security reasons. Applets do not have runtime permissions to create or modify thread groups and hence you are getting the exception. Do not create a new thread group. Or else override your security policy to explicitly allow your applet to create one by granting the runtime permission to create or modify thread group. To override default permissions define appropriate policy in your user home's .java.policy file. It is recommended that you edit your user specific policy file and not the global policy file under your JRE security directory.

使用JDK的策略工具定义策略或手动执行.请参考下面的模板:

Use a JDK's policy tool to define the policy or do it manually. Refer the template below:

grant codeBase "<code base>" {
  permission <type> "<target>", "<actions>";
  permission <type> "<target>", "<actions>";
  ...
};

For eg. 
grant codeBase "http://geosim.cs.vt.edu/geosim/-" {
  permission java.lang.RuntimePermission "modifyThreadGroup";
  ...
};