开发者

Error: java.security.AccessControlException: Access denied

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 JavaA开发者_运维问答gent 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)


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.


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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜