Deleting files from signed java applet

拟墨画扇 提交于 2019-12-11 12:32:15

问题


I have to delete some temporary file from a users system when he logs out of application. The application has applet. The applet jar is signed. I am following the strategy to call the applet's destroy method to delete files. I am invoking the destroy method of applet by javascript like document.myApplet.destroy() . After invoking this I am getting the error on browser as

Uncaught Error: java.security.AccessControlException: access denied (java.io.FilePermission Uncaught Error: Error calling method on NPObject.


回答1:


Ok I got the answer myself: After refering to this link http://docs.oracle.com/javase/7/docs/api/java/security/AccessController.html , I figured out ,that reading,writing or even deleting can be done by wraping them up in AccessController.doPrivileged method.

AccessController.doPrivileged(new PrivilegedAction() {

                @Override
                public Object run() {
                    try {
                        deleteAppCacheDirectory();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    return null;
                }

            });



回答2:


You should remove the call to the destroy method from your javascript code. The destroy method is automatically called by the browser when the user leaves the page. The reason this is happening is probably because your destroy method is not public. This doesn't prevent the browser from calling it, however.



来源:https://stackoverflow.com/questions/18013636/deleting-files-from-signed-java-applet

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