All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----java.lang.SecurityManager
The SecurityManager
class contains many methods with
names that begin with the word check
. These methods
are called by various methods in the Java libraries before those
methods perform certain potentially sensitive operations. The
invocation of such a check method typically looks like this:
SecurityManager security = System.getSecurityManager(); if (security != null) { security.checkXXX(argument, . . . ); }
The security manager is thereby given an opportunity to prevent
completion of the operation by throwing an exception. A security
manager routine simply returns if the operation is permitted, but
throws a SecurityException
if the operation is not
permitted. The only exception to this convention is
checkTopLevelWindow
, which returns a
boolean
value.
The current security manager is set by the
setSecurityManager
method in class
System
. The current security manager is obtained
by the getSecurityManager
method.
As of JDK 1.2, the default implementation of each of the
check
XXX methods is to use the AccessController
to determine if the caller has permission to perform the requested
operation.
Permissions fall into these categories: File, Socket, Net,
Security, Runtime, Property, and AWT. The classes managing these various
permission categories are java.io.FilePermission
,
java.net.SocketPermission
,
java.net.NetPermission
,
java.security.SecurityPermission
,
java.lang.RuntimePermission
,
java.util.PropertyPermission
, and
java.awt.AWTPermission
.
All but the first two (FilePermission and SocketPermission) are
subclasses of java.security.BasicPermission
, which itself
is an abstract subclass of the
top-level class for permissions, which is
java.security.Permission
. BasicPermission defines the
functionality needed for all permissions that contain a name
that follows the hierarchical property naming convention
(for example, "exit", "setFactory", "print.queueJob", etc).
An asterisk
may appear at the end of the name, following a ".", or by itself, to
signify a wildcard match. For example: "a.*" or "*" is valid,
"*a" or "a*b" is not valid.
FilePermission and SocketPermission are subclasses of the
top-level class for permissions
(java.security.Permission
). Classes like these
that have a more complicated name syntax than that used by
BasicPermission subclass directly from Permission rather than from
BasicPermission. For example,
for a java.io.FilePermission
object, the permission name is
the pathname of a file (or directory).
Some of the permission classes have an "actions" list that tells
the actions that are permitted for the object. For example,
for a java.io.FilePermission
object, the actions list
(such as "read, write") specifies which actions are granted for the
specified file (or for files in the specified directory).
Other permission classes are for "named" permissions - ones that contain a name but no actions list; you either have the named permission or you don't.
The permission namespace is organized in the manner shown below. For each category, the category name is given, followed by an indented list of permission names (such as "createClassLoader" and "exit") and permission name types in braces (such as "{property name}" to represent an actual property name). Each permission name (or name type) is followed by the name in parentheses of the SecurityManager class(es) that handle that kind of permission.
RuntimePermission createClassLoader (checkCreateClassLoader) exit (checkExit) setFactory (checkSetFactory) setIO (java.lang.System.{setIn,setOut,SetErr}) thread (checkAccess(Thread), checkAccess(ThreadGroup)) fileDescriptor.read (checkRead(FileDescriptor)) fileDescriptor.write (checkWrite(FileDescriptor)) loadLibrary.{library name} (checkLink) package.access.{package name} (checkPackageAccess) package.define.{package name} (checkPackageDefinition) reflect.declared.{class name} (checkMemberAccess) print.queueJob (checkPrintJobAccess) NetPermission multicast (checkMulticast) Authenticator.setDefault Authenticator.requestPasswordAuthentication PropertyPermission * (checkPropertiesAccess) {property name} (checkPropertyAccess) AWTPermission topLevelWindow (checkTopLevelWindow) systemClipboard (checkSystemClipboardAccess) eventQueue (checkAwtEventQueueAccess) SecurityPermission {action} (checkSecurityAccess) FilePermission {file or directory pathname} (checkExec, checkRead(String), checkWrite(String), checkDelete} SocketPermission {host:port} {checkConnect, checkListen, checkAccept}
true
if there is a security check in
progress; false
otherwise.
Deprecated.
SecurityManager
.
AccessControlException
if the
calling thread is not permitted to accept a socket connection from
the specified host and port number.
AccessControlException
if the
calling thread is not allowed to modify the thread argument.
AccessControlException
if the
calling thread is not allowed to modify the thread group argument.
AccessControlException
if the
calling thread is not allowed to open a socket connection to the
specified host and port number.
SecurityException
if the
specified security context is not allowed to open a socket
connection to the specified host and port number.
AccessControlException
if the
calling thread is not allowed to create a new class loader.
AccessControlException
if the
calling thread is not allowed to delete the specified file.
AccessControlException
if the
calling thread is not allowed to create a subprocess.
AccessControlException
if the
calling thread is not allowed to cause the Java Virtual Machine to
halt with the specified status code.
AccessControlException
if the
calling thread is not allowed to dynamic link the library code
specified by the string argument file.
AccessControlException
if the
calling thread is not allowed to wait for a connection request on
the specified local port number.
AccessControlException
if the
calling thread is not allowed to access the package specified by
the argument.
AccessControlException
if the
calling thread is not allowed to define classes in the package
specified by the argument.
AccessControlException
if the
calling thread is not allowed to access or modify the system
properties.
AccessControlException
if the
calling thread is not allowed to access the system property with
the specified key
name.
AccessControlException
if the
calling thread is not allowed to read from the specified file
descriptor.
AccessControlException
if the
calling thread is not allowed to read the file specified by the
string argument.
SecurityException
if the
specified security context is not allowed to read the file
specified by the string argument.
AccessControlException
if the
calling thread is not allowed to set the socket factory used by
ServerSocket
or Socket
, or the stream
handler factory used by URL
.
false
if the calling
thread is not trusted to bring up the top-level window indicated
by the window
argument.
AccessControlException
if the
calling thread is not allowed to write to the specified file
descriptor.
AccessControlException
if the
calling thread is not allowed to write to the file specified by
the string argument.
protected boolean inCheck
true
if there is a security check in
progress; false
otherwise.
public SecurityManager()
SecurityManager
. An application is
not allowed to create a new security manager if there is already a
current security manager.
public boolean getInCheck()
inCheck
field. This field
should contain true
if a security check is
in progress,
false
otherwise.protected Class[] getClassContext()
The length of the array is the number of methods on the execution
stack. The element at index 0
is the class of the
currently executing method, the element at index 1
is
the class of that method's caller, and so on.
protected ClassLoader currentClassLoader()
null
if there is no occurrence on the
stack of a method from a class defined using a class loader.protected Class currentLoadedClass()
protected int classDepth(String name)
-1
if such a frame cannot be found.protected int classLoaderDepth()
-1
if there is no occurrence of a method from
a class defined using a class loader.protected boolean inClass(String name)
true
if a method from a class with the specified
name is on the execution stack; false
otherwise.protected boolean inClassLoader()
true
if a method from a class defined using a
class loader is on the execution stack.public Object getSecurityContext()
checkConnect
method and by the
two-argument checkRead
method.
These methods are needed because a trusted method may be called on to read a file or open a socket on behalf of another method. The trusted method needs to determine if the other (possibly untrusted) method would be allowed to perform the operation on its own.
public void checkCreateClassLoader()
AccessControlException
if the
calling thread is not allowed to create a new class loader.
The checkCreateClassLoader
method for class
SecurityManager
calls
AccessController.checkPermission
with the
RuntimePermission("createClassLoader")
permission.
public void checkAccess(Thread g)
AccessControlException
if the
calling thread is not allowed to modify the thread argument.
This method is invoked for the current security manager by the
stop
, suspend
, resume
,
setPriority
, setName
, and
setDaemon
methods of class Thread
.
The checkAccess
method for class
SecurityManager
calls
AccessController.checkPermission
with the
RuntimePermission("thread")
permission.
public void checkAccess(ThreadGroup g)
AccessControlException
if the
calling thread is not allowed to modify the thread group argument.
This method is invoked for the current security manager when a
new child thread or child thread group is created, and by the
setDaemon
, setMaxPriority
,
stop
, suspend
, resume
, and
destroy
methods of class ThreadGroup
.
The checkAccess
method for class
SecurityManager
calls
AccessController.checkPermission
with the
RuntimePermission("thread")
permission.
public void checkExit(int status)
AccessControlException
if the
calling thread is not allowed to cause the Java Virtual Machine to
halt with the specified status code.
This method is invoked for the current security manager by the
exit
method of class Runtime
. A status
of 0
indicates success; other values indicate various
errors.
The checkExit
method for class
SecurityManager
calls
AccessController.checkPermission
with the
RuntimePermission("exit")
permission.
public void checkExec(String cmd)
AccessControlException
if the
calling thread is not allowed to create a subprocess.
This method is invoked for the current security manager by the
exec
methods of class Runtime
.
The checkExec
method for class
SecurityManager
calls
AccessController.checkPermission
with the
FilePermission(cmd,"execute")
permission.
public void checkLink(String lib)
AccessControlException
if the
calling thread is not allowed to dynamic link the library code
specified by the string argument file. The argument is either a
simple library name or a complete filename.
This method is invoked for the current security manager by
methods load
and loadLibrary
of class
Runtime
.
The checkLink
method for class
SecurityManager
calls
AccessController.checkPermission
with the
RuntimePermission("loadLibrary."+lib)
permission.
public void checkRead(FileDescriptor fd)
AccessControlException
if the
calling thread is not allowed to read from the specified file
descriptor.
The checkRead
method for class
SecurityManager
calls
AccessController.checkPermission
with the
RuntimePermission("fileDescriptor.read")
permission.
public void checkRead(String file)
AccessControlException
if the
calling thread is not allowed to read the file specified by the
string argument.
The checkRead
method for class
SecurityManager
calls
AccessController.checkPermission
with the
FilePermission(file,"read")
permission.
public void checkRead(String file, Object context)
SecurityException
if the
specified security context is not allowed to read the file
specified by the string argument. The context must be a security
context returned by a previous call to
getSecurityContext
.
The checkRead
method for class
SecurityManager
currently always throws a
SecurityException
.
public void checkWrite(FileDescriptor fd)
AccessControlException
if the
calling thread is not allowed to write to the specified file
descriptor.
The checkWrite
method for class
SecurityManager
calls
AccessController.checkPermission
with the
RuntimePermission("fileDescriptor.write")
permission.
public void checkWrite(String file)
AccessControlException
if the
calling thread is not allowed to write to the file specified by
the string argument.
The checkWrite
method for class
SecurityManager
calls
AccessController.checkPermission
with the
FilePermission(file,"write")
permission.
public void checkDelete(String file)
AccessControlException
if the
calling thread is not allowed to delete the specified file.
This method is invoked for the current security manager by the
delete
method of class File
.
The checkDelete
method for class
SecurityManager
calls
AccessController.checkPermission
with the
FilePermission(file,"delete")
permission.
public void checkConnect(String host, int port)
AccessControlException
if the
calling thread is not allowed to open a socket connection to the
specified host and port number.
A port number of -1
indicates that the calling
method is attempting to determine the IP address of the specified
host name.
The checkConnect
method for class
SecurityManager
calls
AccessController.checkPermission
with the
SocketPermission(host+":"+port,"connect")
permission if
the port is not equal to -1. If the port is equal to -1, then
it calls AccessController.checkPermission
with the
SocketPermission(host,"resolve")
permission.
host
and port
.public void checkConnect(String host, int port, Object context)
SecurityException
if the
specified security context is not allowed to open a socket
connection to the specified host and port number.
A port number of -1
indicates that the calling
method is attempting to determine the IP address of the specified
host name.
The checkConnect
method for class
SecurityManager
currently always throws a
SecurityException
.
host
and port
.public void checkListen(int port)
AccessControlException
if the
calling thread is not allowed to wait for a connection request on
the specified local port number.
If port is not 0, the checkListen
method for class
SecurityManager
calls
AccessController.checkPermission
with the
SocketPermission("localhost:"+port,"listen")
.
If port is zero, calls AccessController.checkPermission
with SocketPermission("localhost:1024-","listen").
public void checkAccept(String host, int port)
AccessControlException
if the
calling thread is not permitted to accept a socket connection from
the specified host and port number.
This method is invoked for the current security manager by the
accept
method of class ServerSocket
.
The checkAccept
method for class
SecurityManager
calls
AccessController.checkPermission
with the
SocketPermission(host+":"+port,"accept")
permission.
public void checkMulticast(InetAddress maddr)
The checkMulticast
method for class
SecurityManager
calls
AccessController.checkPermission
with the
RuntimePermission("multicast")
permission.
public void checkMulticast(InetAddress maddr, byte ttl)
The checkMulticast
method for class
SecurityManager
calls
AccessController.checkPermission
with the
RuntimePermission("multicast")
permission.
public void checkPropertiesAccess()
AccessControlException
if the
calling thread is not allowed to access or modify the system
properties.
This method is used by the getProperties
and
setProperties
methods of class System
.
The checkPropertiesAccess
method for class
SecurityManager
calls
AccessController.checkPermission
with the
PropertyPermission("*", "read,write")
permission.
public void checkPropertyAccess(String key)
AccessControlException
if the
calling thread is not allowed to access the system property with
the specified key
name.
This method is used by the getProperty
method of
class System
.
The checkPropertyAccess
method for class
SecurityManager
calls
AccessController.checkPermission
with the
PropertyPermission(key, "read")
permission.
public boolean checkTopLevelWindow(Object window)
false
if the calling
thread is not trusted to bring up the top-level window indicated
by the window
argument. In this case, the caller can
still decide to show the window, but the window should include
some sort of visual warning. If the method returns
true
, then the window can be shown without any
special restrictions.
See class Window
for more information on trusted and
untrusted windows.
This method calls
AccessController.checkPermission
with the
AWTPermission("topLevelWindow")
permission,
and returns true if an AccessControlException is not thrown, otherwise
it returns false.
true
if the caller is trusted to put up
top-level windows; false
otherwise.public void checkPrintJobAccess()
AccessController.checkPermission
with the
RuntimePermission("print.queueJob")
permission.
public void checkSystemClipboardAccess()
This method calls AccessController.checkPermission
with the
AWTPermission("systemClipboard")
permission.
public void checkAwtEventQueueAccess()
This method calls AccessController.checkPermission
with the
AWTPermission("eventQueue")
permission.
public void checkPackageAccess(String pkg)
AccessControlException
if the
calling thread is not allowed to access the package specified by
the argument.
This method is used by the loadClass
method of class
loaders.
The checkPackageAccess
method for class
SecurityManager
calls
AccessController.checkPermission
with the
RuntimePermission("package.access."+pkg)
permission.
public void checkPackageDefinition(String pkg)
AccessControlException
if the
calling thread is not allowed to define classes in the package
specified by the argument.
This method is used by the loadClass
method of some
class loaders.
The checkPackageDefinition
method for class
SecurityManager
calls
AccessController.checkPermission
with the
RuntimePermission("package.define."+pkg)
permission.
public void checkSetFactory()
AccessControlException
if the
calling thread is not allowed to set the socket factory used by
ServerSocket
or Socket
, or the stream
handler factory used by URL
.
The checkSetFactory
method for class
SecurityManager
calls
AccessController.checkPermission
with the
RuntimePermission("setFactory")
permission.
public void checkMemberAccess(Class clazz, int which)
AccessController.checkPermission
with the RuntimePermission("reflect.declared."+clazz.getName())
permission.
public void checkSecurityAccess(String action)
This method calls
AccessController.checkPermission
with the
SecurityPermission(action)
permission.
public ThreadGroup getThreadGroup()
All Packages Class Hierarchy This Package Previous Next Index