java.security.manager property 

Joined:
04/09/2007
Posts:
776

July 08, 2011 09:37:03    Last update: July 08, 2011 09:37:03
A security manager is automatically installed when you run an applet, but not so when you run an application. Setting the java.security.manager property enables the default Security Manager for the application.

For example, you can bind to a "privileged" port without security manager:
$ java SocketBind localhost:83
Binding to localhost:83
success


With security manager, it fails:
$ java -Djava.security.manager SocketBind localhost:83
Binding to localhost:83
Exception in thread "main" java.security.AccessControlException: access denied (java.net.SocketPermission localhost:83 listen,resolve)
        at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
        at java.security.AccessController.checkPermission(AccessController.java:546)
        at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
        at java.lang.SecurityManager.checkListen(SecurityManager.java:1120)
        at java.net.ServerSocket.bind(ServerSocket.java:318)
        at java.net.ServerSocket.bind(ServerSocket.java:277)
        at SocketBind.main(SocketBind.java:24)
Share |
| Comment  | Tags