Skip to main content

Requires (Method Keyword)

Specifies a list of privileges a user or process must have to call this method.

Usage

To specify that this method should be restricted to users or processes that have the specified privileges, use the following syntax:

Method name(formal_spec) As returnclass [ Requires = privilegelist ] 
{    //implementation } 

Where privilegelist is either a single privilege or a comma-separated list of privileges, enclosed in quotation marks. Each privilege takes the form resource:permission, where permission is Use, Read, or Write (or the single-letter abbreviations U, R, or W).

To specify multiple permissions for one resource, use the single-letter abbreviations.

Details

The user or process must have all of the privileges in the list of privileges in order to call the method. Calling the method without the specified privileges results in a <PROTECT> error.

If a method inherits the Requires keyword from a superclass, you can add to the list of required privileges by setting a new value for the keyword. You cannot remove required privileges in this manner.

Default

If you omit this keyword, no special privileges are required to call this method.

Examples

The method below requires Read permission to the Sales database and Write permission to the Marketing database. (Note that if a database has Write permission, it automatically has Read permission.)

ClassMethod UpdateTotalSales() [ Requires = "%DB_SALES: Read, %DB_MARKETING: Write" ]
{
   set newSales = ^["SALES"]Orders
   set totalSales = ^["MARKETING"]Orders
   set totalSales = totalSales + newSales
   set ^["MARKETING"]Orders = totalSales
}

To specify multiple permissions for one resource, use the single-letter abbreviations. The two methods below are functionally equivalent:

ClassMethod TestMethod() [ Requires = "MyResource: RW" ]
{
   write "You have permission to run this method"
}

ClassMethod TestMethodTwo() [ Requires = "MyResource: Read, MyResource: Write" ]
{
   write "You have permission to run this method"
}

See Also

FeedbackOpens in a new tab