-Djava.security.manager
command line argument.
To execute the GetProps
application with the default security manager, type the following:
java -Djava.security.manager GetProps
C:\TEST>java -Djava.security.manager GetProps About to get os.name property value The name of your operating system is: WindowsXP About to get java.version property value The version of the JVM you are running is: JDK 1.6.0 About to get user.home property value Caught exception java.security.AccessControlException: access denied (java.util.PropertyPermission user.home read)
The process is shown in the following figure.
"os.name"
and "java.version"
.
These properties are not
security-sensitive, so granting these permissions does not normally pose a security risk.
The other properties GetProps
tries to access,
"user.home"
and "java.home"
,
are not among the properties for which
the system policy file grants read permission. Thus as soon as
GetProps
attempts to access the first of these properties
("user.home"
),
the security manager prevents the access and reports an
AccessControlException
.
This exception indicates that the policy currently in
effect, which consists of entries in one or more policy files, doesn't allow
permission to read the "user.home"
property.
By default, the system policy file located at:
Windows: java.home\lib\security\java.policy UNIX: java.home/lib/security/java.policy
"java.home"
property, which is a system property specifying the
directory into which the JRE was installed.
Thus if the JRE was installed in the directory named C:\jdk\jre
on
Windows and /jdk/jre
on UNIX,
the system policy file is located at
Windows: C:\jdk\jre\lib\security\java.policy UNIX: /jdk/jre/lib/security/java.policy
Here is a copy of the default policy file.