Java 小程序无法在 Safari 7 (Mac OS X 10.9) 下打开文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19542427/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java applet can't open files under Safari 7 (Mac OS X 10.9)
提问by JetLizard
We have a web app that uses Java applet to manipulate files on local disk. We develop it for quite a while and we already know all types with issues an applet may have with modern OS'es and browsers and latest Java versions and new security restrictions.
我们有一个 Web 应用程序,它使用 Java 小程序来操作本地磁盘上的文件。我们开发它已经有一段时间了,我们已经知道小程序在现代操作系统和浏览器以及最新的 Java 版本和新的安全限制中可能存在的所有类型的问题。
Yesterday Apple rolled out its new Mac OS 10.9 Mavericks with new Safari browser (7.0). I tested our web app under Safari 7 / Mac OS X 10.9 just to find that Safari 7 (probably?) blocks access to local files from Java applet.
昨天,Apple 推出了带有新 Safari 浏览器 (7.0) 的新 Mac OS 10.9 Mavericks。我在 Safari 7 / Mac OS X 10.9 下测试了我们的网络应用程序,只是为了发现 Safari 7(可能?)阻止从 Java 小程序访问本地文件。
Although the applet (signed with valid Thawte certificate, and with all security requirements specific to Java 7u45 fulfilled) runs in unrestricted mode with full access to local file system (Java security prompt says that), on attempt to access the local file it catches fileNotFoundException:
尽管小程序(使用有效的 Thawte 证书签名,并且满足特定于 Java 7u45 的所有安全要求)在不受限制的模式下运行,并具有对本地文件系统的完全访问权限(Java 安全提示说明了这一点),但在尝试访问本地文件时它会捕获 fileNotFoundException :
java.io.FileNotFoundException: /Users/yury/Pictures/Paris 2012/L1050258.jpg (Operation not permitted)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at com.trackntag.a.v.a(Unknown Source)
Also when opening Java file open dialog from the applet, it displays no files and the folders in the folder selector do not have any icons (normally they should have them). When you traverse back to the root folder, you can see top level folders (bin, cores, dev, home, and so on), but you cannot browse into them.
此外,当从小程序打开 Java 文件打开对话框时,它不显示任何文件,并且文件夹选择器中的文件夹没有任何图标(通常应该有它们)。当您遍历回根文件夹时,您可以看到顶级文件夹(bin、cores、dev、home 等),但无法浏览到它们。
The applet does have an access to local files with latest Firefox 24 for Mac, on the same machine (Java 7u45, Mac OS X 10.9). Same with Safari 6 and Mac OS X 10.8.5, not to mention Linux and Windows machines in various configurations: no issues with accessing local files.
小程序确实可以在同一台机器(Java 7u45,Mac OS X 10.9)上使用最新的 Firefox 24 for Mac 访问本地文件。与 Safari 6 和 Mac OS X 10.8.5 相同,更不用说各种配置的 Linux 和 Windows 机器:访问本地文件没有问题。
Having all of above, I must conclude that we have ran into the problem specific to Safari 7.
综上所述,我必须得出结论,我们遇到了 Safari 7 特有的问题。
Do you have any ideas on this issue? Any thoughts are greatly appreciated.
你对这个问题有什么想法吗?任何想法都非常感谢。
Cheers, Yury
干杯,尤里
EDIT (Answer): In Safari 7 there is a new security setting: Safe/Unsafe mode (I think it's for Java plug-in only). You can allow Java plugin to work in Unsafe mode either for individual websites or for all sites. In Unsafe mode the applets will have unrestricted access to local file system.
编辑(答案):在 Safari 7 中有一个新的安全设置:安全/不安全模式(我认为它仅适用于 Java 插件)。您可以允许 Java 插件在不安全模式下为单个网站或所有网站工作。在不安全模式下,applet 将可以不受限制地访问本地文件系统。
It appears that this security setting works on top of Java's own security settings (restricted/unrestricted access).
看来这个安全设置是在 Java 自己的安全设置(受限/无限制访问)之上工作的。
This setting is available through Safari preferences / Security tab / Internet plugins: manage website settings (then select Java plugin).
此设置可通过 Safari 首选项/安全选项卡/互联网插件获得:管理网站设置(然后选择 Java 插件)。
So once I already answered my own original question, I would rather rephrase it: is that possible to set Unsafe mode or override Safe mode for specific web-site / URL without asking user to set this security preference? Maybe something like Apple developer certificate would help?
因此,一旦我已经回答了我自己的原始问题,我宁愿改写它:是否可以在不要求用户设置此安全首选项的情况下为特定网站/URL 设置不安全模式或覆盖安全模式?也许像Apple开发人员证书之类的东西会有所帮助?
Thanks again!
再次感谢!
回答by Paul R
I had a similar problem with another Java app today. I think you may need to add your app to the "Allow the apps below ..." list in this dialog (System Prefs -> Security & Privacy -> Accessibility
):
我今天在另一个 Java 应用程序上遇到了类似的问题。我认为您可能需要将您的应用添加到此对话框中的“允许下面的应用...”列表 ( System Prefs -> Security & Privacy -> Accessibility
):
回答by fycth
For Safari 11:
对于 Safari 11:
- go to Safari Preferences->Websites->Plug-ins, and select Java
- at the right side you can see list of 'Allow websites to use this plug-in with settings below'
- now select the website
- press and hold Option button and then click the three option (Ask, Off, On), you will see additional option 'Run in safe mode' - un-check this option.
- 转到 Safari Preferences->Websites->Plug-ins,然后选择 Java
- 在右侧,您可以看到“允许网站在下面的设置中使用此插件”列表
- 现在选择网站
- 按住 Option 按钮,然后单击三个选项(询问、关闭、打开),您将看到附加选项“以安全模式运行” - 取消选中此选项。