15.3 Security Architecture and Security Policy The Java platform builds a security architecture on top of the protections promised by the JVM. A security architecture is a way of organizing the software that makes up the Java platform so that potentially harmful operations are isolated from unprivileged code but available to privileged code. Most code is unprivileged; only carefully selected pieces of code are privileged to perform potentially dangerous operations. The security architecture is responsible for making sure that unprivileged code does not masquerade as privileged code. The core of the Java platform security architecture under Java platforms 1.0 and 1.1 is the SecurityManager class. This class decides which pieces of code can perform certain operations and which cannot. Collectively, these decisions are called the security policy . The security policy is enforced by the Java platform classes, which check the SecurityManager before proceeding with any operations under the control of the SecurityManager. [1] On the Java 2 platform, the core of the security architecture is shifted to a class called AccessController, which falls outside the scope of this book. See http//java.sun.com for more information. Only one instance of the SecurityManager can be installed, and once it is installed it cannot be removed. It is called the security manager . By default, there is no security manager, and all operations are permitted. The class java.lang.System is responsible for ensuring that there is only one security manager. It provides the static methods getSecurityManager and setSecurityManager to get and set the security manager. The SecurityManager class has a set of methods that are called by the Java platform code before proceeding with certain potentially harmful operations. These methods throw a SecurityException if the operation is forbidden. If no exception is thrown, then the caller may assume that the operation is permitted, and it can proceed with the operation. describes the operations that are checked by the SecurityManager in the Java 1.02 platform. The security manager uses a variety of factors to determine whether an operation is permitted or not. These factors include the source of the code attempting the operation and the preferences of the user (discussed further in ). First we present an example of how the security architecture and the security policy interact. Table 15.1. Security checks Method | Operation checked | Called by |
---|
checkAccept (String host, int port) | Accepting a socket connection from host on port | ServerSocket.accept | checkAccess (Thread g) | Modifying the thread g | Thread.stop Thread.suspend Thread.resume Thread.setPriority Thread.setName Thread.setDaemon | checkAccess (ThreadGroup g) | Modifying the thread group g | ThreadGroup. ThreadGroup.setDaemon ThreadGroup.setMaxPriority ThreadGroup.stop ThreadGroup.resume ThreadGroup.destroy | checkConnect (String host, int port) | Opening a socket to host on port | Socket.connect | checkCreateClassLoader() | Creating a class loader | ClassLoader. | checkDelete(String file) | Deleting a file | File.delete | checkExec(String cmd) | Creating a subprocess | Runtime.exec | checkExit(int status) | Exiting the JVM | Runtime.exit | checkLink(String lib) | Loading a library | Runtime.load Runtime.loadLibrary | checkListen(int port) | Listening at a port | Socket.listen | checkPackageAccess (String package) | Attempting to access package | ClassLoader.loadClass | checkPackageDefinition (String package) | Defining a class in package | ClassLoader.loadClass | checkPropertiesAccess() | Reading or writing properties | System.getProperties System.setProperties | checkPropertyAccess (String property) | Reading the property named property | System.getProperty | checkRead (FileDescriptor fd) | Reading from the file descriptor fd | FileInputStream. | checkRead(String file) | Reading from the file named file | FileInputStream. | checkSetFactory() | Setting a socket factory | ServerSocket SetSocketFactory | checkWrite (FileDescriptor fd) | Writing to a file descriptor | FileOutputStream. | checkWrite(String f) | Writing to a file named file | FileOutputStream. |
15.3.1 Example |