You can create a virtual attribute from an attribute source and from an external data source.
On the Home page, click Identity Servers > IDP Global Settings > Virtual Attributes.
Click Plus icon to create a virtual attribute.
Specify a name and description for the virtual attribute.
Click Provide Input Parameters and specify the following details:
Field |
Description |
---|---|
Name |
Specify a name for the attribute. If you use advanced JavaScript option, specify the same name in Advanced JavaScript. The default value is P1. |
Parameter Value |
Select an attribute from the list. To specify additional values, click +. NOTE:If an attribute source returns a null or an empty value, the corresponding input parameter takes an empty string value. |
Show / Add Test Values |
You can add, edit, and delete a test value. |
Click Provide a Modification Function and specify the following details:
Select a Modification Function: Select a function. The corresponding JavaScript is displayed in Script. You can further customize these scripts and use them in Advanced JavaScript.
The following table lists the pre-defined JavaScript functions with examples:
Function |
Description |
Example: Pre-Defined Functions |
---|---|---|
No Modification |
Use this function if you do not require any modification to the input parameters. |
|
To UpperCase |
Converts the input value to upper case. This function works on arrays and single-valued input. It uses the toUpperCase() JavaScript function. Works only on one input parameter that is selected in Input Parameters. |
If P1=alice, then the result displays ALICE. |
To LowerCase |
Converts the input value to lower case. This function works on arrays and single-valued input. It uses the toLowerCase() JavaScript function. Works only on one input parameter that is selected in Input Parameters. |
If P1=ALICE, then the result displays alice. |
Remove Substring |
Removes a substring from all instances of the input value. This function does not remove a substring from the global option. This function works on arrays and single-valued input. It uses the following JavaScript function: split() and join(). Works only on one input parameter that is selected in Input Parameters. |
If P1=a@opentext.com Remove=@opentext, then the result is a.com. |
Find And Replace |
Finds and replaces a string from all instances of the input value. Works only on one input parameter that is selected in Input Parameters. |
If P1=abcde Find=e Replace=a, then the result displays abcda. |
Regex Replace |
Finds and replaces a substring from all instances of the input value by using a regular expression. For example, to search /, you must escape it first using \. Use the following syntax: /\// This function works on arrays and single-valued input. It uses the following JavaScript functions: replace() Works only on one input parameter that is selected in Input Parameters. |
If P1=bob@novell.com Find=@novell.com Replace=@opentext.com The result displays: bob@opentext.com |
Find Subset by Regex |
Use this function if it is a multivalue input and you want a subset of values from it, satisfying a particular condition by using a regular expression. This function works on arrays and single-valued input. It uses the following JavaScript function: replace() Works only on one input parameter that is selected in Input Parameters. |
If P1='’a@ot.com, b@ot.com,c @opentext.com, d@opentetxhr.com” regex= /opentext/ Then, the result displays: c@opentext.com, d@opentexthr.com |
Concatenate Values in a Parameter |
Concatenates multiple values of a multivalue input. You must add a separator between the values that you want to concatenate. Works only on one input parameter that is selected in Input Parameters. |
If P1=abc, def Separator=+ Then, the result displays: abc+ def |
Concatenate Multiple Parameters |
Concatenates multiple input parameter values, where each input parameter can be multivalue input. You must add a separator between the values that you want to concatenate. |
If P1=abc, def and P2=123, 456 Parameter Separator=+ Multivalue Separator=: Then, the result displays abc:def+123:456 |
Advanced JavaScript: |
Specify a customized JavaScript in this field. You need to create a JavaScript function with name “main” and specify the code in it. You can do the following:
|
IMPORTANT:
After JavaScript processing, if the output is a null value, the value of the virtual attribute is empty.
The pre-defined function can handle both single-valued and multivalue inputs. If the input is multivalue, the pre-defined function is applied on each values.
Advanced JavaScript:
Sample JavaScript:
function main(P1, P2) { //some logic //you can call yourFunction(name) and use its return value return some value; } function yourFunction(name) { //some code //return some value; }
For advanced JavaScript, the input parameter name in the main function of the JavaScript must match the input parameter name specified in Input Parameters. The return value can be a single value or an array.
When it is a multivalue input, it is sent as an array to the main function.
When the Identity Server computes the value of a virtual attribute, it calls a function named main that is available in the script provided for it. The value (single value or array) returned by main is the value of the virtual attribute.
For example: Consider a scenario where P1 contains bmw and nissan, you can use the JavaScript instanceof function to check if the input is single-valued or multivalue. If it is multivalue, then JavaScript iterates over the values P1=['bmw', 'nissan']
function main (P1){ if( P1 instanceof Array) { var a =P1[0] //will assign 'bmw' value to variable a //do something } else{ // if the P1 is single value not a array //do something } }
The following code checks if an input parameter is empty, contains a value, or undefined:
function main(P1){ if(hasNoValue(P1)) // do something return something; } function hasNoValue(P1){ if(P1 == null || (typeof P1 == 'undefined') || P1.trim().length == 0) return true; else return false; }
Test: Click this to test the input values based on the modification function. To test multivalue inputs, click the + icon.
For example, if an attribute mail has two values: abc@example.com and def@example.com, click the + icon twice. In each field, add the values separately.
The test result displays the status with the test results. You can view the error logs at the following location:
/opt/novell/nam/adminconsole/logs/catalina.out
Base64 Encode: (Conditional) Select this if you want to encode the modified attribute with Base64.
Click Save and update the Identity Server.