Package java.lang Previous
Previous
Java API
Java API
Index
Index
Next
Next

Class SecurityManager

Fields , Constructors , Methods

public abstract  class  java.lang.SecurityManager
    extends  java.lang.Object  
{
        // Fields
    protected boolean inCheck;	

        // Constructors
    protected SecurityManager();	

        // Methods
    public void  checkAccept(String  host, int  port);	
    public void checkAccess(Thread  g);	
    public void checkAccess(ThreadGroup  g);	
    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  lib);	
    public void checkListen(int  port);	
    public void checkPackageAccess(String  pkg);	
    public void checkPackageDefinition(String  pkg);	
    public void checkPropertiesAccess();	
    public void checkPropertyAccess(String  key);	
    public void checkRead(FileDescriptor  fd);	
    public void checkRead(String  file);	
    public void checkRead(String  file, Object  context);	
    public void checkSetFactory();	
    public boolean checkTopLevelWindow(Object  window);	
    public void checkWrite(FileDescriptor  fd);	
    public void checkWrite(String  file);	
    protected int classDepth(String  name);	
    protected int classLoaderDepth();	
    protected ClassLoader currentClassLoader();	
    protected Class[] getClassContext();	
    public boolean getInCheck();	
    public Object getSecurityContext();	
    protected boolean inClass(String  name);	
    protected boolean inClassLoader();	
}

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 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:

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 by the setSecurityManager method in class -System. The current security manager is obtained by the get-Security-Manager method .

The default implementation of each of the checkXXX methods is to assume that the caller does not have permission to perform the requested operation.


Fields


inCheck

protected boolean inCheck 

This field is true if there is a security check in progress; false otherwise.


Constructors


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

Throw:

SecurityException

If a security manager already exists.


Methods


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 by the accept method of class ServerSocket.

The checkAccept method for class SecurityManager always throws a SecurityException.

ParameterDescription
host the host name of the socket connection
port the port number of the socket connection

Throw:

SecurityException

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 by the stop , suspend , resume , setPriority , setName and setDaemon methods of class Thread.

The checkAccess method for class SecurityManager always throws a SecurityException.

ParameterDescription
g the thread to be checked

Throw:

SecurityException

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 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 always throws a SecurityException.

ParameterDescription
g the Thread group to be checked

Throw:

SecurityException

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.

ParameterDescription
host the host name port to connect to
port the protocol port to connect to

Throw:

SecurityException

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 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.

ParameterDescription
host the host name port to connect to
port the protocol port to connect to
context a system-dependent security context

Throw:

SecurityException

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 .

The checkCreateClassLoader method for class SecurityManager always throws a SecurityException.

Throw:

SecurityException

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 by the delete method of class File.

The checkDelete method for class SecurityManager always throws a SecurityException.

ParameterDescription
file the system dependent file name

Throw:

SecurityException

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 by the exec methods of class Runtime.

The checkExec method for class SecurityManager always throws a SecurityException.

ParameterDescription
cmd the specified system command

Throw:

SecurityException

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 by the exit method of class Runtime. A status of 0 indicates success; other values indicate various errors.

The checkExit method for class SecurityManager always throws a SecurityException.

ParameterDescription
status the exit status

Throw:

SecurityException

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 by methods load and loadLibrary of class Runtime.

The checkLink method for class SecurityManager always throws a SecurityException.

ParameterDescription
lib the name of the library

Throw:

SecurityException

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.

ParameterDescription
port the local port

Throw:

SecurityException

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 of class loaders.

The checkPackageAccess method for class SecurityManager always throws a SecurityException.

ParameterDescription
pkg the package name

Throw:

SecurityException

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 of some class loaders.

The checkPackageDefinition method for class SecurityManager always throws a SecurityException.

ParameterDescription
pkg the package name

Throw:

SecurityException

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 and setProperties methods of class System.

The checkPropertiesAccess method for class SecurityManager always throws a SecurityException.

Throw:

SecurityException

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 method of class System.

The checkPropertiesAccess method for class SecurityManager always throws a SecurityException.

ParameterDescription
key a system property key.

Throw:

SecurityException

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 .

The checkRead method for class SecurityManager always throws a SecurityException.

ParameterDescription
fd the system dependent file descriptor

Throw:

SecurityException

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.

ParameterDescription
file the system dependent file name

Throw:

SecurityException

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 .

The checkRead method for class SecurityManager always throws a SecurityException.

ParameterDescription
file the system dependent file name
context

Throw:

SecurityException

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 or Socket , or the stream handler factory used by URL .

The checkSetFactory method for class SecurityManager always throws a SecurityException.

Throw:

SecurityException

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 for more information on trusted and untrusted windows.

The checkSetFactory method for class SecurityManager always return false.

Return Value:

Returns true if the caller is trusted to put up top-level windows; false otherwise.

ParameterDescription
window the new window that's being created.


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 .

The checkWrite method for class SecurityManager always throws a SecurityException.

ParameterDescription
fd the system dependent file descriptor

Throw:

SecurityException

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.

ParameterDescription
file the system dependent file name

Throw:

SecurityException

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.

Return Value:

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.

ParameterDescription
name the fully qualified name of the class to search for


classLoaderDepth

protected int classLoaderDepth() 

Determines the stack stack of the most recently executing method from a class defined using a class loader.

Return Value:

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.

Return Value:

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.

Return Value:

Returns the execution stack.


getInCheck

public boolean getInCheck() 

Return Value:

Returns the value of the inCheck 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 and by the two-argument checkRead method .

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.

Return Value:

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) 

Return Value:

Returns true if a method from a class with the specified name is on the execution stack; false otherwise.

ParameterDescription
name the fully-qualified name of the class


inClassLoader

protected boolean inClassLoader() 

Return Value:

Returns true if a method from a class defined using a class loader is on the execution stack.



Top© 1996 Sun Microsystems, Inc. All rights reserved.