Question

I am attempting to connect to an SQL database using a JApplet. However, I get a SecurityException:

com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: 

** BEGIN NESTED EXCEPTION ** 

java.net.SocketException
MESSAGE: java.security.AccessControlException: access denied ("java.net.SocketPermission" "162.243.229.150:3306" "connect,resolve")

STACKTRACE:

java.net.SocketException: java.security.AccessControlException: access denied ("java.net.SocketPermission" "162.243.229.150:3306" "connect,resolve")
    at com.mysql.jdbc.StandardSocketFactory.unwrapExceptionToProperClassAndThrowIt(StandardSocketFactory.java:407)
    at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:268)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:271)
    at com.mysql.jdbc.Connection.createNewIO(Connection.java:2771)
    at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:270)
    at me.nrubin29.cubesorter.MySQL.setup(MySQL.java:24)
    at me.nrubin29.cubesorter.MySQL.access$100(MySQL.java:8)
    at me.nrubin29.cubesorter.MySQL$1.run(MySQL.java:35)
    at java.lang.Thread.run(Thread.java:744)


** END NESTED EXCEPTION **



Last packet sent to the server was 1 ms ago.
    at com.mysql.jdbc.Connection.createNewIO(Connection.java:2847)
    at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:270)
    at me.nrubin29.cubesorter.MySQL.setup(MySQL.java:24)
    at me.nrubin29.cubesorter.MySQL.access$100(MySQL.java:8)
    at me.nrubin29.cubesorter.MySQL$1.run(MySQL.java:35)
    at java.lang.Thread.run(Thread.java:744)
Exception in thread "Thread-38" java.lang.NullPointerException
    at me.nrubin29.cubesorter.MySQL$1.run(MySQL.java:38)
    at java.lang.Thread.run(Thread.java:744)

I have tried using AccessController#doPrivileged, but that didn't help. How do I grant permission to use a socket with my applet?

Was it helpful?

Solution 2

Unsigned Applets have a number of restrictions applied to them. One of the restrictions is that they can't open network connections to hosts other than the one hosting the applet.

There are a few ways around this:

  1. Sign the applet. The obvious problem with this is that you need an application signing certificate.
  2. Host the DB server on the same machine as the applet.
  3. Write a WebStart application instead (although it probably has the same problem).

OTHER TIPS

See these:

java.net.SocketPermission in Applet

Can signed applets connect with a different host from which they originate?

If your applet is not signed, you need to make sure your applet
is loaded from the server to which it is trying to open a socket.
Then this will work.

This is a new breakage in java 8 - it appears that sandboxed applets are not allowed to use sockets at all.

A partial solution is to change the applet to request all-permissions. This changes the scary dialogs the user has to click through a little, but not much more ominous than he already has to.

-- and of course, due to previous security calisthenics, the jars have to be signed using a trusted certificate.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top