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

梦想的初衷 提交于 2019-12-23 14:56:52

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/10980614/java-lang-runtimepermission-when-running-a-applet-from-the-web-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!