繁体   English   中英

Applet签名抛出:java.security.AccessControlException。 如何运行?

[英]Applet signed throw: java.security.AccessControlException. How can I make it run?

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

Index.html

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

现在,当我将浏览器指向页面时,我在控制台上发现了以下消息:

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

您需要将连接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);
  }  

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM