JFileChooser use within JApplet

筅森魡賤 提交于 2019-12-04 07:25:40

This thread indicates that you need to digitally sign your applet before a JFileChooser is permitted.

As mentioned, you need to sign your applet, which result in a "vague security warning" when the user is presented the applet. When the user accept to run this applet, the applet is given full access and functions like an ordinary application with it's obvious security implications. I'm in the same dilemma regarding a web application I'm working on and is not yet sure if it'll get deployed.

You could alternatively use the built-in filebrowser in the webbrowser and bounce back the file-content from your server if you're working with smaller files.

Also, some security measures you can make regarding a signed applet are:

  • Validating the origin of the applet code.

    URL appletUrl = MyApplet.class.getProtectionDomain().getCodeSource().getLocation();
    if(appletUrl.toString().equalsIgnoreCase(safeAppletUrl) == false)
       return false;
    
  • Verifying the base URL from which the applet was run.

    URL documentUrl = this.getDocumentBase(); 
    if(documentUrl.toString().equalsIgnoreCase(safeDocumentUrl) == false)
       return false;
    

In that case (of using default settings), you're correct, the default security manager does not allow access to local files.

You will probably have to use PrivilegedAction to read anything from the user's hard drive. Just as @mmyers said you'll have to sign your applet as well.

So your answer is yes, I've done this before so I know it can be done.

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