Using Eclipse Kepler (Windows 7) for a project which opens a ServerSocket on localhost
, port 80
.
I use a security manager with a policy file located at:
C:\Users\John\Developpement\workspace\security\my.policy
In Eclipse, for the project launch configuration properties, for VM arguments:
-Djava.security.manager
-Djava.security.policy=${workspace_loc}/security/my.policy
The bin file executed is (I use separate source and output folders in Eclipse):
C:\Users\John\Developpement\workspace\SocketApps\bin\TinyHttpd.class
In my.policy
:
grant codeBase "file:\C:\Users\John\Developpement\workspace\SocketApps\bin\-" {
permission java.net.SocketPermission "localhost:80", "listen,resolve";
};
When running from Eclipse:
Exception in thread "main" java.security.AccessControlException: access denied ("java.net.SocketPermission" "localhost:80" "listen,resolve")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:372)
at java.security.AccessController.checkPermission(AccessController.java:559)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.SecurityManager.checkListen(SecurityManager.java:1134)
at java.net.ServerSocket.bind(ServerSocket.java:375)
at java.net.ServerSocket.<init>(ServerSocket.java:237)
at java.net.ServerSocket.<init>(ServerSocket.java:128)
at TinyHttpd.main(TinyHttpd.java:35)
when reaching code:
ServerSocket ss = new ServerSocket(80));
If I remove the codeBase
filter:
grant {
permission java.net.SocketPermission "localhost:80", "listen,resolve";
};
the problem disappears, so I imagine this is the way the codeBase
is expressed that is wrong.
I've tried the solution proposed for this question, but it doesn't work. Can you help me?