Write to a local file through JNLP

时光毁灭记忆、已成空白 提交于 2019-12-08 05:41:57

问题


I have a specific requirement to read a resource from jar file and then write it to local disk. But when I try to write that resource to local disk an exception:

java.io.FilePermission (write) is raised.

I have my jar signed. I have also tried the following solution but it does not work either.

AccessController.doPrivileged(new PrivilegedAction() 

Nothing seems to work.

Am I missing a step after signing jar because this is the most common solution available everywhere?

How can I write to a local file without using policy files (because that can't be done on each client machine)?


回答1:


The JNLP also needs to specify:

<security>
    <all-permissions/>
</security>

See the JNLP File Syntax for details.


I would generally use the FileSaveService as detailed in Tom's answer, but this sounds more like a situation where the 'file' could be a default properties file for configuring the app. The save service is not well suited to that, since the app. has no way to know where the file is stored, or how to access it later. For security reasons, the FileContents object that is provided in place of a File has no methods that return the path.

In that case, extract the details of the config. file & store them using the PersistenceService of the JNLP API. Here is a demo. of the PersistenceService. This service is also available to sand-boxed apps. (no code signing voodoo).




回答2:


You can save a file, with user interaction, from an unsigned WebStart application using javax.jnlp.FileSaveService.

Possibly a piece you are missing is marking the aplication as secure in the JNLP file. However, writing a secure application is a little tricky, and I wouldn't recommend it.



来源:https://stackoverflow.com/questions/11023018/write-to-a-local-file-through-jnlp

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