错误:java.security.AccessControlException:拒绝访问

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2635881/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 22:08:48  来源:igfitidea点击:

Error: java.security.AccessControlException: Access denied

javasecurityaccess-deniedlotus-domino

提问by RMD

I have to connect to a https URL with username and password to read a file. I am not able to connect to the server (see the error log below). I do not have much Java experience, so I need help with this code.

我必须使用用户名和密码连接到 https URL 才能读取文件。我无法连接到服务器(请参阅下面的错误日志)。我没有太多的 Java 经验,所以我需要这段代码的帮助。

import lotus.domino.*;
import java.net.*;
import java.io.*;
import javax.net.ssl.HttpsURLConnection;

public class JavaAgent extends AgentBase {

public void NotesMain() {

  try {
    String username = "123";
    String password = "456";
    String input = username + ":" + password;
    String encoding = new sun.misc.BASE64Encoder().encode (input.getBytes());

    //Open the URL and read the text into a Buffer
    String urlName = "https://server.org/Export.mvc/GetMeetings?modifiedSince=4/9/2010";
    URL url = new URL(urlName);
    HttpsURLConnection connection = (HttpsURLConnection)url.openConnection();

    connection.setRequestMethod("POST");
    connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    connection.setRequestProperty("Content-Length", String.valueOf (encoding.length())); 
    connection.setUseCaches(false);
    connection.setDoInput(true);
    connection.setDoOutput(true);
    connection.setAllowUserInteraction(true);
    connection.setRequestProperty("Authorization", "Basic " + encoding);
    connection.setRequestProperty("Cookie", "LocationCode=Geneva");

    connection.connect();

    BufferedReader rd = null;
      try{
        rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
      } catch (IOException e) {
        System.out.println("Read failed");
        System.exit(-1);
      }

    String line;
    while((line = rd.readLine()) != null) {
      System.out.println(line.toString());
    }
    rd.close();

    connection.disconnect();

  } catch(Exception e) {
    e.printStackTrace();
  }
}
}

Exception thrown:

抛出异常:

java.security.AccessControlException: Access denied (java.lang.RuntimePermission exitVM.-1)
 at java.security.AccessController.checkPermission(AccessController.java:108)
 at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
 at COM.ibm.JEmpower.applet.AppletSecurity.superDotCheckPermission(AppletSecurity.java:1449)
 at COM.ibm.JEmpower.applet.AppletSecurity.checkRuntimePermission(AppletSecurity.java:1311)
 at COM.ibm.JEmpower.applet.AppletSecurity.checkPermission(AppletSecurity.java:1611)
 at COM.ibm.JEmpower.applet.AppletSecurity.checkPermission(AppletSecurity.java:1464)
 at java.lang.SecurityManager.checkExit(SecurityManager.java:744)
 at java.lang.Runtime.exit(Runtime.java:99)
 at java.lang.System.exit(System.java:275)
 at JavaAgent.NotesMain(Unknown Source)
 at lotus.domino.AgentBase.runNotes(Unknown Source)
 at lotus.domino.NotesThread.run(Unknown Source)

回答by haylem

Old thread, but I stumbled upon it so here's an updated answer.

旧线程,但我偶然发现了它,所以这里有一个更新的答案。

The answer is in your stacktrace. while it may relate to the use of Domino this is a general issue that would occur for a pretty simple applet used on a normal JVM invoked from the standard Java browser plugins, and apparently your Java Agent is using an applet sandbox.

答案在您的堆栈跟踪中。虽然它可能与 Domino 的使用有关,但这是一个普遍问题,在从标准 Java 浏览器插件调用的普通 JVM 上使用的非常简单的小程序会发生,显然您的 Java 代理正在使用小程序沙箱。

Applets are not allowed (except by modifying directly the Java Security Policy on the client machine) to perform some critical calls. Even if using signed applets.

不允许小程序(除非直接修改客户机上的 Java 安全策略)执行一些关键调用。即使使用签名小程序。

In your case, System.exit(-1)is triggering the exception. The reason for this is that applets have a fairly complex lifecycle, and you are not supposed to mess around with it. It's for your own good, as you want the browser to be able to interact with the applet for you and to be able to tear-down (or re-use) the JVM process launched to run the applet. By invocating System.exit()or others, you'd mess up with this lifecycle and with your browser's chances of controlling the applet's destruction.

在您的情况下,System.exit(-1)正在触发异常。这样做的原因是 applet 有一个相当复杂的生命周期,你不应该把它弄乱。这是为了您自己的利益,因为您希望浏览器能够为您与小程序交互,并能够拆除(或重新使用)为运行小程序而启动的 JVM 进程。通过调用System.exit()或其他方式,您会弄乱这个生命周期以及您的浏览器控制小程序销毁的机会。

You may want to re-consider why you need this entirely, as you probably don't need to invoke a System.exit()call there.

您可能需要重新考虑为什么完全需要它,因为您可能不需要在System.exit()那里调用调用。

回答by Sio

I take it this is a Java agent? Things to check.

我认为这是一个Java代理?要检查的东西。

  1. In the agent properties that the security level is set for what you want to do. Normally file access requires at least level 2.

  2. The signature of the agent or the user the agent is set to run as is allowed to run on the server.

  3. You can modify the java.policy file to allow access to certain restricted classes. (but you need to know why you are making the change).

  1. 在代理属性中为您要执行的操作设置了安全级别。通常文件访问至少需要级别 2。

  2. 代理或代理设置为运行的用户的签名被允许在服务器上运行。

  3. 您可以修改 java.policy 文件以允许访问某些受限类。(但您需要知道为什么要进行更改)。

http://java.sun.com/j2se/1.5.0/docs/guide/security/permissions.html

http://java.sun.com/j2se/1.5.0/docs/guide/security/permissions.html

回答by angryITguy

Thissupport thread from IBM sounds similar to your problem if you're running on an 8.5 Domino server.

如果您在 8.5 Domino 服务器上运行,IBM 的这个支持线程听起来与您的问题相似。

回答by Arne Deutsch

An applet may access only the server it is loaded from. Most probably your applet is not loaded from the server you are trying to connect to?

小程序只能访问加载它的服务器。很可能您的小程序没有从您尝试连接的服务器加载?

EDIT: Your stacktrace suggests, that there is a specialised security manager is installed (COM.ibm.JEmpower.applet.AppletSecurity). Googling this class reveals the problem: http://lekkimworld.com/2006/02/28/imported_java_agent.html

编辑:您的堆栈跟踪表明,安装了一个专门的安全管理器 (COM.ibm.JEmpower.applet.AppletSecurity)。谷歌搜索这个类揭示了问题:http: //lekkimworld.com/2006/02/28/imported_java_agent.html