Packages
 In this topic

*Constructors

*Methods

*Fields

 

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

 


Class ReflectionPermission

public class ReflectionPermission implements IPermission, 
            IEncodablePermission, IAdjustablePermission
{
  // Fields
  public static int ALL;
  public static int DIFFERENTLOADER;
  public static int NONE;
  public static int SAMELOADER;
  public static int SYSTEMLOADER;

  // Constructors
  public ReflectionPermission();

  // Methods
  public void adjustPermission (String tag, Object adjustment);
  public void check(Object param);
  public IPermission combine (IPermission source2);
  public int compareSet(Object target);
  public IPermission copy();
  public boolean decode(String tag, InputStream data);
  public boolean encode(String tag, OutputStream out);
  public int getAllowedAccess(int accessType);
  public int getAllowedDeclaredAccess();
  public int getAllowedPublicAccess();
  public ClassLoader getAssociatedLoader();
  public String mapFormat(String format);
  public void reset();
  public void setAllowedDeclaredAccess(int loadertypes);
  public void setAllowedPublicAccess(int loadertypes);
  public void setAssociatedLoader(ClassLoader ldr);
  public String[] supportedFormats();
  public String toString();
}

This class represents a permission that controls the ability to perform reflection operations. The StandardSecurityManager checks for this permission type when performing the checkMemberAccess operation.

A ReflectionPermission distinguishes between two different types of reflection operations:

Public
Reflective access to a public member of some class. This type of access is specified by the constant java.lang.reflect.Member.PUBLIC.
Declared
Reflective access to any member of a given class. This type of access is specified by the constant java.lang.reflect.Member.DECLARED.

A ReflectionPermission object further distinguishes between types of reflection operations, depending on the type of class being reflected. The types of classes that can be reflected are as follows:

SAMELOADER
A class from the same loader as the class initiating the reflection operation.
DIFFERENTLOADER
A non-system class from a loader other than that of the class that is initiating the reflection operation.
SYSTEMLOADER
A System class.

Also see com.ms.security.permissions.ReflectionRequest

Constructors

ReflectionPermission

public ReflectionPermission();

Creates a new ReflectionPermission instance. The new instance does not allow reflective access to any classes.

Methods

adjustPermission

public void adjustPermission (String tag, Object adjustment);

Adjusts the permission object with some runtime state. The ReflectionPermission only responds to the "classloader" adjustment type. This method expects the adjustment parameter to be a ClassLoader instance. All other adjustment types are ignored. The class loader instance used for the adjustment parameter is the loader that SAMELOADER will refer to after this method adjusts the class loader.

Note The "classloader" adjustment to this permission is equivalent to an explicit setAssociatedLoader call.

Return Value:

No return value.

ParameterDescription
tag The adjustment type. Every value except "classloader" is ignored.
adjustment This parameter must be an instance of java.lang.ClassLoader for the "classloader" tag.

check

public void check(Object param);

Determines whether the permission object allows the specified action. The request parameter represents a request to perform a particular action. The type of the parameter depends on the type of the permission object.

Return Value:

No return value.

ParameterDescription
param The object that represents the action for which permission is being checked.

Exceptions:

SecurityException if the state of the permission object indicates that the action is not allowed.

combine

public IPermission combine (IPermission source2);

Creates and returns a new ReflectionPermission object that is a combination of the current permission object and the specified permission object. The new object allows access to exactly those resources allowed by either one of the permission objects that it was constructed from.

Return Value:

Returns the resulting ReflectionPermission object.

ParameterDescription
source2 The permission object that indicates additional resources to allow access to.

compareSet

public int compareSet(Object target);

Compares the ReflectionPermission instance with a specified permission object

Return Value:

Returns one of the following constants:

ParameterDescription
target The permission object that the ReflectionPermission instance is compared with.

copy

public IPermission copy();

Retrieves a copy of the ReflectionPermission instance.

Return Value:

Returns the copy of the ReflectionPermission instance.

decode

public boolean decode(String tag, InputStream data);

Decodes a source according to the specified tag. This method implements the IEncodablePermission.decode method.

Return Value:

Returns true if the decoding process is completed successfully; otherwise, returns false.

ParameterDescription
tag The tag used for the decoding. It is the same tag that was used to encode the data.
data The stream that contains the encoded permission.

encode

public boolean encode(String tag, OutputStream out);

Encodes a source according to the specified tag. This method implements the IEncodablePermission.encode method.

Return Value:

Returns true if the encoding process is completed successfully; otherwise, returns false.

ParameterDescription
tag The string that indicates how to encode the data.
out The stream to write the encoded data to.

getAllowedAccess

public int getAllowedAccess(int accessType);

Retrieves the types of classes that the permission object allows access to, based on a reflective access type.

Return Value:

Returns the types of classes that the permission object allows access to. This will be one of the following: SAMELOADER, DIFFERENTLOADER, SYSTEMLOADER, ALL, or NONE.

ParameterDescription
accessType The reflective access type. It must be either java.lang.reflect.Member.PUBLIC or java.lang.reflect.Member.DECLARED.

Exceptions:

IllegalArgumentException if the accessType parameter is not equal to java.lang.reflect.Member.PUBLIC or java.lang.reflect.Member.DECLARED.

getAllowedDeclaredAccess

public int getAllowedDeclaredAccess();

Retrieves the types of classes that the permission object allows declared access to.

Return Value:

Returns the types of classes that the permission object allows declared access to. This will be one of the following: SAMELOADER, DIFFERENTLOADER, SYSTEMLOADER, ALL, or NONE.

getAllowedPublicAccess

public int getAllowedPublicAccess();

Retrieves the types of classes that the permission object allows public access to.

Return Value:

Returns the types of classes that the permission object allows public access to. This will be one of the following: SAMELOADER, DIFFERENTLOADER, SYSTEMLOADER, ALL, or NONE.

getAssociatedLoader

public ClassLoader getAssociatedLoader();

Retrieves the class loader associated with this permission object.

Return Value:

Returns the class loader associated with the permission object.

mapFormat

public String mapFormat(String format);

Retrieves a permission-specific tag when given an encoding format. The tag can be used with the encode and decode methods to specify an encoding type. This method implements the IEncodablePermission.mapFormat method.

Return Value:

Returns the tag used to encode the data in the given format. If the specified format is not supported, null is returned.

ParameterDescription
format The format that the tag is requested for. If format is null, the default format for the class is returned.

reset

public void reset();

Resets the permission object to a state in which it allows no reflection access.

Return Value:

No return value.

setAllowedDeclaredAccess

public void setAllowedDeclaredAccess(int loadertypes);

Sets the types of classes that the permission object allows declared reflective access to. The classes are specified by the loader types.

For example, the following code indicates that the permission should only allow declared reflective access to classes from the same loader.


    ...
    ReflectionPermission perm = new ReflectionPermission();
    perm.setAssociatedLoader( some loader );
    perm.setAllowedDeclaredAccess(ReflectionPermission.SAMELOADER);
    ...

Return Value:

No return value.

ParameterDescription
loadertypes The types of classes that the permission object will allow declared reflective access to. This should be one of the following types: SAMELOADER, DIFFERENTLOADER, SYSTEMLOADER, ALL, or NONE.

setAllowedPublicAccess

public void setAllowedPublicAccess(int loadertypes);

Sets the types of classes that the permission object allows public reflective access to. The classes are specified by the loader types.

For example, the following code indicates that the permission should allow reflective access to public members of all classes.


    ...
    ReflectionPermission perm = new ReflectionPermission();
    perm.setAllowedPublicAccess(ReflectionPermission.ALL);
    ...

Return Value:

No return value.

ParameterDescription
loadertypes The types of classes that the permission object allows public reflective access to. This should be one of the following types: SAMELOADER, DIFFERENTLOADER, SYSTEMLOADER, ALL, or NONE.

setAssociatedLoader

public void setAssociatedLoader(ClassLoader ldr);

Sets the class loader that this permission is associated with. The associated class loader should be the class loader that loaded the classes that this permission will be assigned to. The loader access type SAMELOADER refers to the class loader set by this method.

Return Value:

No return value.

ParameterDescription
ldr The class loader object.

supportedFormats

public String[] supportedFormats();

Retrieves a list of supported formats. This method implements the IEncodablePermission.supportedFormats method.

Return Value:

Returns the supported formats.

toString

public String toString();

Converts the permission object to its string representation.

Return Value:

Returns the string representation of the permission object.

Fields

ALL
A loader type that indicates all classes.
DIFFERENTLOADER
A loader type that refers to any loaders other than the one associated with this permission instance. If no loader has been associated with this permission, this loader type refers to all non-system classes.
NONE
A loader type that indicates no classes.
SAMELOADER
A loader type that refers to the loader that has been associated with this permission object with the setAssociatedLoader method. If no loader has been associated with this permission instance, this loader type has no meaning.
SYSTEMLOADER
A loader type that indicates system classes.

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