0

Understanding Java Security Manager in 5 minutes or less

General Idea

The general idea of Java Security Manager is to restrict what an application can do. This is important as it provides a separate environment for programs to do whatever they do without affecting the host system or other applications.

For instance, we only allow application MyApp to read and write files in some directory.

Here are some useful links:

Through the Security Manager, the applications are controlled with security policies ( .policy files).

Consider this source code file.

Running Java without Security Manager

Run your application from the command line prompt as follows.

Outputs

Running Java with Security Manager

Now run it with -D option.

Outputs

Since we did not specify a .policy file, Java uses a default .policy file.

Karl San Gabriel

Karl San Gabriel

Java and Enterprise Technologies Expert