SecurityManager

Name

SecurityManager

Synopsis

Description

The SecurityManager class provides a way of implementing a comprehensive security policy for a Java program. As of this writing, SecurityManager objects are used primarily by Web browsers to establish security policies for applets. However, the use of a SecurityManager object is appropriate in any situation where a hosting environment wants to limit the actions of hosted programs.

The SecurityManager class contains methods that are called by methods in other classes to ask for permission to do something that can affect the security of the system. These permission methods all have names that begin with check. If a check method does not permit an action, it throws a SecurityException or returns a value that indicates the lack of permission. The SecurityManager class provides default implementations of all of the check methods. These default implementations are the most restrictive possible implementations; they simply deny permission to do anything that can affect the security of the system.

The SecurityManager class is an abstract class. A hosting environment should define a subclass of SecurityManager that implements an appropriate security policy. To give the subclass of SecurityManager control over security, the hosting environment creates an instance of the class and installs it by passing it to the setSecurityManager() method of the System class. Once a SecurityManager object is installed, it cannot be changed. If the setSecurityManager() method is called any additional times, it throws a SecurityException.

The methods in other classes that want to ask the SecurityManager for permission to do something are able to access the SecurityManager object by calling the getSecurityManager() method of the System class. This method returns the SecurityManager object, or null to indicate that there is no SecurityManager installed.

Class Summary

public abstract class java.lang.SecurityManager extends java.lang.Object {
 // Constructors protected SecurityManager(); // Variables protected boolean inCheck; // Instance Methods public void checkAccept(String host, int port);
public void checkAccess(Thread t);
public void checkAccess(ThreadGroup g);
public void checkAwtEventQueueAccess(); // New in 1.1 public void checkConnect(String host, int port);
public void checkConnect(String host, int port, Object context);
public void checkCreateClassLoader();
public void checkDelete(String file);
public void checkExec(String cmd);
public void checkExit(int status);
public void checkLink(String libname);
public void checkListen(int port);
public void checkMemberAccess(Class clazz, int which); // New in 1.1 public void checkMulticast(InetAddress maddr); // New in 1.1 public void checkMulticast(InetAddress maddr, byte ttl); // New in 1.1 public void checkPackageAccess();
public void checkPackageDefinition();
public void checkPrintJobAccess(); // New in 1.1 public void checkPropertiesAccess();
public void checkPropertyAccess(String key);
public void checkRead(int fd);
public void checkRead(String file);
public void checkRead(String file, Object context);
public void checkSecurityAccess(String action); // New in 1.1 public void checkSetFactory();
public void checkSystemClipboardAccess(); // New in 1.1 public boolean checkTopLevelWindow();
public void checkWrite(int fd);
public void checkWrite(String file);
public boolean getInCheck();
public Object getSecurityContext();
public ThreadGroup getThreadGroup(); // New in 1.1 // Protected Instance Methods protected int classDepth(String name); protected int classLoaderDepth(); protected ClassLoader currentClassLoader(); protected Class currentLoadedClass(); // New in 1.1 protected Class[] getClassContext(); protected boolean inClass(String name); protected boolean inClassLoader();
}

Variables

inCheck

protected boolean inCheck = false

Constructors

SecurityManager

protected SecurityManager()

Public Instance Methods

checkAccept

public void checkAccept(String host, int port)

checkAccess

public void checkAccess(Thread g)

public void checkAccess(ThreadGroup g)

checkAwtEventQueueAccess

public void checkAwtEventQueueAccess()

checkConnect

public void checkConnect(String host, int port)

public void checkConnect(String host, int port, Object context) 

checkCreateClassLoader

public void checkCreateClassLoader()

checkDelete

public void checkDelete(String file)

checkExec

public void checkExec(String cmd)

checkExit

public void checkExit(int status)

checkLink

public void checkLink(String lib)

checkListen

public void checkListen(int port)

checkMemberAccess

public void checkMemberAccess(Class clazz, int which)

checkMulticast

public void checkMulticast(InetAddress maddr)

public void checkMulticast(InetAddress maddr, byte ttl)

checkPackageAccess

public void checkPackageAccess(String pkg)

checkPackageDefinition

public void checkPackageDefinition(String pkg)

checkPrintJobAccess

public void checkPrintJobAccess()

checkPropertiesAccess

public void checkPropertiesAccess()

checkPropertyAccess

public void checkPropertyAccess(String key)

checkRead

public void checkRead(FileDescriptor fd)

public void checkRead(String file)

public void checkRead(String file, Object context)

checkSecurityAccess

public void checkSecurityAccess(String action)

checkSetFactory

public void checkSetFactory()

checkSystemClipboardAccess

public void checkSystemClipboardAccess()

checkTopLevelWindow

public boolean checkTopLevelWindow(Object window)

checkWrite

public void checkWrite(FileDescriptor fd)

public void checkWrite(String file)

getInCheck

public boolean getInCheck()

getSecurityContext

public Object getSecurityContext()

getThreadGroup

public ThreadGroup getThreadGroup()

Protected Instance Methods

classDepth

protected native int classDepth(String name)

classLoaderDepth

protected native int classLoaderDepth()

currentClassLoader

protected native ClassLoader currentClassLoader()

currentLoadedClass

protected Class currentLoadedClass()

getClassContext

protected native Class[] getClassContext()

inClass

protected boolean inClass(String name)

inClassLoader

protected boolean inClassLoader()

Inherited Methods

Method Inherited From Method Inherited From
clone() Object equals(Object) Object
finalize() Object getClass() Object
hashCode() Object notify() Object
notifyAll() Object toString() Object
wait() Object wait(long) Object
wait(long, int) Object

See Also

Class; ClassLoader; Exceptions; Object; Runtime; System; Thread; ThreadGroup