Java Applet AccessControlException

Post here all your questions related with SmartFoxServer Java API

Moderators: Lapo, Bax

DC Internet
Posts: 5
Joined: 08 Feb 2009, 03:38

Java Applet AccessControlException

Postby DC Internet » 17 Apr 2009, 19:11

I used the Java API to create a test applet that connects to SmartFox.

If I grant "permission java.security.AllPermission" in the java.policy file, it connects and works perfectly. However, with default permissions, where I make the sfs.connect(ip, socket) call I get...

java.security.AccessControlException: access denied (java.util.PropertyPermission org.xsocket.stream.UseDirectReadBufferClient read)

Code: Select all

Exception in thread "Thread-29" java.lang.ExceptionInInitializerError
   at org.xsocket.stream.Connection.<clinit>(Connection.java:77)
   at it.gotoandplay.utils.net.xmlsocket.XMLSocket.connect(XMLSocket.java:134)
   at it.gotoandplay.smartfoxclient.SmartFoxClient.connect(SmartFoxClient.java:1237)
   at com.biddle.biddlej2js.BiddleJ2JS$1ConnectClient.run(BiddleJ2JS.java:138)
   at java.lang.Thread.run(Unknown Source)
Caused by: java.security.AccessControlException: access denied (java.util.PropertyPermission org.xsocket.stream.UseDirectReadBufferClient read)
   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.checkPropertyAccess(Unknown Source)
   at java.lang.System.getProperty(Unknown Source)
   at org.xsocket.stream.io.impl.IoProvider.<clinit>(IoProvider.java:129)
   ... 5 more


I have tried signing the Applet, get the security dialog and that doesn't help. I've been searching Google for the past two days and nothing I try works.

Any ideas?
DC Internet
Posts: 5
Joined: 08 Feb 2009, 03:38

Postby DC Internet » 17 Apr 2009, 22:39

I should also add that I get this Exception under the same circumstances (only works when granting java.security.AllPermission in java.policy)...

Code: Select all

java.security.AccessControlException: access denied (java.util.logging.LoggingPermission control)
   at java.security.AccessControlContext.checkPermission(Unknown Source)
   at java.security.AccessController.checkPermission(Unknown Source)
   at java.lang.SecurityManager.checkPermission(Unknown Source)
   at java.util.logging.LogManager.checkAccess(Unknown Source)
   at java.util.logging.Logger.checkAccess(Unknown Source)
   at java.util.logging.Logger.setLevel(Unknown Source)
   at it.gotoandplay.smartfoxclient.SmartFoxClient.<init>(SmartFoxClient.java:670)
   at com.biddle.biddlej2js.BiddleJ2JS.init(BiddleJ2JS.java:42)
   at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)
Exception: java.security.AccessControlException: access denied (java.util.logging.LoggingPermission control)


I had disabled it to avoid the error and forgot it was there.

I've found that a signed applet doesn't throw the LoggingPermission exception; however, the original PropertyPermission exception is still thrown.
DC Internet
Posts: 5
Joined: 08 Feb 2009, 03:38

Postby DC Internet » 18 Apr 2009, 08:44

I entered this permission in my java.policy file...
permission java.util.PropertyPermission "org.xsocket.stream.*", "read,write";

Now I get this exception...

Code: Select all

network: Connecting http://XEON/crossdomain.xml with proxy=DIRECT
network: Connecting http://XEON:80/ with proxy=DIRECT
java.security.PrivilegedActionException: java.net.ConnectException: Connection refused: connect
   at java.security.AccessController.doPrivileged(Native Method)
   at com.sun.deploy.net.CrossDomainXML.check(Unknown Source)
   at com.sun.deploy.net.CrossDomainXML.check(Unknown Source)
   at sun.plugin2.applet.Applet2SecurityManager.checkConnect(Unknown Source)
   at java.net.InetAddress.getLocalHost(Unknown Source)
   at org.xsocket.stream.io.impl.IoProvider.<clinit>(IoProvider.java:166)
   at org.xsocket.stream.Connection.<clinit>(Connection.java:77)
   at it.gotoandplay.utils.net.xmlsocket.XMLSocket.connect(XMLSocket.java:134)
   at it.gotoandplay.smartfoxclient.SmartFoxClient.connect(SmartFoxClient.java:1237)
   at com.biddle.biddlej2js.BiddleJ2JS.connectServer(BiddleJ2JS.java:164)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at sun.plugin.javascript.JSInvoke.invoke(Unknown Source)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at sun.plugin.javascript.JSClassLoader.invoke(Unknown Source)
   at sun.plugin2.liveconnect.JavaClass$MethodInfo.invoke(Unknown Source)
   at sun.plugin2.liveconnect.JavaClass$MemberBundle.invoke(Unknown Source)
   at sun.plugin2.liveconnect.JavaClass.invoke0(Unknown Source)
   at sun.plugin2.liveconnect.JavaClass.invoke(Unknown Source)
   at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$DefaultInvocationDelegate.invoke(Unknown Source)
   at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$3.run(Unknown Source)
   at java.security.AccessController.doPrivileged(Native Method)
   at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo.doObjectOp(Unknown Source)
   at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$LiveConnectWorker.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)
Caused by: java.net.ConnectException: Connection refused: connect
   at java.net.PlainSocketImpl.socketConnect(Native Method)
   at java.net.PlainSocketImpl.doConnect(Unknown Source)
   at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
   at java.net.PlainSocketImpl.connect(Unknown Source)
   at java.net.SocksSocketImpl.connect(Unknown Source)
   at java.net.Socket.connect(Unknown Source)
   at sun.net.NetworkClient.doConnect(Unknown Source)
   at sun.net.www.http.HttpClient.openServer(Unknown Source)
   at sun.net.www.http.HttpClient.openServer(Unknown Source)
   at sun.net.www.http.HttpClient.<init>(Unknown Source)
   at sun.net.www.http.HttpClient.New(Unknown Source)
   at sun.net.www.http.HttpClient.New(Unknown Source)
   at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
   at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
   at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
   at com.sun.deploy.net.CrossDomainXML$2.run(Unknown Source)
   ... 30 more

XEON is the name of my local computer. Is the applet trying to load a crossdomain.xml file from the local computer?

Does anybody have the source files used here for org.xsocket?
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 20 Apr 2009, 11:50

No, that doesn't depend on xsocket, it depends on the security restrictions imposed by the JVM when running as an applet in the browser.

I don't have much experience with applets (thought they died back in 1999 or so :D ) so I am not to able to help here. I'd suggest to investigate in the JDK docs or post a question in the Sun Developer Forums ( http://forums.sun.com/ )
Lapo
--
gotoAndPlay()
...addicted to flash games
DC Internet
Posts: 5
Joined: 08 Feb 2009, 03:38

Postby DC Internet » 20 Apr 2009, 20:26

Applets are, to a degree, old news except in the world of open socket games. They are still used heavily.

My SmartFox-based game has a bad disconnect problem, a problem talked about in these forums.
viewtopic.php?t=2878
The "solution" is horrible and makes using open sockets no better (perhaps worse) than simple polling.

I don't think this has anything to do with SmartFox. I suspect that it's a server/firewall config problem or, highly likely, Flash handles sockets poorly.

I made a Java applet that connects to the server and communicates with my Flash game to see if the disconnect problem is with Flash.

I spent the weekend hacking away at this and have a working applet now.

I found that the security restriction was caused by net.n3.nanoxml. This is odd, since all it does is parse some XML. With it gone, I have no security issues.

On a related note, my game still uses AS2. Does anybody have any experience that suggests AS3 handles sockets better?
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 21 Apr 2009, 05:13

My SmartFox-based game has a bad disconnect problem, a problem talked about in these forums.
viewtopic.php?t=2878

What is the problem exactly? That post is very long and there are many posters.

On a related note, my game still uses AS2. Does anybody have any experience that suggests AS3 handles sockets better?

I wouldn't expect big differences.
However I wouldn't jump to conclusions too quickly. Flash sockets are from immaculate but we have never seen horrible things happening, maybe there's a way around it.
Let us know more details
Lapo

--

gotoAndPlay()

...addicted to flash games
DC Internet
Posts: 5
Joined: 08 Feb 2009, 03:38

Postby DC Internet » 21 Apr 2009, 17:14

Read soupman's posts from that thread. His comments are an accurate description of the problem.

I don't experience the disconnects, but I do have the Admin symptom where, if left idle for 10 minutes, it cannot refresh due to disconnection and leaves a ghost admin that I must force login away.

His solution is to have each player send a chat string that is suppressed by the players every n seconds. You can see how that can get exponentially expensive.

Our Smartfox runs under Windows Server 2003 on a dual-core XEON hosted at a co-lo with fat pipes. That server ONLY runs SmartFox. Smartfox has a gig of RAM allocated. Currently we have less than 200 concurrent users. I'm confident the disconnect problem is not resource related.

Some of our early feedback is hinting that connections are improving with the Java Applet. I'll post an update here when we have definitive results.

When I can, I'll set up a test server and start troubleshooting the disconnects from server end. I'll first tackle the hardware firewall.
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 22 Apr 2009, 06:15

Our Smartfox runs under Windows Server 2003 on a dual-core XEON hosted at a co-lo with fat pipes. That server ONLY runs SmartFox. Smartfox has a gig of RAM allocated. Currently we have less than 200 concurrent users. I'm confident the disconnect problem is not resource related.

Yes, I agree. Plus resource related disconnections are easy to spot by simply monitoring your bandwidth. The server itself is not going to drop connections just because it's running short on memory, in that case it would slow down and eventually crash (with an OOM) but that's another story.

I would definitely keep an eye on the number of outgoing dropped messages in the AdminTool. The same goes for the Server's message queues (again from the AdminTool): if you notice that they are always filled with messages it could be a problem with extension scalability.

Read more here as regards dropped messages:
http://www.smartfoxserver.com/docs/docP ... ooting.htm
("Understanding Dropped Messages" section)
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “Java2SE / Android Client API”

Who is online

Users browsing this forum: No registered users and 18 guests