java.lang.RuntimePermission when running a applet from the web application

applet, environment-variables, java, tomcat6, web-applications

Solution

When you run your applet from netbeans, Java virtual machines runs it under a different security regime than when you run it through browser.

Applets, downloaded through browsers, that are not signed using a security certificate, are considered to be untrusted and referred to as unsigned applets. When running on a client, unsigned applets operate within a security sandbox that allows only a set of safe operations. You can check if a perticular permission is granted to you applet or not by using SecurityManager. For example in your case :

System.getSecurityManager().checkPermission(new RuntimePermission("accessDeclaredMembers"));

You can know more about applet security here and here. A very nice tutorial on making signed applets can be found here.

Problem

I'm trying to read a envrionment varaible from a applet, here is my code ``` String env = System.getenv("TWS"); System.out.println(env); Runtime rt = Runtime.getRuntime(); String s = env + "\\WebStart.bat " ; System.out.println(s); try { Process p = rt.exec(s); } catch (Exception e) { } ``` when i run the code from netbeans by right click and run, it is running without a problem. but when i put it to a jar file, add it to my web application and try to run it from a html page using the following code ``` <applet code="draw.class" archive='AppletTest.jar'> <param name="shape" value="triangle"/> </applet> ``` i'm getting a error saying access denied , java.lang.RuntimePermission i am running this web application using tomcat 6. i have read some guides and added the following entry to catalina.policy file in tomcat 6 and restarted tomcat ``` permission java.lang.RuntimePermission "accessDeclaredMembers"; ``` but still the same warning. can some one please suggest a solution for this problem? --rangana

Original source