|
|
|
|||
|
Introducing the Security ManagerEach Java application can have its own security manager object that acts as a full-time security guard. The SecurityManager class in the java.lang package is an abstract class that provides the programming interface and partial implementation for all Java security managers.By default an application does not have a security manager. That is, the Java runtime system does not automatically create a security manager for every Java application. So by default an application allows all operations that are subject to security restrictions. To change this default lenient behavior, an application must create and install its own security manager. You will learn how to create a security manager in Writing a Security Manager, and how to install it in Installing Your Security Manager.
You can get the current security manager for an application using
the System class's Note thatSecurityManager appsm = System.getSecurityManager(); getSecurityManager() returns null if there
is no current security manager for the application so you should check
to make sure that you have a valid object before calling any of its
methods.
Once you have the security manager, you can request permission to allow
or disallow certain operations. Indeed many of the classes in the Java
packages do just this. For example, the
If the security manager approves the exit operation, the
checkExit() returns normally.
If the security manager disallows the operation,
the checkExit() method throws a SecurityException.
In this manner, the security manager allows or disallows
a potentially threatening operation before it can be completed.
The SecurityManager class defines many other methods used to verify
other kinds of operations. For example, SecurityManager's
In addition, the set of | |||
|