使用applet遇到java.security.AccessControlException异常

时间:2021-01-25 20:29:14

 

今天写一个使用jta(Telnet/SSH for the JAVA) applet例子, 遇到Socket: can't connect: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:23 connect,resolve)。

 

例子jtaAppletView.html 内容为:

<html>
  <body>
    <applet CODEBASE="."
            ARCHIVE="jta26.jar"
            CODE="de.mud.jta.Applet"
            WIDTH=590 HEIGHT=360>
            <param name="Socket.port" value="23">
            <param name="Socket.host" value="127.0.0.1">
    </applet>
  </body>
</html>

 

解决方法:

在jre的lib/security/java.policy中的default permissions grant 增加一行permission java.net.SocketPermission "*", "accept, connect, listen, resolve";

 

部分内容如下:


// Standard extensions get all permissions by default

grant codeBase "file:${{java.ext.dirs}}/*" {
    permission java.security.AllPermission;
};

// default permissions granted to all domains

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

    .......


};

 

学习参考:

http://www.cs.fit.edu/~ryan/java/language/security.html http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/security/index.html