Java Security Manager: How to Specify "No Permission"?
The Java Security Manager Allows to Specify the Permissions of Some Piece of Code by Defining Clauses Like: .. . Grant Codebase { Permission Java. Io...
The Java Security Manager allows to specify the permissions of some piece of code by defining clauses like:
...
grant codebase {
permission java.io.FilePermission "${user.dir}/*", "read,write"; };
...
in a policy file (default: <JRE_root>\lib\security.
This grants code stemming from the given URL to read and write from/to the user's home directory (which is of course a no-no but that's another story).
But how do I define "NO permission", i.e. if that piece of code should NOT be allowed to read or write anywhere? I tried to specify:
...
permission java.io.FilePermission "/-", "";
...
"/-" means the root directory and everything below it (i.e. everything) and the second argument "" was meant to signal "". But when I specify this like above I get a "token error". Apparently "" is not a valid "action". But how else does one then express "nothing" or "no permission" in these policy files?
1 Answer
Simply don't add any permissions lines. Classes will typically be given permissions to read their own code and resources. (See the API docs for java.io.FilePermission.)