Skip to main content

Code for Privileged Routine Example

Here is the code for the privileged routine example. Create the class using your IDE.

Class SecurityTutorial.PrivilegedRoutineExample

ClassMethod PrivilegedRoutineEx(){

    Write !, "Welcome to the Privileged App Routine"
    Write !, "User before: ", $USERNAME
    Write !, "Roles before: ", $ROLES

    New $ROLES
    Set status=$System.Security.AddRoles("MyPrivilegedRoutineApplication")

    Write !, "User after: ", $USERNAME
    Write !, "Roles after: ", $ROLES


The code does the following:

  1. Writes the user's user name and roles when the user enters the routine.

  2. Declares a new $ROLES variable within the local environment of the routine. Issuing this command before invoking AddRoles() to add application roles is important: it ensures that exiting the routine revokes those changes and restores the user’s original login roles.

  3. Uses $SYSTEM.Security.AddRoles to add the user to additional roles. Note that MyPrivilegedRoutineApplication is the name of the privileged routine application. It is not the name of any role. The user is added to roles listed as Application Roles for the privileged routine application.

  4. Writes the user's user name and roles again to show the changes in the roles.

FeedbackOpens in a new tab