1

I am creating a socket connection with an unsigned applet to a different host and I'm getting java.security.AccessControlException: access denied

If I sign this applet with either "self-cert" or "CA cert" does the applet gain the permissions to create a socket connection to a different host (not the same host it was downloaded from) and does a security message popup if its been certified by a CA?

Thanks

4

2 回答 2

4

如果您不签署小程序,访问本地资源的代码将不会以任何方式执行。

如果您使用自我证书签署小程序,最终用户只会收到一条请求许可的警告消息。但是,您仍然需要将调用包装在AccessController#doPrivileged().

public void init() {
    AccessController.doPrivileged(new PrivilegedAction<Object> {
        @Override public Object run() {
            // Put your original init() here.
            return null;
        }
    });
}

如果您使用 $$$ 证书签署小程序,最终用户将不会收到警告消息。

于 2010-07-20T16:09:58.713 回答
0

您应该看到证书的相应对话框,除非禁用或始终接受该证书。只有在用户同意的情况下,代码才会被授予完全权限。

更好的方法是坚持仅连接到同源主机。

于 2010-07-20T16:12:05.547 回答