Custom Permissions Sample

This sample is located in \Samples\Security\Custom.

Description
Using the Sample
Key Project Files
Technologies Demonstrated

Description

This sample shows how to set custom permissions to protect resources that are not described by the stock permissions in com.ms.security.permissions.

To implement custom permissions, you must do the following:

  1. Define what the permission will protect and write an implementation of IPermission.

  2. Perform security checks for the custom permission in the code that accesses the resources the permission will protect

  3. If the permission will be used for signing, write an implementation of IEncodablePermission.

  4. If a request object for access to the custom permission can provide additional details that may be useful to an auditor, write an implementation of ISecurityAuditInfo. Additional registry keys must be set when the library is installed to indicate where the auditing messages are located.

  5. Sign and package the custom permission classes as system code to be installed with the library. (Only system classes may define permissions.)

Using the Sample

To compile the sample

Use the following command from the \Samples\Security\Custom directory to compile and install the sample:

nmake

install.bat

To run the sample

Use the following command from the \Samples\Security\Custom directory to run the sample:

start custom_permissions_app.htm

Key Project Files

baseperms.javacustomperms.ini

These files are used by the makefile to set the custom permissions.

Main.java

This file is the main applet that demonstrates the security features.

SampleLib.java

This class contains a static method that checks permissions on an item and writes the result to standard output.

SamplePermission.java

This is a sample permission that implements IPermission; used in Main.java.

SampleRequest.java

This file implements ISecurityRequest; used by SamplePermission.

Technologies Demonstrated

Security

This sample shows how to:

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