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

发布于 2024-08-29 00:25:23 字数 2648 浏览 8 评论 0原文

我必须使用用户名和密码连接到 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();
  }
}
}

抛出异常:

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)

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.

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

薔薇婲 2024-09-05 00:25:23

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

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

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

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

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

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.

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.

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.

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

木槿暧夏七纪年 2024-09-05 00:25:23

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

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

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

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

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

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

  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).

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

神仙妹妹 2024-09-05 00:25:23

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

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

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

盛夏尉蓝 2024-09-05 00:25:23

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文