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.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.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest