Packages This Package Prev Next Index
§1.15 Class SecurityManager
public abstract class java.lang.SecurityManager
extends java.lang.Object (I-§1.12)
{
// Fields
protected boolean inCheck; §1.15.1
// Constructors
protected SecurityManager(); §1.15.2
// Methods
public void checkAccept(String host, int port); §1.15.3
public void checkAccess(Thread g); §1.15.4
public void checkAccess(ThreadGroup g); §1.15.5
public void checkConnect(String host, int port); §1.15.6
public void checkConnect(String host, int port, §1.15.7
Object context);
public void checkCreateClassLoader(); §1.15.8
public void checkDelete(String file); §1.15.9
public void checkExec(String cmd); §1.15.10
public void checkExit(int status); §1.15.11
public void checkLink(String lib); §1.15.12
public void checkListen(int port); §1.15.13
public void checkPackageAccess(String pkg); §1.15.14
public void checkPackageDefinition(String pkg); §1.15.15
public void checkPropertiesAccess(); §1.15.16
public void checkPropertyAccess(String key); §1.15.17
public void checkRead(FileDescriptor fd); §1.15.18
public void checkRead(String file); §1.15.19
public void checkRead(String file, Object context); §1.15.20
public void checkSetFactory(); §1.15.21
public boolean checkTopLevelWindow(Object window); §1.15.22
public void checkWrite(FileDescriptor fd); §1.15.23
public void checkWrite(String file); §1.15.24
protected int classDepth(String name); §1.15.25
protected int classLoaderDepth(); §1.15.26
protected ClassLoader currentClassLoader(); §1.15.27
protected Class[] getClassContext(); §1.15.28
public boolean getInCheck(); §1.15.29
public Object getSecurityContext(); §1.15.30
protected boolean inClass(String name); §1.15.31
protected boolean inClassLoader(); §1.15.32
}
The security manager is an abstract class that allows applications to implement a security
policy. It allows an application to determine, before performing a possibly unsafe or sensitive operation, what the operation is and whether the operation is being performed by a
class created via a class loader (I-§1.4) rather than installed locally. Classes loaded via a
class loader (especially if they have been downloaded over a network) may be less trustworthy than classes from files installed locally. The application has the option of allowing
or disallowing the operation.
The securityManager class contains a large number of methods whose names 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:
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 (I-§1.43) if the operation is not permitted. The
only exception to this convention is checkTopLevelWindow (I-§1.15.22), which returns a boolean value.
The current security manager is set by the by the setSecurityManager method (I-§1.18.16) in
class -System. The current security manager is obtained by the get-Security-Manager method
(I-§1.18.11).
The default implementation of each of the checkXXX methods is to assume that the caller
does not have permission to perform the requested operation.
inCheck
protected boolean inCheck
- This field is true if there is a security check in progress; false otherwise.
SecurityManager
protected SecurityManager()
- Constructs a new SecurityManager. An application is not allowed to create a
new security manager if there is already a current security manager
(I-§1.18.11)
- Throws
- SecurityException (I-§1.43)
- If a security manager already exists.
checkAccept
public void checkAccept(String host, int port)
- This method should throw a SecurityException if the calling thread is not permitted to accepting a socket connection from the specified host and port
number.
- This method is invoked for the current security manager (I-§1.18.11) by
the accept method (I-§4.5.3) of class ServerSocket.
- The checkAccept method for class SecurityManager always throws a SecurityException.
- Parameters:
host
-
the host name of the socket connection
port
-
the port number of the socket connection
- Throws
- SecurityException (I-§1.43)
- If the caller does not have permission to accept the connection
checkAccess
public void checkAccess(Thread g)
- This method should throw a SecurityException if the calling thread is not
allowed to modify the thread argument.
- This method is invoked for the current security manager (I-§1.18.11) by
the stop (I-§1.19.37), suspend (I-§1.19.39), resume (I-§1.19.29), setPriority
(I-§1.19.33), setName (I-§1.19.32) and setDaemon (I-§1.19.31) methods of
class Thread.
- The checkAccess method for class SecurityManager always throws a SecurityException.
- Parameters:
g
-
the thread to be checked
- Throws
- SecurityException (I-§1.43)
- If the caller does not have permission to modify the thread
checkAccess
public void checkAccess(ThreadGroup g)
- This method should throw a SecurityException if the calling thread is not
allowed to modify the thread group argument.
- This method is invoked for the current security manager (I-§1.18.11) when
a new child thread or child thread group is created, and by the setDaemon
(I-§1.20.18), setMaxPriority (I-§1.20.19), stop (I-§1.20.20), suspend
(I-§1.20.21), resume (I-§1.20.17), and destroy (I-§1.20.6) methods of class
ThreadGroup.
- The checkAccess method for class SecurityManager always throws a SecurityException.
- Parameters:
g
-
the Thread group to be checked
- Throws
- SecurityException (I-§1.43)
- If the caller does not have permission to modify the thread group
checkConnect
public void checkConnect(String host, int port)
- This method should throw a SecurityException if the calling thread is not
allowed to open a socket connection to the specified host and port number.
- A port number of 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 always throws a SecurityException.
- Parameters:
host
-
the host name port to connect to
port
-
the protocol port to connect to
- Throws
- SecurityException (I-§1.43)
- If the caller does not have permission to open a socket connection to
the specified host and port.
checkConnect
public void
checkConnect(String host, int port, Object context)
- This method should throw a SecurityException if the specified security context
(I-§1.15.30) is not allowed to open a socket connection to the specified
host and port number.
- A port number of 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 always throws a SecurityException.
- Parameters:
host
-
the host name port to connect to
port
-
the protocol port to connect to
context
-
a system-dependent security context
- Throws
- SecurityException (I-§1.43)
- If the specified security context does not have permission to open a
socket connection.to the specified host and port.
checkCreateClassLoader
public void checkCreateClassLoader()
- This method should throw a SecurityException if the calling thread is not
allowed to create a new class loader (I-§1.4.1).
- The checkCreateClassLoader method for class SecurityManager always throws a
SecurityException.
- Throws
- SecurityException (I-§1.43)
- If the caller does not have permission to create a new class loader.
checkDelete
public void checkDelete(String file)
- This method should throw a SecurityException if the calling thrad is not
allowed to delete the specified file.
- This method is invoked for the current security manager (I-§1.18.11) by
the delete method (I-§2.7.10) of class File.
- The checkDelete method for class SecurityManager always throws a SecurityException.
- Parameters:
file
-
the system dependent file name
- Throws
- SecurityException (I-§1.43)
- If the caller does not have permission to delete the file.
checkExec
public void checkExec(String cmd)
- This method should throw a SecurityException if the calling thread is not
allowed to create a subprocss.
- This method is invoked for the current security manager (I-§1.18.11) by
the exec methods (§1.14.1-§1.14.4) of class Runtime.
- The checkExec method for class SecurityManager always throws a SecurityException.
- Parameters:
cmd
-
the specified system command
- Throws
- SecurityException (I-§1.43)
- If the caller does not have permission to create a subprocess.
checkExit
public void checkExit(int status)
- This method should throw a SecurityException if the calling thread is not
allowed to cause the Java Virtual Machine to halt with the specified access
code.
- This method is invoked for the current security manager (I-§1.18.11) by
the exit method (I-§1.14.5) of class Runtime. A status of 0 indicates success;
other values indicate various errors.
- The checkExit method for class SecurityManager always throws a SecurityException.
- Parameters:
status
-
the exit status
- Throws
- SecurityException (I-§1.43)
- If the caller does not have permission to halt the Java Virtual Machine
with the specified status.
checkLink
public void checkLink(String lib)
- This method should throw a SecurityException 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 file name.
- This method is invoked for the current security manager (I-§1.18.11) by
methods load (I-§1.14.11) and loadLibrary (I-§1.14.12) of class Runtime.
- The checkLink method for class SecurityManager always throws a SecurityException.
- Parameters:
lib
-
the name of the library
- Throws
- SecurityException (I-§1.43)
- If the caller does not have permission to dynamically link the library.
checkListen
public void checkListen(int port)
- This method should throw a SecurityException if the calling thread is not
allowed to wait for a connection request on the specified local port number.
- The checkListen method for class SecurityManager always throws a SecurityException.
- Parameters:
port
-
the local port
- Throws
- SecurityException (I-§1.43)
- If the caller does not have permission to listen on the specified port.
checkPackageAccess
public void checkPackageAccess(String pkg)
- This method should throw a SecurityException if the calling thread is allowed
to access the package specified by the argument.
- This method is used by the loadClass method (I-§1.4.4) of class loaders.
- The checkPackageAccess method for class SecurityManager always throws a SecurityException.
- Parameters:
pkg
-
the package name
- Throws
- SecurityException (I-§1.43)
- If the caller does not have permission to access the specified package.
checkPackageDefinition
public void checkPackageDefinition(String pkg)
- This method should throw a SecurityException 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 (I-§1.4.4) of some class loaders.
- The checkPackageDefinition method for class SecurityManager always throws a
SecurityException.
- Parameters:
pkg
-
the package name
- Throws
- SecurityException (I-§1.43)
- If the caller does not have permission to define classes in the specified
package.
checkPropertiesAccess
public void checkPropertiesAccess()
- This method should throw a SecurityException if the calling thread is not
allowed to access or modify the system properties.
- This method is used by the getProperties (I-§1.18.8) and setProperties
(I-§1.18.15) methods of class System.
- The checkPropertiesAccess method for class SecurityManager always throws a SecurityException.
- Throws
- SecurityException (I-§1.43)
- If the caller does not have permission to access or modify the system
properties.
checkPropertyAccess
public void checkPropertyAccess(String key)
- This method should throw a SecurityException if the calling thread is not
allowed to access the system property with the specified key name.
- This method is used by the getProperty (I-§1.18.9) method of class System.
- The checkPropertiesAccess method for class SecurityManager always throws a SecurityException.
- Parameters:
key
-
a system property key.
- Throws
- SecurityException (I-§1.43)
- If the caller does not have permission to access the specified system
property.
checkRead
public void checkRead(FileDescriptor fd)
- This method should throw a SecurityException if the calling thread is not
allowed to read from the specified file descriptor (I-§2.8).
- The checkRead method for class SecurityManager always throws a SecurityException.
- Parameters:
fd
-
the system dependent file descriptor
- Throws
- SecurityException (I-§1.43)
- If the caller does not have permission to access the specified file
descriptor.
checkRead
public void checkRead(String file)
- This method should throw a SecurityException if the calling thread is not
allowed to read the file specified by the string argument.
- The checkRead method for class SecurityManager always throws a SecurityException.
- Parameters:
file
-
the system dependent file name
- Throws
- SecurityException (I-§1.43)
- If the caller does not have permission to access the specified file.
checkRead
public void checkRead(String file, Object context)
- This method should throw a 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
(I-§1.15.30).
- The checkRead method for class SecurityManager always throws a SecurityException.
- Parameters:
file
-
the system dependent file name
context
-
- a system-dependent security context
-
- Throws
- SecurityException (I-§1.43)
- If the specified security context does not have permission to read the
specified file.
checkSetFactory
public void checkSetFactory()
- This method should throw a SecurityException if the calling thread is not
allowed to set the socket factor used by ServerSocket (I-§4.5.7) or Socket
(I-§4.6.11), or the stream handler factory used by URL (I-§4.8.16).
- The checkSetFactory method for class SecurityManager always throws a SecurityException.
- Throws
- SecurityException (I-§1.43)
- The caller does not have permission to specify a socket factory or a
stream handler factory.
checkTopLevelWindow
public boolean checkTopLevelWindow(Object window)
- This method should return 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 (II-§1.42) for more information on trusted and untrusted
windows.
- The checkSetFactory method for class SecurityManager always return false.
- Parameters:
window
-
the new window that's being created.
- Returns:
- true if the caller is trusted to put up top-level windows; false otherwise.
checkWrite
public void checkWrite(FileDescriptor fd)
- This method should throw a SecurityException if the calling thread is not
allowed to write to the specified file descriptor (I-§2.8).
- The checkWrite method for class SecurityManager always throws a SecurityException.
- Parameters:
fd
-
the system dependent file descriptor
- Throws
- SecurityException (I-§1.43)
- If the caller does not have permission to access the specified file
descriptor.
checkWrite
public void checkWrite(String file)
- This method should throw a SecurityException if the calling thread is not
allowed to write to the file specified by the string argument.
- The checkWrite method for class SecurityManager always throws a SecurityException.
- Parameters:
file
-
the system dependent file name
- Throws
- SecurityException (I-§1.43)
- If the caller does not have permission to access the specified file.
classDepth
protected int classDepth(String name)
- Determines the stack depth of a given class.
- Parameters:
name
-
the fully qualified name of the class to search for
- Returns:
- the depth on the stack frame of the first occurrence of a method from a
class with the specified name; -1 if such a frame cannot be found.
classLoaderDepth
protected int classLoaderDepth()
- Determines the stack stack of the most recently executing method from a
class defined using a class loader.
- Returns:
- the depth on the stack frame of the most recent occurrence of a
method from a class defined using a class loader; returns -1 if there is
no occurrence of a method from a class defined using a class loader
currentClassLoader
protected ClassLoader currentClassLoader()
- Determines the most recent class loader executing on the stack.
- Returns:
- the class loader of the most recent occurrence on the stack of a method
from a class defined using a class loader; returns null if there is no
occurrence on the stack of a method from a class defined using a class
loader.
getClassContext
protected Class[] getClassContext()
- Calculates the current execution stack, which is returned as an array of
classes.
- 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 forth.
- Returns:
- the execution stack.
getInCheck
public boolean getInCheck()
- Returns:
- the value of the inCheck (I-§1.15.1) field. This field should contain true
if a security check is in progress; false otherwise.
getSecurityContext
public Object getSecurityContext()
- Creates an object when encapsulates the current execution environment.
The result of this method is used by the three-argument checkConnect
method (I-§1.15.7) and by the two-argument checkRead method
(I-§1.15.20).
- These methods are needed because a trusted method may be called upon 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.
- Returns:
- an implementation-dependent object which encapsulates sufficient
information about the current execution environment to perform some
security checks later.
inClass
protected boolean inClass(String name)
- Parameters:
name
-
the fully-qualified name of the class
- Returns:
- true if a method from a class with the specified name is on the execution stack; false otherwise.
inClassLoader
protected boolean inClassLoader()
- Returns:
- true if a method from a class defined using a class loader is on the execution stack.
Packages This Package Prev Next Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc.
All rights reserved
Please send any comments or corrections to doug.kramer@sun.com