Tomcat – java.security.AccessControlException: access denied (java.lang.RuntimePermission accessDeclaredMembers)

Problem

As i said in previously post, Tomcat 5.5.25 made a lot of modification in policy file, which may enhance security on web application but it also causing a lot of problem, see another error message :


SEVERE: Context initialization failed java.security.AccessControlException: 
      access denied (java.lang.RuntimePermission accessDeclaredMembers) at           
      java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)

Solution

Policy file issue, vi 04webapps.policy, this file is usually located at policy.d folder


mkyong@mkyong-desktop:/etc/tomcat5.5/policy.d$ 04webapps.policy

add following statement into the policy file


permission java.lang.RuntimePermission "accessDeclaredMembers";

For example,

File : 04webapps.policy


    // JVM properties to allow read access
    permission java.util.PropertyPermission "java.version", "read";
    permission java.util.PropertyPermission "java.vendor", "read";
    //omitted for readability 
    // Precompiled JSPs need access to this package.
    permission java.lang.RuntimePermission "accessClassInPackage.org.apache.jasper.runtime";
    permission java.lang.RuntimePermission "accessClassInPackage.org.apache.jasper.runtime.*";

    permission java.lang.RuntimePermission "accessDeclaredMembers";
};

Saved it, restart Tomcat and Done.

7 comments on “Tomcat – java.security.AccessControlException: access denied (java.lang.RuntimePermission accessDeclaredMembers)

  1. I will be created PDF File in Runtime Applet Window (Button Click Event). I face this error:

    “java.security.accesscontrolexception access denied (java.lang.runtimepermission getenv.*) in Applet Window”

    Code
    ———-
    .
    .
    .
    pdfFile = new File(System.getenv(“Temp”) + File.separator + “Filename.pdf”);
    if (pdfFile.exists())
    {
    if (Desktop.isDesktopSupported()) {
    Desktop.getDesktop().open(pdfFile);
    }
    }

    Reply
  2. I will be created PDF File in Runtime Applet Window (Button Click Event). I face this error:

    “java.security.accesscontrolexception access denied (java.lang.runtimepermission getenv.*) in Applet Window”

    Code
    ———-
    .
    .
    .
    pdfFile = new File(System.getenv(“Temp”) + File.separator + “Filename.pdf”);
    if (pdfFile.exists())
    {
    if (Desktop.isDesktopSupported()) {
    Desktop.getDesktop().open(pdfFile);
    }
    }

    Reply
  3. java.security.accesscontrolexception access denied (java.lang.runtimepermission getenv.*) in Applet Window.

    Reply
  4. java.security.accesscontrolexception access denied (java.lang.runtimepermission getenv.*) in Applet Window.

    Reply
  5. Well, it depends, in my case im deploying an application through JWS and i got that message. My app contains a web service client and i needed some jars to connect the server.
    The problem was that the jnlp file was missing the section:

    
    

    Of course, the jars are signed in order to run without problems. Once i added that instructions the exception gone.

    Btw, I didn’t need to modify any policy file.

    Reply

Leave a Comment

Your email address will not be published. Required fields are marked *