Sun Java logo     Previous      Contents      Index      Next     

Sun logo
Sun Java[TM] System Identity Manager 7.0 Deployment Tools 

Chapter 2
Working with Rules

This chapter introduces Identity Manager rules and rules libraries, and describes how to implement rules and rule libraries in forms, roles, and workflows.

This chapter is organized into the following sections:


Note

You use the Sun Identity Manager Integrated Development Environment (Identity Manager IDE) to create, edit, and test rules for your deployment.

See Chapter 1, "Using the Identity Manager IDE" for an introduction to the Identity Manager IDE interface and for the detailed instructions you need to create and edit rules.

You can also use the Identity Manager Business Process Editor (BPE) application to create, edit, and validate rules. See Appendix A, "Using the Business Process Editor" for instructions.



Understanding Identity Manager Rules

This section covers the following introductory topics:

What is a Rule?

A rule is an object in the Identity Manager repository that contains a function written in the XPRESS, XML Object, or JavaScript languages. Within Identity Manager, rules provide a mechanism for storing frequently used logic or static variables for reuse within forms, workflows, and roles.

Arguments can be passed to a rule to control its behavior, and a rule can reference and modify variables maintained by the form or workflow.

Because simple rules are most commonly written in XML, the examples in this chapter will use the XPRESS or XML Object languages.


Note

Both XPRESS and XML Object are written in XML, so their code examples in this chapter look alike.

This chapter assumes you are familiar with the XPRESS language. For detailed information about using XPRESS, see Sun Java™ System Identity Manager Workflows, Forms, and Views.

For information about writing rules in JavaScript, see Writing Rules in JavaScript.


Example Rule

Code Example 2-1 contains a simple XML rule. The rule name is defined by the name attribute in the <Rule> element, and it returns the string value john or mary. The rule body is an XPRESS expression within the <Rule> element.

Code Example 2-1  XML Rule

<Rule name='getApprover'>
   <cond><eq><ref>department></ref><s>sales</s></eq>
      <s>john</s>
      <s>mary</s>
   </cond>
</Rule>

Why Use Rules?

You can call a rule wherever XPRESS is allowed — most notably in workflow and forms. Rules allow you to encapsulate a fragment of logic or a static value that can then be reused in many locations.

The benefits of saving XPRESS logic or static values for reuse include:

Using Rules in Forms

You typically call a rule in forms to calculate the allowedValues display property or to control field visibility within a <Disable> expression. Within forms, rules could be the most efficient mechanism for storing and reusing:

When calling rules from forms, it is particularly important that you properly secure those forms. For information about securing rules, see Securing Rules.

Sample Scenario: Forms

The rule in Code Example 2-2 returns a list of job titles. Rules such as this are often used in Identity Manager forms to calculate lists of names for selection. To add or change a new Job Title, you only need to modify this rule instead of having to modify all of the forms that reference the rule.

Code Example 2-2   Rule to Return a Job Titles List

<Rule name='Job Titles'>
   <list>
      <s>Sales</s>
      <s>Accounting Manager</s>
      <s>Customer Service Representative</s>
   </list>
</Rule>

The field in Code Example 2-3 calls the rule defined in the preceding example to use the job titles list in a select box:

Code Example 2-3   Rule to Use the Job Titles List in a Select Box

<Field name='global.jobTitle'>
   <Display class='Select'>
      <Property name='title' value='Job Title'/>
      <Property name='allowedValues'>
         <rule name='Job Titles'/>
      </Property>
   </Display>
</Field>


Note

The rule name element in the preceding code uses a lowercase r because it is used to call the rule, not define it.


Using Rules in Workflows

In workflow, you can use a rule to:

Sample Scenario: Workflow

The following manual action is used to send an approval request to an administrator. The action can have a timeout value. If the administrator does not respond within the specified time, the action terminates, and the workflow can escalate the approval to a different administrator.

In the following rule, the timeout is specified with a fixed value of 86,400 seconds or 24 hours.

Code Example 2-4   Timeout Specified with a Fixed Value

<Rule name='Approval Timeout'>
<i>86400</i>
</Rule>

The following manual action calls the timeout rule:

Code Example 2-5  Calling timeout Rule

<ManualAction>
   <Owner name='$(approver)'/>
   <Timeout>
      <rule name='Approval Timeout'/>
   </Timeout>
   <FormRule>
      <ref>approvalForm</ref>
   </FormRule>
</ManualAction>

Using Rules in Roles

You can use rules to set the value of any resource attribute in a role definition. When the rule is evaluated, it can reference any attribute of the user view.

Sample Scenario: Roles

The rule in Code Example 2-6 sets a value for the user's description of a resource, such as NT. When a user is created with a role that has this rule associated with it, the description value will automatically be set according to the rule.

Code Example 2-6   Setting the Value for a User’s Resource Description

<Rule name='account description'>
    <concat>
      <s>Account for </s>
      <ref>global.firstname</ref>
      <ref>global.lastname</ref>
      <s>.</s>
    </concat>
</Rule>

Dynamically Calculating the Name of the Rule

Identity Manager forms and workflow support rules that can dynamically calculate the name of another rule to call. Code Example 2-7 shows a form field that calls a rule that calculates a department code:

Code Example 2-7  Calling a Rule that Calculates a Department Code

<Field name='DepartmentCode'>
   <Display class='Text'>
     <Property name='title' value='DepartmentCode'/>
   </Display>
     <Expansion>
        <rule>
          <cond>
            <eq>
               <ref>var1</ref>
               <s>Admin</s>
            </eq>
            <s>AdminRule</s>
            <s>DefaultRule</s>
          </cond>
        </rule>
     </Expansion>
</Field>

Workflow activities can also contain subprocesses that contain a rule that dynamically calculates the subprocess name:

Code Example 2-8  Dynamically Calculating the Subprocess Name

<Activity id='0' name='activity1'>
   <Variable name='ValueSetByRule'>
     <rule>
       <cond>
          <eq><ref>var2</ref><s>specialCase</s></eq>
          <s>Rule2</s>
          <s>Rule1</s>
       </cond>
       <argument name='arg1'>
          <ref>variable</ref>
       </argument>
     </rule>
   </Variable>
</Activity>


Developing Rules

This section describes how to develop rules for your deployment, and provides the following information:

Understanding Rule Syntax

Rules are typically written in XML and encapsulated in the <Rule> element.

This section covers the following topics:

Using the <Rule> Element

Code Example 2-9 shows the use of the <Rule> element to define a basic rule expression. The name property identifies the name of the rule. The rule is written in XPRESS.

Code Example 2-9  Using a <Rule> element to Define a Basic Rule Expression

<Rule name='getApprover'>
   <cond><eq><ref>department></ref><s>sales</s></eq>
      <s>Sales Manager</s>
      <s>HR Manager</s>
   </cond>
</Rule>

Returning Fixed Values

If the rule returns a fixed value, you can write it using XML Object syntax.
Code Example 2-10 returns a list of strings.

Code Example 2-10  Rule Returning a List of Strings

<Rule name='UnixHostList'>
   <List>
      <String>aas</String>
      <String>ablox</String>
      <String>aboupdt</String>
   </List>
</Rule>


Note

For more information about XML Object syntax, see the XML Object Language chapter in Sun Java™ System Identity Manager Workflows, Forms, and Views.


Referencing Variables

Rules are allowed to reference the value of external variables with a <ref> expression. The names of the available variables are determined by the context in which the rule is used. When used within forms, any form field, view attribute, or variable defined with <defvar> can be referenced. When used within workflow, any variable defined within the workflow process can be referenced.

In Code Example 2-11, a form uses a rule to calculate an email address. The form defines the fields global.firstname and global.lastname, and the rule references them. The email address is calculated by concatenating the first letter of global.firstname with global.lastname and the string @waveset.com.

Code Example 2-11  Using a Rule to Calculate an Email Address

<Rule name='Build Email'>
   <concat>
      <substr> <ref>global.firstname</ref> <i>0</i> <i>1</i> </substr>
      <ref>global.lastname</ref>
      <s>@waveset.com</s>
   </concat>
</Rule>

In Code Example 2-12, a workflow uses a rule to test whether a transition to a particular activity should be taken. The workflow defines a variable named user that contains the User View. The rule returns true if this user has any NT resources assigned to them or null if no NT resources are assigned. The workflow engine interprets null as false and would consequently not take the transition.

Code Example 2-12  Using a Rule to Test a Transition

<Rule name='Has NT Resources'>
   <notnull>
      <ref>user.accountInfo.types[NT].accounts</ref>
   </notnull>
</Rule>

Declaring a Rule with Arguments

Though rules are not required to declare arguments, it is considered good practice to do so. Declaring arguments provides documentation to the rule author, allows reference validation in the Identity Manager IDE, and allows the rule to be used in forms and workflows that may not use the same naming convention.

To declare rule arguments, use the <RuleArgument> element. The argument can have a default value set by specifying a value after the argument name as shown in the following location argument.

Code Example 2-13  Setting a Default Value

<Rule name='description'>
   <RuleArgument name='UserId'/>
   <RuleArgument name='location' value='Austin'/>
   <concat>
      <ref>UserId</ref>
      <s>@</s>
      <ref>location</ref>
   </concat>
</Rule>


Note

When defining a rule, use the <Rule> element that has an uppercase R as in <Rule name='rulename'>. When calling a rule, the XPRESS <rule> element has a lowercase r, as in <rulename='rulename'>.


You can use this rule in a user form, but UserId and location are not attributes of the user view. To pass the expected arguments into the rule the <argument> element is used in the rule call. Note that passing an argument whose name is location will override the default value declared in the RuleArgument element.

Code Example 2-14  Overriding Default Value Declared in RuleArgument

<rule name='description'>
   <argument name='UserId' value='$(waveset.accountId)'/>
   <argument name='location' value='global.location'/>
</rule>

For more information about calling rules, see Referencing Rules.

There is no formal way to declare argument type, but you can specify type in a comment field. Use the <Comment> element to include comments in your rule:

Code Example 2-15  Using <Comment> to Include Comments in a Rule

<Comments>
Description rule is expecting 2 arguments. A string value
UserId, which is the employees’ ID number, and a string
value location that describes the building location for
the employee
</Comments>


Tip

If you are using the Identity Manager IDE to edit rules, you might find it helpful to formally define a list of rule arguments. This list would consist of the names of variables that are expected to be available to the rule. You can use them afterwards to perform validation in the Identity Manager IDE.


Rules with Side Effects

Rules typically return a single value, but in some cases you may want a rule to return several values. While a rule expression can return only a single value, a rule can assign values to external variables with the following XPRESS expressions:

In Code Example 2-16, the rule tests the value of the external variable named department and assigns values to two other variables.

Code Example 2-16  Testing the department Variable and Assigning Values to Other Variables  

<Rule name='Check Department'>
    <switch>
      <ref>global.department</ref>
      <case>
        <s>Engineering</s>
        <block>
          <setvar name='global.location'>
            <s>Building 1</s>
          </setvar>

          <setvar name='global.mailServer'>
            <s>mailserver.somecompany.com</s>
          </setvar>

        </block>
      </case>

      <case>
        <s>Marketing</s>
        <block>
          <setvar name='global.location'>
            <s>Building 2</s>
          </setvar>          <setvar name='global.mailServer'>
            <s>mailserver2.somecompany.com</s>
          </setvar>
        </block>
      </case>
    </switch>
</Rule>

In the preceding example, the variables global.location and global.mailServer are both set according to the value of the variable department. In this case, the return value of the rule is ignored, and the rule is called only for its side effects.

Writing Rules in JavaScript

When rules become complex, you may find it more convenient to write those rules in JavaScript rather than XPRESS. You can wrap the JavaScript in a <script> element. For example,

Code Example 2-17  Wrapping JavaScript in a <script> Element

<Rule name='Build Email'>
   <script>
      var firstname = env.get('firstname');
      var lastname = env.get('lastname');
      var email = firstname.substring(0, 1) + lastname + "@waveset.com";
      email;
   </script>
</Rule>

To reference the values of form and workflow variables, call the env.get function and pass the variable name. You can use the env.put function to assign variable names. The value of the last statement in the script becomes the value of the rule. In the preceding example, the rule will return the value in the email variable.

You can call other rules with the env.call function.

Using Default Rules and Rule Libraries

You can use the Identity Manager IDE to edit the default Identity Manager rules to follow a custom set of steps. Identity Manager ships with a library of default rules and rule libraries, including:

Auditor Rules

Identity Manager provides rules to use for Periodic Access Reviews and other identity auditing features. These rules are specified when defining an access scan.

Attestor Rule

The Attestor Rule determines the list of users who are responsible for attesting a particular user entitlement.

The rule accepts the following input variables:

You must specify the following for a custom attestor rule:

Identity Manager provides a pre-defined rule, the Default Attestor rule. This rule returns the idmManager of the user that the entitlement record represents. If the idmManager value is null, it returns Configurator.

Attestation Escalation Rule

The Attestation Escalation Rule determines where to route the escalated attestation request to after a specified period for responding has expired.

The rule accepts the following input variables:

You must specify the following for a custom Attestation Escalation rule:

Identity Manager provides a pre-defined rule, the Default Escalation Attestor rule. This rule returns the attestor’s manager, or if none, it returns Configurator.

Review Determination Rule

The access review process evaluates the Review Determination Rule to determine if a user entitlement can be automatically approved, automatically rejected, or must be manually attested.

This rule accepts the following input variables:

You must specify the following for a custom review determination rule:

Identity Manager provides the following pre-defined implementation of this rule:

User Scope Rule

The User Scope Rule provides several options for scoping the users to be included in an access review. One of the options is the According to attribute condition rule. Identity Manager provides the following pre-defined implementation of this rule:

You must specify the following for a custom review determination rule:

Active Sync Rules

When an Active Sync adapter detects a change to an account on a resource, it either maps the incoming attributes to an Identity Manager user, or it creates an Identity Manager user account.


Note

Active Sync rules must use context, not display.session.


Table 2-1 lists the predefined Active Sync rules.

Table 2-1  Predefined Active Sync Rules

Rule Name

Description

ActiveSync has isDeleted set

Used by migration from resources with “Process deletes as updates” set to false.

No Correlation Rule

Default rule to use when no correlation is desired.

No Confirmation Rule

Default rule to use when no confirmation is desired.

AlphaNumeric Rules

A default library of alphanumeric rules enables you to control how numbers and letters are ordered and displayed in Identity Manager forms and workflows. In the Identity Manager IDE, this library is displayed as the Alpha Numeric Rules library object.

Table 2-2 lists the rules in this library.

Table 2-2  Default Alphanumeric Rules

Rule Name

Description

AlphaCapital

List of English uppercase alphabetic characters

AlphaLower

List of English lowercase alphabetic characters

Numeric

List of numeric characters

WhiteSpace

List of white space characters

SpecialCharacters

List of common special characters

IllegalNTCharacters

List of illegal NT characters

legalEmailCharacters

Tests to see if str is all numeric characters.

isNumeric

Tests to see if str is only numeric

isAlpha

Tests to see if str is only alpha

hasSpecialChar

Tests to see if str has any special characters

hasWhiteSpace

Tests to see if str has any white space characters

isLegalEmail

Tests to see is str contains legal characters for an email address

hasIllegalNTChar

Tests to see is str is all numeric characters

stringToChars

Converts the supplied string (passed as a testStr argument) to a list of its component characters.

StripNonAlphaNumeric

Removes any nonalphanumeric characters from testStr

Excluded Resource Accounts Rule Subtype

The ExcludedAccountRule subtype supports the exclusion of resource accounts from resource operations.

This rule has the following parameters:

You can compare the accountID parameter to one or more resource accounts that should be excluded from Identity Manager. In addition, the rule can use the operation parameter to have finer control over which resource accounts are exempt from the actions specified by the operation parameter.

The operation parameter can contain the following values:

If the operation parameter is not used within the rule, all accounts identified by the rule will be excluded from all the listed operations.

Sample Rules

Code Example 2-18 exemplifies subtype use, and it excludes specified resource accounts for UNIX adapters.

Code Example 2-18  Rule Exemplifying Subtype Use

<Rule name='Excluded Resource Accounts' authType='ExcludedAccountsRule'>
   <RuleArgument name='accountID'/>
   <defvar name 'excludedList'>
      <List>
         <String>root</String>
         <String>daemon</String>
         <String>bin</String>
         <String>sys</String>
         <String>adm</String>
         <String>uucp</String>
         <String>nuucp</String>
         <String>listen</String>
         <String>lp</String>
      </List>
   </defvar>
   <cond>
      <eq>
         <contains>
            <ref>excludedList</ref>
            <ref>accountID</ref>
         </contains>
         <i>1</i>
      </eq>
      <Boolean>true</Boolean>
      <Boolean>false</Boolean>
   </cond>
</Rule>

Code Example 2-19 illustrates the use of the operation parameter.
This parameter allows the “Test User” resource account to be manipulated — without impacting Identity Manager — if Active Sync is running against the resource.

Code Example 2-19  Using the operation Parameter

<Rule name='Example Excluded Resource Accounts' authType='ExcludedAccountsRule'>

<!--
Exclude all operations on 'Administrator' account
Exclude activeSync events on 'Test User' account
-->

   <RuleArgument name='accountID'/>
   <RuleArgument name='operation'/>

<!-- List of IAPI Operations -->
   <defvar name='iapiOperations'>
      <List>
         <String>iapi_create</String>
         <String>iapi_update</String>
         <String>iapi_delete</String>
      </List>
   </defvar>
   <or>

   <!-- Always ignore the administrator account. -->
      <cond>
         <eq>
            <s>Administrator</s>
            <ref>accountID</ref>
         </eq>
         <Boolean>true</Boolean>
         <Boolean>false</Boolean>
      </cond>

<!-- Ignore IAPI events for the 'Test User' account -->
      <and>
         <cond>
            <eq>
               <contains>
                  <ref>iapiOperations</ref>
                  <ref>operation</ref>
               </contains>
               <i>1</i>

            </eq>
            <Boolean>true</Boolean>
            <Boolean>false</Boolean>
         </cond>

         <cond>
            <eq>
               <ref>accountID</ref>
               <s>Test User</s>
            </eq>
            <Boolean>true</Boolean>
            <Boolean>false</Boolean>
         </cond>
      </and>
   </or>
</Rule>

Naming Rules Library

A default library of naming rules enables you to control how names are displayed after rule processing. In the Identity Manager IDE, this library is displayed as the NamingRules library object.

Table 2-3 lists the default naming rules.

Table 2-3  Default Naming Rules  

Rule Name

Description/Output

AccountName — First dot Last

Marcus.Aurelius

AccountName — First initial Last

MAurelius

AccountName — First underscore Last

Marcus_Aurelius

Email

marcus.aurelius@sun.com

Fullname — First space Last

Marcus Aurelius

Fullname — First space MI space Last

Marcus A Aurelius

Fullname — Last comma First

Aurelius, Marcus

RegionalConstants Library

A default library of regional constants rules enables you to control how states, days, months, countries, and provinces are displayed. In the Identity Manager IDE, this library is displayed as the RegionalConstants Rules library object.

Table 2-4  Default Regional Constants Rules

Rule Name

Description

US States

List of the full names of the US states

US State Abbreviations

List of the standard US state abbreviations.

Days of the Week

List of the full names of the seven days of the week.

Work Days

List of the five work days of the week (U.S.)

Months of the Year

List of the full names of the months of the year.

Month Abbreviations

List of the standard abbreviation for the selected month.

Numeric Months of the Year

Returns a list of 12 months.

Days of the Month

Returns a list of 31 days.

Smart Days of the Month

Returns a list based on a numeric month and four-digit year.

Countries

Lists the names, in English, of the countries of the world.

Canadian Provinces

Lists the names, in English, of the Canadian provinces.

The Date Library rule library contains the Date Validation rule, which returns true if the passed-in string is a valid date. This rule takes one RuleArgument in the form mm/dd/yy. If the month or the day are passed in with single digits, it accounts for it approximately.


Using Rule Libraries

A rule library serves as a convenient way to organize closely related rules into a single object in the Identity Manager repository. Using libraries can ease rule maintenance by reducing the number of objects in the repository and making it easier for form and workflow designers to identify and call useful rules.

A rule library is defined as an XML Configuration object. The Configuration object contains a Library object, which in turn contains one or more Rule objects. Code Example 2-20 shows a library containing two different account ID generation rules:

Code Example 2-20   Library with Two Different Account ID Generation Rules

<Configuration name='Account ID Rules'>
   <Extension>
      <Library>

         <Rule name='First Initial Last'>
            <expression>
               <concat>
                  <substr>
                     <ref>firstname</ref>
                     <i>0</i>
                     <i>1</i>
                  </substr>
                  <ref>lastname</ref>
               </concat>
            </expression>
         </Rule>

         <Rule name='First Dot Last'>
            <expression>
               <concat>
                  <ref>firstname</ref>
                  <s>.</s>
                  <ref>lastname</ref>
               </concat>
            </expression>
         </Rule>

      </Library>
   </Extension>
</Configuration>

You reference rules in a library using an XPRESS <rule> expression. The value of the name attribute is formed by combining the name of the Configuration object containing the library, followed by a colon, followed by the name of a rule within the library. Therefore, all rule names in a library must be unique.

For example, the following expression calls the rule named First Dot Last contained in a library named Account ID Rules:

<rule name='Account ID Rules:First Dot Last'/>

Viewing and Customizing Rule Libraries

You can use the Identity Manager IDE to view and edit rule libraries, or to add rules to an existing library object. For detailed instructions, see Working with Repository Objects.


Referencing Rules

This section provides information about referencing rules. The information is organized as follows:

Basic Rule Call Syntax

Rules can be called from anywhere XPRESS is allowed, which includes forms, workflows, or even another rule. To call a rule, use the XPRESS <rule> expression as exemplified below:

<rule name='Build Email'/>

When the XPRESS interpreter evaluates this expression, it assumes the value of the name attribute is the name of a Rule object in the repository. The rule is automatically loaded from the repository and evaluated. The value returned by the rule becomes the result of the <rule> expression.

In the previous example, no arguments are passed explicitly to the rule. The next example shows an argument passed to the rule using the argument element.

<rule name='getEmployeeId'>
   <argument name='accountId' value='jsmith'/>
</rule>

In the previous example, the value of the argument is specified as a static string jsmith. You can also calculate the value of an argument using an expression.

<rule name='getEmployeeId'>
   <argument name='accountId'>
      <ref>user.waveset.accountId</ref>
   </argument>
</rule>

In the previous example, the argument value is calculated by evaluating a simple ref expression that returns the value of the view attribute user.waveset.accountId.

Because calculating argument values by referencing attributes is so common, an alternate syntax is also provided.

<rule name='getEmployeeId'>
   <argument name='accountId' value='$(user.waveset.accountId)'/>
</rule>

The previous examples have the same behavior. They both pass the value of the view attribute user.waveset.account as the value of the argument.

Rule Argument Resolution

Most rules contain XPRESS <ref> expressions or JavaScript env.get calls to retrieve the value of a variable. Several options are available for controlling how the values of these variables are obtained.

In the simplest case, the application calling the rule will attempt to resolve all references. For rules called from workflows, the workflow processor will assume all references are to workflow variables. For rules called from forms, the form processor will assume all references are to attributes in a view. Rules can also call another rule by dynamically resolving the called rule’s name.

You can also use the optional <RuleArgument> element, which is described in Declaring a Rule with Arguments.

This section provides the following information:

Calling Scope or Explicit Arguments

This section provides examples to illustrate rule argument resolution.

Code Example 2-21 illustrates adding a rule to a form that can be used with the User view because there are attributes names in the view:

Code Example 2-21  

<Rule name='generateEmail'>
   <concat>
      <ref>global.firstname</ref>
      <s>.</s>
      <ref>global.lastname</ref>
      <s>@sun.com</s>
   </concat>
</Rule>

This rule references two variables:

You can call this rule in a Field, as shown in Code Example 2-22:

Code Example 2-22  Calling the Rule in a Field

<Field name='global.email'>
   <Expansion>
      <rule name='generateEmail'/>
   </Expansion>
</Field>

This method can be a convenient way to write simple rules that are used in user forms only — similar to the concept of global variables in a programming language. But there are two problems with this style of rule design. First, it is unclear to the form designer which variables the rule will be referencing. Second, the rule can be called only from user forms because it references attributes of the user view. The rule cannot be called from most workflows because workflows usually do not define variables named global.firstname and global.lastname.

You can address these problems by passing rule arguments explicitly, and by writing the rule to use names that are not dependent on any particular view.

Code Example 2-23 shows a modified version of the rule that references the variables firstname and lastname:

Code Example 2-23  Rule Referencing firstname and lastname Variables

<Rule name='generateEmail'>
   <concat> \
      <ref>firstname</ref>
      <s>.</s>
      <ref>lastname</ref>
      <s>@sun.com</s>
   </concat>
</Rule>

The rule shown in Code Example 2-24 is simpler and more general because it does not assume that the rule will be called from a user form. But the rule must then be called with explicit arguments such as:

Code Example 2-24  Calling the Rule with Explicit Arguments

<Field name='global.email'>
   <Expansion>
      <rule name='generateEmail'>
         <argument name='firstname' value='$(global.firstname)'/>
         <argument name='lastname' value='$(global.lastname)'/>
      </rule>
   </Expansion>
</Field>

The name attribute of the argument elements correspond to the variables referenced in the rule. The values for these arguments are assigned to values of global attributes in the user view. This keeps the rule isolated from the naming conventions used by the calling application, and makes the rule usable in other contexts.

Local Scope Option

Even when arguments are passed explicitly to a rule, the system by default allows references to other variables not passed as explicit arguments. Code Example 2-25 shows a workflow action calling the rule but only passing one argument:

Code Example 2-25  Workflow Action Calling the Rule and Passing a Single Argument

<Action>
   <expression>
      <setvar name='email'>
         <rule name='generateEmail'>
            <argument name='firstname' value='$(employeeFirstname)'/>
         </rule>
      </setvar>
   </expression>
</Action>

When the rule is evaluated, the workflow processor will be asked to supply a value for the variable lastname. Even if there is a workflow variable with this name, it may not have been intended to be used with this rule. To prevent unintended variable references, it is recommended that rules be defined with the local scope option.

This option is enabled by setting the localScope attribute to true in the Rule element:

Code Example 2-26  Setting localScope attribute to true in a Rule Element

<Rule name='generateEmail' localScope='true'>
   <concat>
      <ref>firstname</ref>
      <s>.</s>
      <ref>lastname</ref>
      <s>@sun.com</s>
   </concat>
</Rule>

By setting this option, the rule is only allowed to reference values that were passed explicitly as arguments in the call. When called from the previous workflow action example, the reference to the lastname variable would return null.

Rules intended for general use in a variety of contexts should always use the local scope option.

Rule Argument Declarations

Though not required, it is considered good practice to include within the rule definition explicit declarations for all arguments that can be referenced by the rule. Argument declarations offer advantages, and can:

You could rewrite the generateEmail rule as shown in Code Example 2-27:

Code Example 2-27  generateEmail Rule

<Rule name='generateEmail' localScope='true'>
   <RuleArgument name='firstname'>
      <Comments>The first name of a user</Comments>
   </RuleArgument>
   <RuleArgument name='lastname'>
      <Comments>The last name of a user</Comments>
   </RuleArgument>
   <RuleArgument name='domain' value='waveset.com'>
      <Comments>The corporate domain name</Comments>
   </RuleArgument>
   <concat>
      <ref>firstname</ref>
      <s>.</s>
      <ref>lastname</ref>
      <s>@</s>
      <ref>domain</ref>
   </concat>
</Rule>

The Comments element can contain any amount of text that might be useful to someone examining the rule.

The rule has been modified to define another argument named domain, which is given a default value of waveset.com. The default value is used by the rule unless the caller passes an explicit argument named domain.

The call in Code Example 2-28 produces the string john.smith@sun.com:

Code Example 2-28  Call Producing john.smith@sun.com String

<rule name='generateEmail'>
   <argument name='firstname' value='john'/>
   <argument name='lastname' value='smith'/>
</rule>

The call in Code Example 2-29 produces the string john.smith@yourcompany.com:

Code Example 2-29  Call Producing john.smith@yourcompany.com String

<rule name='generateEmail'>
   <argument name='firstname' value='john'/>
   <argument name='lastname' value='smith'/>
   <argument name='domain' value='yourcompany.com'/>
</rule>

The call in Code Example 2-30 produces the string john.smith@:

Code Example 2-30  Call Producing john.smith@ String

<rule name='generateEmail'>
   <argument name='firstname' value='john'/>
   <argument name='lastname' value='smith'/>
   <argument name='domain'/>
</rule>


Note

In the previous example, a null value is passed for the domain argument, but the default value is not used. If you specify an explicit argument in the call, that value is used even if it is null.


Locked Arguments

Declaring arguments with default values can be a useful technique for making the development and customization of rules easier. If you have a constant value in a rule that may occasionally change, it is easier to locate and change if the value is defined in an argument rather than embedded deep within the rule expression.

The Identity Manager IDE provides a simplified GUI for configuring rules by changing the default values of arguments which is much easier than editing the entire rule expression.

But once an argument is declared, it is possible for the caller of the rule to override the default value by passing an explicit argument. You may not wish the caller to have any control over the value of the argument. This can be prevented by locking the argument. Arguments are locked by including the attribute locked with a value of true in the RuleArgument element (see Code Example 2-31):

Code Example 2-31  Locking an Argument

<Rule name='generateEmail' localScope='true'>
   <RuleArgument name='firstname'>
      <Comments>The first name of a user</Comments>
   </RuleArgument>
   <RuleArgument name='lastname'>
      <Comments>The last name of a user</Comments>
   </RuleArgument>
   <RuleArgument name='domain' value='waveset.com' locked='true'>
      <Comments>The corporate domain name</Comments>
   </RuleArgument>
   <concat>
      <ref>firstname</ref>
      <s>.</s>
      <ref>lastname</ref>
      <s>@</s>
      <ref>domain</ref>
   </concat>
</Rule>

In the preceding example, the argument domain is locked, which means its value will always be waveset.com, even if the caller tries to pass an value for the argument. If this rule is to be used at a site whose domain name is not waveset.com, all the administrator needs to do is edit the rule and change the value of the argument. There is no need to understand or modify the rule expression.


Securing Rules

You should secure a rule so it cannot be used in an unintended way if that rule contains sensitive information such as credentials or it calls out to a Java utility that can have dangerous side effects.

Securing rules is especially important if the rules are called from forms. Form rules run above the session, so exposed rules are available to anyone capable of creating a session — either through the API or a SOAP request.

This section provides the following information:

Securing a Rule

To secure a rule:

Creating Rules that Reference More Secure Rules

When you call a rule, you are first authorized for that rule. If authorized, that rule can then call other rules without further checking authorization. This allows users to be given indirect access to secure rules. The user cannot view or modify the contents of the secure rule. They can call it only through a rule to which they have been given access.

To create a rule that references a more secure rule, the user creating the rule must control both of the organizations that contain the rules. Typically, the secure rule is in a high level organization such as Top. The insecure rules are then placed in a lower level organization to which more users have access.



Previous      Contents      Index      Next     


Part No: 819-6127-10.   Copyright 2006 Sun Microsystems, Inc. All rights reserved.