Microsoft SDK for Java

assertPermission

This method of the PolicyEngine Class asserts the right to a certain type of permission. This method causes the security system to ignore your callers when you cause a security check of the asserted type to occur.

Syntax

public static native void assertPermission(PermissionID pid);

Parameters

pid The type of permission to assert.

Remarks

Normally, when checking a given permission, the security system examines every frame on the call stack to ensure that all the callers possess the ability to perform the operation in question. However, if the security system sees a stack frame where the requested permission has been asserted (with this method), the stack crawl stops early and the security check succeeds.

The asserted permission state disappears when the stack frame of the caller to assertPermission exits (by executing a return statement or throwing an exception). The revertPermission method can be used to un-assert a permission type.

The following example shows how to assert the right to perform file I/O operations:

Example

   ...
   // Assert the right to perform file I/O
   PolicyEngine.assertPermission(PermissionID.FILEIO);

   // Now, do some file operation. Since you have asserted
   // your rights to file I/O, this check will succeed even if your callers do
   // not possess the ability to perform file I/O.
   FileInputStream fis = new FileInputStream("c:\\MySample.txt");
   ...

Note   To assert all permissions, pass PermissionID.SYSTEM to the assertPermission method. This assertion forces the security system to ignore your callers during all security checks. Only fully trusted code can assert the SYSTEM permission.

See Also

denyPermission, revertPermission

© 1999 Microsoft Corporation. All rights reserved. Terms of use.