Applet签名throw:java.security.AccessControlException。我该如何让它运行?

时间:2010-07-05 21:54:50

标签: java sockets ftp applet policy

经过几个小时的工作(我不是一个java程序员)我已经设法打包并放入一个小程序,它将ftp-upload上传到远程服务器。主文件是“invia.jar”中的“prova.class”;我使用第三部分库,放在“edtftpj.jar”中。我已经签署了这两个文件并将其包含在页面中,其中包含以下代码:

的index.html

<applet width="300" height="300"  classpath="./" code="prova.class" archive="invio.jar,edtftpj.jar"> </applet>

现在,当我将浏览器指向我的页面时,我在consolle上找到了这条消息:

Could not read property 'edtftp.log.level' due to security permissions
Could not read property 'edtftp.log.log4j' due to security permissions
Could not read property 'edtftp.log.log4j' due to security permissions
java.security.AccessControlException: access denied (java.net.SocketPermission www.artkiller-web.com resolve)
 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.checkConnect(Unknown Source)
 at sun.plugin2.applet.Applet2SecurityManager.checkConnect(Unknown Source)
 at java.net.InetAddress.getAllByName0(Unknown Source)
 at java.net.InetAddress.getAllByName(Unknown Source)
 at java.net.InetAddress.getAllByName(Unknown Source)
 at java.net.InetAddress.getByName(Unknown Source)
 at com.enterprisedt.net.ftp.FTPClient.connect(FTPClient.java:966)
 at com.enterprisedt.net.ftp.FileTransferClient.connect(FileTransferClient.java:386)
 at prova.start(prova.java:44)
 at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
 at java.lang.Thread.run(Unknown Source)

关于如何工作的任何想法 -

提前谢谢你

ArtoAle

1 个答案:

答案 0 :(得分:1)

您需要将连接URL包装在特权代码块中。

看起来您在从属性文件读取时遇到问题,您可以在jar中打包的属性文件,如果您尝试从客户端计算机读取属性文件,则需要将该代码包装在特权块中代码也是如此。

这是我用于通过访问控制器获取URL的另一个答案中使用的代码块。

 try 
 {
     final String imageURL = "http://www.google.com/intl/en_ALL/images/logo.gif";
     URL url = (URL) AccessController.doPrivileged(new PrivilegedAction() 
     {

         public Object run() 
         {
             try
             {
               return new URL(imageURL);
             }
             catch (MalformedURLException e)
             {
               e.printStackTrace();
               return null;
             }

        }  
      });  

     if(url == null)
     {
        // Something is wrong notify the user
     }
     else
     {
        // We know the url is good so continue on
         img = ImageIO.read(url);
     }

  } 
  catch (IOException e) 
  {
   System.out.println(e);
  }