Skip to content

Dynamic Script Attribute Mapping

IDaaS supports mapping definitions between platform attributes and application system attributes. This chapter guides you through using JavaScript dynamic scripts as the mapping type for mapping configuration. When writing dynamic scripts, use script code to generate attribute values and set display conditions for the attribute.

Prerequisites

You have administrator permissions for the IDaaS enterprise center platform.

Script Code Rules

Java Class Usage Is Prohibited

For example, the following code is not allowed:

javascript
var File = Java.type('java.io.File'); File;

The following exception will be thrown:

javascript
java.lang.ClassNotFoundException: java.io.File

CPU Time Limit

The default execution time limit is 1 second. If exceeded, an exception will be thrown.

For example, the following code is not allowed:

javascript
do{}while(true);

The following exception will be thrown:

javascript
ScriptCPUAbuseException

Memory Usage Limit

The default memory size limit is 10 MB. If exceeded, an exception will be thrown.

For example, the following code is not allowed:

javascript
var o={},i=0; while (true) {o[i++] = 'abc'}

The following exception will be thrown:

javascript
ScriptMemoryAbuseException

Script Format Restriction

To facilitate script rewriting, if, while, and for statements in scripts must use braces; otherwise, a format error will occur.

For example, the following code is not allowed:

javascript
var o={},i=0; while (true) o[i++] = 'abc';

The following exception will be thrown:

javascript
BracesException

Restricted Functions

The following functions are not allowed in the code. If they appear, they will have no effect.

javascript
print
echo
quit
exit
readFully
readLine
load
loadWithNewGlobal

Script Objects

Mapping scripts include the following objects: user (user), organization (organization), enterprise (enterprise), and account (application account).

user Object

The user object stores the attributes of the current user, including built-in attributes and custom attributes defined in attribute configuration.

Attribute NameValue TypeDescription
idstringUser ID
organizationIdstringOrganization ID
userNamestringUsername
namestringName
firstNamestringFirst name
middleNamestringMiddle name
lastNamestringLast name
emailstringEmail
mobilestringMobile number
disabledbooleanDisabled
guidstringUser GUID
employeeidstringEmployee ID
attrGenderstringGender
attrBirthdayTimestampBirthday
attrNickNamestringNickname
attrIdentityTypestringIdentity type
attrIdentityNumberstringID card number
attrAreastringRegion
attrCitystringCity
attrManagerIdstringManager ID
attrUserTypestringUser type
attrHireDateTimestampHire date
attrWorkPlacestringWork address
externalIdstringExternal system ID
employeeRelationstringEmployment relationship
deactivationDateTimestampDeactivation date
disabledModestringDisabled mode
Other custom attributesstring

organization Object

The organization object stores organization information.

Attribute NameValue TypeDescription
idstringOrganization ID
codestringCode
namestringName
categoryIdstringOrganization category ID
parentIdstringParent organization ID
disabledbooleanDisabled
displayPathstringOrganization path
leaderIdstringOrganization leader ID

enterprise Object

The enterprise object stores basic enterprise information.

Attribute NameValue TypeDescription
idstringEnterprise ID
tenantIdstringRemote enterprise ID
domainstringEnterprise domain
namestringEnterprise name
logostringEnterprise logo

account Object

The account object stores the attributes of the current account, including built-in attributes and custom attributes defined in the application account model.

Attribute NameValue TypeDescription
idstringAccount ID
usernamestringAccount name
namestringAccount name
attrManagerIdstringDirect manager
organizationIdstringApplication organization ID
disabledbooleanDisabled
remoteIdstringRemote ID
roleslistRole list
Other custom attributesstring

TIP

When using script objects, you can directly obtain values in the format <u>[Object].[AttributeName]</u>.

For example: user.name, organization.code, account.username, enterprise.domain. This method also applies to extended attributes. For example, if a user has an extended attribute hobby, you can use user.hobby to obtain the hobby value.

Operation Steps

TIP

This section uses the authentication mapping configuration of an OIDC protocol application as an example. Other attribute mapping configurations can refer to the following method.

  1. Log in to the IDaaS enterprise center platform, select Resources > Applications in the top navigation bar, and choose an application.

  2. Enter the application details page and select Authentication Integration > Mapping Configuration.

  3. Click Add Mapping and configure the parameters as follows:

    • Application System Attribute Name: Customize the application system attribute name.

    • Mapping Type: Select Dynamic Script.

    • Dynamic Script Content: JavaScript script.

  4. After configuration, save and click the Test button to select a test user.

  5. Click Test to display the value corresponding to the attribute. (The example script generates an email address by concatenating the username with an email suffix.)

Script Examples

The following are simple script examples for reference during actual configuration.

Example 1. Current Time of Tomorrow

javascript
var date =new Date();
date.setDate(date.getDate()+1);
date.toISOString();

Example 2. User Extended Attribute

First, add hobby as an extended attribute in the user's attribute definition.

javascript
user.hobby;

Example 3. User Mobile Number with Middle 4 Digits Hidden

javascript
var mobile = user.mobile;
var result = "";
if(mobile.length==11){
    result = mobile.slice(0,3)+"****"+mobile.slice(-4);
}
result;

Example 4. Generate User Email Based on Username

javascript
var username = user.userName;
username.toLowerCase()+"@bamboocloud.com";

BambooCloud IDaaS Open Platform