Assuming you'd connected a managed system or source system to CzechIdM, prepared synchronization or provisioning with some attribute mappings (e.g. identity), you may then have several attributes that differ in format between the source and the managed system. For instance, you want to fill an Active Directory's attribute diplayName whose format is <firstName + LastName>. For scripts, we currently use Groovy language.
From the HR system to CzechIdM you provide firstName and lastName as separate attributes as is common. Now you want to make a transformation script to fill displayName from 2 other attributes.
To fill the attribute from 2 entity (identity in our case) attributes, just use this piece of code:
entity.firstName + " " + entity.lastName
Thus you can define basic transformation scripts that does not need any additional privilege to run.
There is another convenient way to use transformation scripts. You can define your script in CzechIdM via menu Settings → Script definition. There you can see the list of all available scripts (not only transformation ones). If you click on the Add button, you can now add your own script definition to the CzechIdM script library.
If you click on Add button, you can add your own script definition to the CzechIdM script library.
Fill the following fields:
In this table, you specify what authorizations on data you give to the script. There are some basic rules, that every script has by default - e.g. get attributes and their values from entity. Other rules must be added if you want to access other entities such as Roles or Organizations from the script that is used in Identities synchronization. Another common use case is that you want to use some non basic java Classes or Methods. Again, you have to give your script specific authorization to use that Class.
The script is then available in synchronization and provisioning mapping in attribute detail. To use it, click on the green button insert script in the right upper corner of transformation box.
Then you can see a new window listing available scripts
When you select the desired one, click on the Select button. The script is then referred/called from the attribute mapping transformation box
E.g. if you want to insert the script "getTrimmedString" as the transformation to script, the transformation box should contain the following code:
scriptEvaluator.evaluate( scriptEvaluator.newBuilder() .setScriptCode('getTrimmedString') .addParameter('scriptEvaluator', scriptEvaluator) .addParameter('uid', uid) .addParameter('attributeValue', attributeValue) .addParameter('entity', entity) .addParameter('system', system) .build());
If you want to insert the script "getTrimmedString" as the transformation from script, the transformation box should contain the following code:
scriptEvaluator.evaluate( scriptEvaluator.newBuilder() .setScriptCode('getTrimmedString') .addParameter('scriptEvaluator', scriptEvaluator) .addParameter('attributeValue', attributeValue) .addParameter('icAttributes', icAttributes) .addParameter('system', system) .build());
In fact, all default scripts that are available in GUI after CzechIdM installation, were loaded into application during its previous start. They meet XML format and file incorporates the script body (groovy), script privileges and its purpose. So if you want to track changes on your scripts e.g. with git, this is the best way.