applet访问控制问题

时间:2011-09-12 07:56:53

标签: security applet

我有applet,而applet又连接到服务器进行文件写入。当我尝试使用localhost连接到服务器时: 它可以在我的机器上运行(服务器在同一台机器上),但不能在其他机器上运行。

当我尝试使用IP地址时,它无法正常工作

我的applet代码:

public class dynamicTreeApplet extends JPrefuseApplet {

    private static final long serialVersionUID = 1L;
    public static int i = 1;
    public String dieasenameencode;
    public void init() {

        System.out.println("the value of i is " + i);
        URL url = null;
        //Here dieasesname is important to make the page refresh happen 

        //String dencode = dieasenameencode.trim();
        try {
            //String dieasename = URLEncoder.encode(dencode, "UTF-8");
            // i want this piece of the code to be called 
            url = new URL("http://localhost:8080/docRuleTool/appletRefreshAction.do?dieasename=");
            URLConnection con = url.openConnection();
            con.setDoOutput(true);
            con.setDoInput(true);
            con.setUseCaches(false);
            InputStream ois = con.getInputStream();
            this.setContentPane(dynamicView.demo(ois, "name"));
            ois.close();

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (FileNotFoundException f) {
            f.printStackTrace();

        } catch (IOException io) {
            io.printStackTrace();
        }
        ++i;
    }

}

java policy file:

grant {
  permission java.net.SocketPermission "*", "accept";
  permission java.net.SocketPermission "*", "connect";
};

我的罐子没有签名,我也不希望他们从维护角度签名。

1 个答案:

答案 0 :(得分:3)

  

它可以在我的机器上运行(服务器在同一台机器上),但不能在其他机器上运行

是的,但实际上只有从“其他机器”提供的applet才能回写到另一台机器才有意义。上面的代码有..

url = new URL("http://localhost:8080/docRuleTool/appletRefreshAction.do?dieasename=");

这意味着来自其他主机的applet正在尝试将数据写回可能不存在的“localhost”。相反,您的applet应该使用更多类似的东西来形成URL。

url = new URL(getDocumentBase(), "/docRuleTool/appletRefreshAction.do?dieasename=");

如果代码执行此操作,则应该能够保持沙盒状态。


另外,策略文件实际上仅用于开发目的。如果代码需要对实际部署进行信任,则需要对其进行数字签名。