The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.security  [30 examples] > Permissions  [7 examples]

e212. Enabling the Security Manager

By default, no security manager is enabled which means that all security checks to protected resources and operations are disabled. To enable security checks, the security manager must be enabled.

Once enabled, policy files determine the type of access an entity has on a resource. For more details, see e220 Managing Policy Files.

This example enables the security manager.

    // Before the security manager is enabled, this call is possible
    System.setProperty("java.version", "malicious data");
    
    try {
        // Enable the security manager
        SecurityManager sm = new SecurityManager();
        System.setSecurityManager(sm);
    } catch (SecurityException se) {
        // SecurityManager already set
    }
    
    // This call is no longer possible; an AccessControlException is thrown
    System.setProperty("java.version", "malicious data");
The security manager can also be installed from the command line:
    > java -Djava.security.manager MyApp

 Related Examples
e213. Checking Read/Write Permission for a Directory
e214. Determining If One Permission Implies Another
e215. Creating a Custom Permission
e216. Controlling Access to an Object
e217. Listing All Permissions Granted to a Loaded Class
e218. Listing All Permissions Granted to Classes Loaded from a URL or Directory

See also: Key Store    Message Digests    Policy Files    Public and Private Keys    Signatures   


© 2002 Addison-Wesley.