Packages
 In this topic

*Constructors

*Methods

 

Packages   PreviousThis PackageNext
Package com.ms.security   Previous This
Package
Next

 


Class StandardSecurityManager

public class StandardSecurityManager extends java.lang.SecurityManager
{
  // Constructors
  public StandardSecurityManager();

  // Methods
  public synchronized void checkAccept(String host, int port);
  public void checkAccess(Thread t);
  public void checkAccess(ThreadGroup g);
  public void checkAwtEventQueueAccess();
  public synchronized 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 checkFileDialog();
  public void checkLink(String lib);
  public synchronized void checkListen(int port);
  public void checkMemberAccess(Class clazz, int which);
  public void checkMulticast(InetAddress maddr);
  public void checkMulticast(InetAddress maddr, byte ttl);
  public synchronized void checkMultimedia();
  public void checkPackageAccess(String pkg);
  public static void checkPackageAccessFromClassName(
        String classname);
  public synchronized void checkPackageDefinition(String pkg);
  public static void checkPackageDefinitionFromClassName(
        String classname);
  public void checkPrintJobAccess();
  public void checkPropertiesAccess();
  public void checkPropertyAccess(String key);
  public void checkRead(String file);
  public static void checkRead(URL url);
  public void checkRead(String file, Object context);
  public void checkRead(FileDescriptor fd);
  public void checkRegistry (int access, String value);
  public void checkSecurityAccess(String provider);
  public void checkSetFactory();
  public void checkSystemClipboardAccess();
  public void checkSystemStreams(int streamID);
  public boolean checkTopLevelWindow(Object window);
  public void checkWrite(String file);
  public void checkWrite (FileDescriptor fd);
  public Object getSecurityContext();
  public ThreadGroup getThreadGroup();
  public static void installStandardSecurity();
}

This class defines a security policy that uses the permission model to perform security checks. The StandardSecurityManager.checkXXX methods call the PolicyEngine.checkPermission methods to do the stack crawl that actually determines whether the specified operation is permitted.

SecurityManager
  |
  +--StandardSecurityManager

Constructors

StandardSecurityManager

public StandardSecurityManager();

Constructs and initializes a StandardSecurityManager object.

Methods

checkAccept

public synchronized void checkAccept(String host, int port);

Determines whether classes within the current execution context, based on the call stack of the current thread, can accept a socket connection from the specified host and port.

The check succeeds only if all the classes found on the call stack possess NetIOPermissions, and if those permissions allow the specified host and port for connections. This method overrides the java.lang.SecurityManager.checkAccept(String,int) method.

Return Value:

No return value.

ParameterDescription
host The host.
port The port.

Exceptions:

SecurityException if the security check fails.

checkAccess

public void checkAccess(Thread t);

Determines whether classes within the current execution context, based on the call stack of the current thread, are allowed to manipulate the specified thread.

Return Value:

No return value.

ParameterDescription
t The thread whose call stack is being checked for permissions.

Remarks:

The check succeeds only if all the classes found on the call stack possess ThreadPermissions, and if those permissions allow access to the specified thread. This method overrides the java.lang.SecurityManager.checkAccess method.

Exceptions:

SecurityException if the security check fails.

checkAccess

public void checkAccess(ThreadGroup g);

Determines whether classes within the current execution context, based on the call stack of the current thread, are allowed to manipulate the specified thread group.

Return Value:

No return value.

ParameterDescription
g The thread group whose call stack is being checked for permissions.

Remarks:

The check succeeds only if all the classes found on the call stack possess ThreadPermissions, and if those permissions allow access to the specified thread group. This method overrides the java.lang.SecurityManager.checkAccess method.

Exceptions:

SecurityException if the security check fails.

checkAwtEventQueueAccess

public void checkAwtEventQueueAccess();

Determines whether classes within the current execution context, based on the call stack of the current thread, are allowed to access the AWT event queue.

Return Value:

No return value.

Remarks:

The check succeeds only if all the classes found on the call stack possess UIPermissions, and those permissions allow access to the AWT event queue. This method overrides the java.lang.SecurityManager.checkAwtEventQueueAccess method.

Exceptions:

SecurityException if the security check fails.

checkConnect

public synchronized void checkConnect (String host, int port);

Determines whether classes within the current execution context, based on the call stack of the current thread, can open a socket connection to the specified host on the specified port.

Return Value:

No return value.

ParameterDescription
host The host.
port The port.

Remarks:

The check succeeds only if all the classes found on the call stack possess NetIOPermissions, and if those permissions allow connections to the specified host and port. This method overrides the java.lang.SecurityManager.checkConnect(String,int) method.

Exceptions:

SecurityException if the security check fails.

checkConnect

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

Determines whether classes within the current execution context, based on the call stack of the current thread, can open a socket connection to the specified host on the specified port. This method overrides the java.lang.SecurityManager.checkConnect(String,int) method.

Note The context parameter is ignored, and this method simply forwards the check to the checkConnect(String host,int port) method.

Return Value:

No return value.

ParameterDescription
host The host.
port The port.
context This parameter is ignored.

Exceptions:

SecurityException if the security check fails.

See Also: checkConnect(String,int)

checkCreateClassLoader

public void checkCreateClassLoader();

Determines whether classes within the current execution context, based on the call stack of the current thread, are allowed to create class loader objects.

Return Value:

No return value.

Remarks:

The check succeeds only if the calling code is fully trusted. This method overrides the java.lang.SecurityManager.checkCreateClassLoader method.

Exceptions:

SecurityException if the security check fails.

checkDelete

public void checkDelete(String file);

Determines whether the specified file can be deleted by the classes active within the current execution context.

Return Value:

No return value.

ParameterDescription
file The system-dependent filename.

Remarks:

The check succeeds only if all the classes found on the call stack possess FileIOPermissions, and if those permissions allow delete access to the specified file. This method overrides the java.lang.SecurityManager.checkDelete(String) method.

Exceptions:

SecurityException if the security check fails.

checkExec

public void checkExec (String cmd);

Determines whether classes within the current execution context, based on the call stack of the current thread, are allowed to execute the specified application.

The check succeeds only if all of the classes found on the call stack possess ExecutionPermissions, and if those permissions allow the specified application to be run. This method overrides the java.lang.SecurityManager.checkExec method.

Return Value:

No return value.

ParameterDescription
cmd The application for which permission to execute is being checked.

Exceptions:

SecurityException if the security check fails.

checkExit

public void checkExit(int status);

Determines whether classes within the current execution context, based on the call stack of the current thread, are allowed to terminate the Microsoft Win32 VM for Java.

Return Value:

No return value.

ParameterDescription
status This parameter is ignored.

Remarks:

The check succeeds only if all the classes found on the call stack are fully trusted. This method overrides the java.lang.SecurityManager.checkExit method.

Exceptions:

SecurityException if the security check fails.

checkFileDialog

public void checkFileDialog();

Determines whether classes within the current execution context, based on the call stack of the current thread, are allowed to display and use file dialog boxes (java.awt.FileDialog).

Return Value:

No return value.

Remarks:

The check succeeds only if all the classes found on the call stack possess UIPermissions, and if those permissions allow the creation of file dialog boxes.

Exceptions:

SecurityException if the security check fails.

checkLink

public void checkLink(String lib);

Determines whether the current execution context, based on the calling classes on the call stack, allows the loading of the specified native code library (DLL).

Return Value:

No return value.

ParameterDescription
lib The DLL for which permission to load is checked.

Remarks:

The check succeeds only if the caller is fully trusted system code. This method overrides the java.lang.SecurityManager.checkLink method.

Exceptions:

SecurityException if the security check fails.

checkListen

public synchronized void checkListen(int port);

Determines whether classes within the current execution context, based on the call stack of the current thread, can wait for connection requests on the specified local port number.

Return Value:

No return value.

ParameterDescription
port The local port from which permission to listen is being checked.

Remarks:

The check succeeds only if all the classes found on the call stack possess NetIOPermissions, and if those permissions allow listening for connections on the specified port. This method overrides the java.lang.SecurityManager.checkListen(int) method.

Exceptions:

SecurityException if the security check fails.

checkMemberAccess

public void checkMemberAccess(Class clazz, int which);

Determines whether classes within the current execution context, based on the call stack of the current thread, are allowed to use the reflection APIs to access members of the specified type from the specified class.

Return Value:

No return value.

ParameterDescription
clazz The class to which access is being checked.
which The type of class members to which access is being checked.

Remarks:

The check succeeds only if all the classes found on the call stack possess ReflectionPermissions, and if those permissions allow access to the specified class.

Exceptions:

SecurityException if the security check fails.

checkMulticast

public void checkMulticast(InetAddress maddr);

Determines whether classes within the current execution context, based on the call stack of the current thread, are allowed to use IP multicast.

Return Value:

No return value.

ParameterDescription
maddr The Internet address.

Remarks:

The check succeeds only if all the classes found on the call stack possess NetIOPermissions, and if those permissions allow multicast operations on the specified Internet address. This method overrides the java.lang.SecurityManager.checkMulticast(InetAddress) method.

Exceptions:

SecurityException if the security check fails.

checkMulticast

public void checkMulticast(InetAddress maddr, byte ttl);

Determines whether classes within the current execution context, based on the call stack of the current thread, are allowed to use IP multicast.

Return Value:

No return value.

ParameterDescription
maddr The Internet address.
ttl The time to live for the packet.

Remarks:

The check succeeds only if all the classes found on the call stack possess NetIOPermissions, and if those permissions allow multicast operations on the specified address. This method overrides the java.lang.SecurityManager.checkMulticast(InetAddress,byte) method.

Exceptions:

SecurityException if the security check fails.

checkMultimedia

public synchronized void checkMultimedia();

Determines whether classes within the current execution context, based on the call stack of the current thread, are allowed to utilize extended multimedia features.

Return Value:

No return value.

Remarks:

The check succeeds only if all the classes found on the call stack possess MultimediaPermissions. This method is currently used by the com.ms.directX APIs.

Exceptions:

SecurityException if the security check fails.

checkPackageAccess

public void checkPackageAccess(String pkg);

Determines whether access to classes within the specified package is permitted. Package access is denied if a system property of the form package.restrict.access.packagename exists. This method overrides the java.lang.SecurityManager.checkPackageAccess(String) method.

Note Because of both the nature of class loaders and the fact that this check is made at load time instead of class resolution time, no specific contextual information can be extrapolated to determine who is attempting to access the specified package. Therefore, this check does not fit into the class-granular permissions model. Its results are based on a global state, so it will always return the same result, independent of the current execution context.

Return Value:

No return value.

ParameterDescription
pkg The name of the package to which access is being checked.

Exceptions:

SecurityException if package access is prohibited.

checkPackageAccessFromClassName

public static void checkPackageAccessFromClassName(String classname);

If a security manager is installed, checks to see if applets can access classes located in the package that contains a specified class.

Return Value:

No return value.

ParameterDescription
classname The name of the class from which the package to check is determined. The class name must be separated from the package name (if any) by a dot (.).

Remarks:

The checkPackageAccess method of the current security manager is called to determine whether the package access is allowed. If a security manager is not installed, this method does nothing. If the class name does not specify a package, the call succeeds.

Note This method requires a full class name. Do not trim off the class name as you would when calling java.lang.SecurityManager.checkPackageAccess.

Exceptions:

SecurityException if access to the package is prohibited.

checkPackageDefinition

public synchronized void checkPackageDefinition(String pkg);

Determines whether classes within the specified package can be defined.

Return Value:

No return value.

ParameterDescription
pkg The name of the package that determines which package to check.

Remarks:

The package definition is denied if a system property of the form package.restrict.definition.packagename exists. This method overrides the java.lang.SecurityManager.checkPackageAccess(String) method.

Note Because of both the nature of class loaders and the fact that this check is made at load time instead of class resolution time, no specific contextual information can be extrapolated to determine who is attempting to define a class in the specified package. Therefore, this check cannot fit into the class-granular permissions model. This check is based on a global state, and will always return the same result, independent of the current execution context.

Exceptions:

SecurityException if the package definition is prohibited.

checkPackageDefinitionFromClassName

public static void checkPackageDefinitionFromClassName(String classname);

If a security manager is installed, checks to see if applets can define classes in the package of the specified class name.

Return Value:

No return value.

ParameterDescription
classname The name of the class that determines which package to check. The class name must be separated from the package name (if any) by dots (.).

Remarks:

The checkPackageDefinition method of the current security manager is called to determine if the package definition is allowed. If the class name does not specify a package, the call will succeed. If a security manager is not installed, this method does nothing.

Note This method expects a full class name. Do not trim off the class name as you would when calling java.lang.SecurityManager.checkPackageDefinition.

Exceptions:

SecurityException if the package definition is prohibited.

See Also: checkPackageDefinition

checkPrintJobAccess

public void checkPrintJobAccess();

Determines whether classes within the current execution context, based on the call stack of the current thread, are allowed to initiate a print job.

Return Value:

No return value.

Remarks:

The check succeeds only if all the classes found on the call stack possess UIPermissions, and if those permissions allow printing. This method overrides the java.lang.SecurityManager.checkPrintJobAccess method.

Exceptions:

SecurityException if the security check fails.

checkPropertiesAccess

public void checkPropertiesAccess();

Determines whether the system properties object can be passed to the caller of the System.getProperties method.

Return Value:

No return value.

Remarks:

The check succeeds only if all the classes found on the call stack possess PropertyPermissions and if those permissions grant unlimited system properties access. This method overrides the java.lang.SecurityManager.checkPropertiesAccess method.

Exceptions:

SecurityException if the security check fails.

checkPropertyAccess

public void checkPropertyAccess(String key);

Determines if the specified system property can be read by all the classes within the current execution context.

Return Value:

No return value.

ParameterDescription
key The system property for which read access is being checked.

Remarks:

The check succeeds only if all the classes found on the call stack possess PropertyPermissions and those permissions allow read access to the specified property. This method overrides the java.SecurityManager.checkPropertyAccess method.

Exceptions:

SecurityException if the security check fails.

checkRead

public void checkRead(String file);

Determines whether the specified file can be read by the classes active within the current execution context.

Return Value:

No return value.

ParameterDescription
file The file for which permission to be read by active classes is being checked.

Remarks:

The check succeeds if all the classes found on the call stack possess FileIOPermissions and those permissions allow read access to the specified file. This method overrides the java.lang.SecurityManager.checkRead(String) method.

Exceptions:

SecurityException if the security check fails.

checkRead

public static void checkRead(URL url);

Determines whether the specified URL can be read by the code in the current execution context.

Return Value:

No return value.

ParameterDescription
url The URL for which permission to read is being checked.

Remarks:

If the specified URL is a file:// URL, this method performs a checkRead(String file) to determine if the file specified by the URL can be read. Otherwise, this method performs a checkConnect(url.getHost(),url.getPort()) to determine if the the host/port can be connected to.

Exceptions:

SecurityException if the security check fails.

checkRead

public void checkRead(String file, Object context);

Determines whether the specified file and the specified context object can be read by the classes within the current execution context. This method overrides the java.lang.SecurityManager.checkRead method.

Note The context object must be an URL object.

Return Value:

No return value.

ParameterDescription
file The system-dependent filename.
context The URL to be checked in addition to the file.

Exceptions:

SecurityException if the file is not found.

checkRead

public void checkRead(FileDescriptor fd);

Determines whether classes within the current execution context, based on the call stack of the current thread, can use the specified FileDescriptor object to read from the file it is associated with.

Return Value:

No return value.

ParameterDescription
fd The file descriptor associated with the file from which permission to read is being checked.

Remarks:

The check succeeds only if all the classes found on the call stack are fully trusted system classes. This method overrides the java.lang.SecurityManager.checkRead(FileDescriptor) method.

Exceptions:

SecurityException if the security check fails.

checkRegistry

public void checkRegistry (int access, String value);

Determines whether classes within the current execution context, based on the call stack of the current thread, are allowed to perform the specified access to the specified portion of the registry.

Return Value:

No return value.

ParameterDescription
access The access type.
value The registry key.

Remarks:

The check succeeds only if all the classes found on the call stack possess RegistryPermissions, and if those permissions allow the specified access type onto the specified portion of the registry.

Exceptions:

SecurityException if the security check fails.

See Also: com.ms.lang.RegKey

checkSecurityAccess

public void checkSecurityAccess(String provider);

Determines if classes within the current execution context, based on the call stack of the current thread, are allowed to perform a security provider-related operation (using the java.security classes).

The check succeeds only if all the classes found on the call stack possess SecurityPermissions. This method overrides the java.lang.SecurityManager.checkSecurityAccess(String) method.

Note This check is used by the JDK security-related APIs within the java.security classes. It is not directly relevant to the Microsoft® security model.

Return Value:

No return value.

ParameterDescription
provider This parameter is ignored.

checkSetFactory

public void checkSetFactory();

Determines whether classes within the current execution context, based on the call stack of the current thread, are allowed to install a networking object factory.

Return Value:

No return value.

Remarks:

The check succeeds only if all the classes found on the call stack are fully trusted. This method overrides the java.lang.SecurityManager.checkSetFactory method.

Exceptions:

SecurityException if the security check fails.

checkSystemClipboardAccess

public void checkSystemClipboardAccess();

Determines whether classes within the current execution context, based on the call stack of the current thread, are allowed to access the system Clipboard.

Return Value:

No return value.

Remarks:

The check succeeds only if all the classes found on the call stack possess UIPermissions, and if those permissions allow access to the system Clipboard. This method overrides the java.lang.SecurityManager.checkSystemClipboardAccess method.

Exceptions:

SecurityException if the security check fails.

checkSystemStreams

public void checkSystemStreams(int streamID);

Determines if classes within the current execution context, based on the call stack of the current thread, are allowed to set the specified system stream.

Return Value:

No return value.

ParameterDescription
streamID The system stream to set. The value must be one of the following:
0
Indicates an attempt to set System.in using System.setIn.
1
Indicates an attempt to set System.out using System.setOut.
2
Indicates an attempt to set System.err using System.setErr.

Remarks:

The check succeeds only if all the classes found on the call stack possess SystemStreamsPermissions, and if those permissions allow the specified stream to be modified.

This security check is called by the java.lang.System APIs that set system streams using the System.setIn, System.setOut, and System.setErr methods.

Exceptions:

SecurityException if the security check fails.

checkTopLevelWindow

public boolean checkTopLevelWindow(Object window);

Determines if classes within the current execution context, based on the call stack of the current thread, are allowed to create top-level windows.

Return Value:

Returns false if top-level window creation is allowed and a top-level window requires a warning banner; otherwise, returns true.

ParameterDescription
window The top-level window.

Remarks:

The check succeeds only if all the classes found on the call stack possess UIPermissions, and if all those permissions allow the creation of top-level windows. If top-level window creation is not allowed, a SecurityException is thrown.

If top-level window creation is allowed, this check determines whether the top-level window for each calling class requires no warning banner. No warning banner is required if all the UIPermission objects associated with the calling classes specify that no warning banners are necessary.

This method overrides the java.lang.SecurityManager.checkTopLevelWindow method.

Exceptions:

SecurityException if the security check fails.

checkWrite

public void checkWrite(String file);

Determines whether the specified file can be written to by the classes active within the current execution context.

The check succeeds only if all of the classes found on the call stack possess FileIOPermissions and if those permissions allow write access to the specified file. This method overrides the java.lang.SecurityManager.checkWrite(String) method.

Return Value:

No return value.

ParameterDescription
file The system-dependent filename.

Exceptions:

SecurityException if the security check fails.

checkWrite

public void checkWrite (FileDescriptor fd);

Determines whether classes within the current execution context, based on the call stack of the current thread, can use the specified FileDescriptor object to write to the file it is associated with.

Return Value:

No return value.

ParameterDescription
fd The file descriptor that is associated with the file.

Remarks:

The check succeeds only if all the classes found on the call stack are fully trusted system classes. This method overrides the java.lang.SecurityManager.checkWrite(FileDescriptor) method.

Exceptions:

SecurityException if the security check fails.

getSecurityContext

public Object getSecurityContext();

Retrieves the codebase URL associated with the nearest SecurityClassLoader instance found on the call stack. The SecurityClassLoader instance is found by examining the classes associated with each stack frame, and then examining the class loader associated with each class.

Return Value:

Returns the URL associated with the nearest SecurityClassLoader instance.

getThreadGroup

public ThreadGroup getThreadGroup();

Determines the active thread group based on the current execution context.

Return Value:

Returns the active thread group.

Remarks:

This method overrides the java.lang.SecurityManager.getThreadGroup method. This method is called by the constructors of the java.lang.Thread class. Its purpose is to ensure that new threads are created in the thread group associated with the active code instead of in the thread group of the current thread.

To understand why this scheme is useful, consider the AWT event dispatch thread, which is a system thread that lives in the system thread group. If an applet creates a new thread while executing code on the dispatch thread, the new thread will be created in the thread group associated with that applet. If, instead, an attempt had been made to create the thread in the system thread group, it is likely that the attempt would have failed because the applet code probably does not have access rights to the system thread group.

The algorithm for determining the active thread group is as follows.

  1. Based on the classes associated with each stack frame on the call stack, locate the nearest SecurityClassLoader instance.
  2. If no SecurityClassLoader is found, the active thread group is simply the thread group of the current thread, as follows.
    
    Thread.currentThread().getThreadGroup()
    
  3. Otherwise, a SecurityClassLoader instance was found. If the thread group of the current thread is a child of the thread group associated with that loader, return it. otherwise, return the thread group associated with the loader.

installStandardSecurity

public static void installStandardSecurity();

Creates a new StandardSecurityManager and installs it as the active security manager.

Return Value:

No return value.

Exceptions:

SecurityException if a security manager is already installed.

upnrm.gif © 1998 Microsoft Corporation. All rights reserved. Terms of use.