Main Tutorials

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.

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
7 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Jassyr Juárez
12 years ago

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.

Jassyr Juárez
12 years ago
Reply to  Jassyr Juárez

I dont know what happened with the code.

Just add the all-permissions tag inside security tag.

More info:

http://download.oracle.com/javase/tutorial/deployment/webstart/security.html

SJK
13 years ago

this dosent work!!!

rganeshbabu
10 years ago

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);
}
}

rganeshbabu
10 years ago

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);
}
}

rganeshbabu
10 years ago

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

Ganesh
10 years ago

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