Property permissions The Types of Permissions

20.2.1.4 Property permissions

The final type of permissions that we will discuss are property permissions. The System class, defined in the java.lang package, has a static reference to the singleton properties object, which you can obtain by calling System.getProperties . This properties object is an instance of java.util.Properties . This object contains two things: a set of canonical name-value pairs that specify information about the JVM and all the command-line properties set by the -D flag. Many people like to think of the systems properties object as being analogous to the environment variables in a command shell. Recall that our application in Chapt er 18 was invoked using the command line: java -Dcom.ora.rmibook.useMonitoringSockets=false ... This created a property in the system properties object named c om.ora.rmibook.useMonitoringSockets and set the value of the property to the string as false . Properties are usually named using a dotted notation consisting of a group name followed by a single period and then a descriptive name. For example, the canonical system properties contain properties named user.name , user.home , and user.dir . By default, a class cannot read or set system properties. However, the read and write property permissions are used to remedy this. Properties are specified in one of three ways: As a single asterisk By itself, is a wildcard that means all properties. As an ordinary string A property permission can be set for an individual property by giving the complete name of the property. As a string followed by a dotted asterisk Names of the form groupname. match all properties that begin with groupname . Here are some typical properties permissions, granting every class the ability to read but not change certain canonical properties: grant { permission java.util.PropertyPermission java.version, read; permission java.util.PropertyPermission java.vendor, read; permission java.util.PropertyPermission java.vendor.url, read; permission java.util.PropertyPermission java.class.version, read; }

20.3 Security Managers