列出已签名小程序的本地目录

发布于 2024-07-23 05:04:40 字数 3520 浏览 2 评论 0 原文

以下小程序被编译并打包到 jar 中,然后使用自签名证书进行签名。

import java.applet.Applet;
import java.io.File;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;

public class Test extends Applet {
        private static final long serialVersionUID = -3127185193501384816L;

        private final class DirectoryLister implements PrivilegedAction<File[]> {
                private final String attachmentsFolder;

                private DirectoryLister(String attachmentsFolder) {
                        this.attachmentsFolder = attachmentsFolder;
                }

                public File[] run() {
                        return new File(attachmentsFolder).listFiles();
                }
        }

        public File[] getFiles() throws PrivilegedActionException {
                String attachmentsFolder = getParameter("attachmentsFolder");

                if (attachmentsFolder != null) {
                        return AccessController.doPrivileged(new DirectoryLister(
                                        attachmentsFolder));
                }

                return null;
        }
}

Applet 实例化如下:

<applet id="applet"
    code="Test"
    archive="applet.jar">
    <param name="attachmentsFolder"
        value="c:/test" />
</applet>

Applet 使用如下:

var files = applet.getFiles();

for (var file in files) {
    // Do something to file.
}

ff。 遇到错误:

java.security.PrivilegedActionException: java.lang.reflect.InvocationTargetException
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.plugin.liveconnect.SecureInvocation$2.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.plugin.liveconnect.SecureInvocation.CallMethod(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at sun.plugin.javascript.JSInvoke.invoke(Unknown Source)
        at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at sun.plugin.javascript.JSClassLoader.invoke(Unknown Source)
        at sun.plugin.liveconnect.PrivilegedCallMethodAction.run(Unknown Source)
        ... 4 more
Caused by: java.security.AccessControlException: access denied (java.io.FilePermission c:\test read)
        at java.security.AccessControlContext.checkPermission(Unknown Source)
        at java.security.AccessController.checkPermission(Unknown Source)
        at java.lang.SecurityManager.checkPermission(Unknown Source)
        at java.lang.SecurityManager.checkRead(Unknown Source)
        at java.io.File.list(Unknown Source)
        at java.io.File.listFiles(Unknown Source)
        at Test$DirectoryLister.run(Test.java:20)
        at Test$DirectoryLister.run(Test.java:1)
        at java.security.AccessController.doPrivileged(Native Method)
        at Test.getFiles(Test.java:28)
        ... 14 more

这导致我询问是否仍然需要在 Java 主目录中的配置文件之一中显式授予权限才能读取 c:/test? 如果是这样,有人能给我指点如何执行此操作的指南吗?

The following applet is compiled and packed into jar which is then signed with a self-signed cert.

import java.applet.Applet;
import java.io.File;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;

public class Test extends Applet {
        private static final long serialVersionUID = -3127185193501384816L;

        private final class DirectoryLister implements PrivilegedAction<File[]> {
                private final String attachmentsFolder;

                private DirectoryLister(String attachmentsFolder) {
                        this.attachmentsFolder = attachmentsFolder;
                }

                public File[] run() {
                        return new File(attachmentsFolder).listFiles();
                }
        }

        public File[] getFiles() throws PrivilegedActionException {
                String attachmentsFolder = getParameter("attachmentsFolder");

                if (attachmentsFolder != null) {
                        return AccessController.doPrivileged(new DirectoryLister(
                                        attachmentsFolder));
                }

                return null;
        }
}

Applet is instantiated as follows:

<applet id="applet"
    code="Test"
    archive="applet.jar">
    <param name="attachmentsFolder"
        value="c:/test" />
</applet>

Applet is used as follows:

var files = applet.getFiles();

for (var file in files) {
    // Do something to file.
}

The ff. error is encountered:

java.security.PrivilegedActionException: java.lang.reflect.InvocationTargetException
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.plugin.liveconnect.SecureInvocation$2.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.plugin.liveconnect.SecureInvocation.CallMethod(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at sun.plugin.javascript.JSInvoke.invoke(Unknown Source)
        at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at sun.plugin.javascript.JSClassLoader.invoke(Unknown Source)
        at sun.plugin.liveconnect.PrivilegedCallMethodAction.run(Unknown Source)
        ... 4 more
Caused by: java.security.AccessControlException: access denied (java.io.FilePermission c:\test read)
        at java.security.AccessControlContext.checkPermission(Unknown Source)
        at java.security.AccessController.checkPermission(Unknown Source)
        at java.lang.SecurityManager.checkPermission(Unknown Source)
        at java.lang.SecurityManager.checkRead(Unknown Source)
        at java.io.File.list(Unknown Source)
        at java.io.File.listFiles(Unknown Source)
        at Test$DirectoryLister.run(Test.java:20)
        at Test$DirectoryLister.run(Test.java:1)
        at java.security.AccessController.doPrivileged(Native Method)
        at Test.getFiles(Test.java:28)
        ... 14 more

Which leads me to ask if I still need to explicitly grant perms in one of the config files in the Java home directory to read c:/test? If so, can anyone point me to a guide on how to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只涨不跌 2024-07-30 05:04:40

显然是缓存问题。 清除所有缓存并重新构建/重新部署解决了问题。 即,不需要额外的权限设置。

Caching problem apparently. Clearing all caches and re-building/re-deploying solved the problem. I.e., no additional perms set-up needed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文