0

I have a seemingly strange problem with the Java 8 Policy.

I used the following permission in Java 7 up to update 51 and it worked fine:

grant { 
    (...)
    java.net.SocketPermission "localhost:1024-", "accept,connect,listen,resolve";
};

But now I'm checking Java 8 Support, and i get this Exception:

Exception in thread "RMI TCP Connection(idle)" java.security.AccessControlException: access denied ("java.net.SocketPermission" "10.1.17.112:55703" "accept,resolve")
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at sun.plugin2.applet.AWTAppletSecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkAccept(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.checkAcceptPermission(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.checkAcceptPermission(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Running IPConfig shows me that 10.1.17.122 is the IP of my local machine:

   Ethernet adapter Local Area Connection:

   IPv4 Address. . . . . . . . . . . : 10.1.17.112
   Subnet Mask . . . . . . . . . . . : 255.255.252.0
   Default Gateway . . . . . . . . . : 10.1.19.254

If I change the permission to 127.0.0.1 it dosent work neither:

grant { 
    (...)
    java.net.SocketPermission "127.0.0.1:1024-", "accept,connect,listen,resolve";
};

BUT, if I enter my IP Address, all works fine again:

grant { 
    (...)
    java.net.SocketPermission "10.1.17.112:1024-", "accept,connect,listen,resolve";
};

Any ideas why?

Edit: For me it seems like a Bug in Java 8, can anyone confirm this?

Oli
  • 561
  • 7
  • 18
  • The only thing I can think of is that you are using `127.0.0.1` in your security file and `localhost` in your code. If the JVM checks the permissions *before* resolving the name, it might be the issue. – SJuan76 May 19 '14 at 07:15
  • @SJuan76 But I tried both in the java.policy, and both are causing the same error. – Oli May 19 '14 at 07:25

2 Answers2

2

"localhost" is 127.0.0.1. "10.1.17.112" is something else entirely. You're lucky it ever worked at all.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • I dont feel like this is an answer to my question, can you clarify? Im just using Localhost in the Code and in the Permission, but for some reason localhost gets translated into 10.1.17.112 (in java 7 and 8). In Java 7 this wasnt an issue, it got translated but as long as it was the ip of the local host it worked with java.net.SocketPermission "localhost:1024-"... – Oli May 19 '14 at 10:32
  • Sounds like you may have the dreaded Linux misconfiguration problem. Check your `etc/hosts` file. It should map "localhost" to 127.0.0.1, and your real hostname to a real IP address. It doesn't have anything to do with Java. The same problem can also show up in RMI stubs, hence the reason for the `java.rmi.server.hostname` feature. – user207421 Jun 05 '14 at 13:02
  • I'm on Windows my host file says: `127.0.0.1 localhost` and `::1 localhost` and when i try pinging localhost and 127.0.0.1 all works, so this shouldn't be the issue, also i've monitored this issue on more than one machine... – Oli Jun 05 '14 at 13:38
1

I think i found what i was looking for: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7077696

The suggested workaround there works for me.

2011-11-09 WORK AROUND

Run with -Djava.net.preferIPv4Stack=true

Thanks for your help!

Community
  • 1
  • 1
Oli
  • 561
  • 7
  • 18