| Back | Main view

Generic connector field evaluation using javascript

Product:IMiS/ARChive
Release:Since 9.10.1904
Date:12/24/2020

Case: Generic connectors are configured with 'field' definitions, which represents translation between IMiS ARChive server and external synchronization service. Here we present a few examples of field configuration, which uses javascript for its evaluation.

Description:

Generic connectors uses 'nashorn' javascript engine, which is part of Java 8 and implements ECMA-262 standard. Each 'field' definition can be configured with two javascript events:
Field names, which contains colon in its name are translated in javascript with underscore. For example, if field name is 'sys:dir:Account', javascript field name will be 'sys_dir_Account'. Javascript result must be present as string or as string array. All examples are based on configuration using Active Directory.

Example 1: Replace 'name' from AD with hardcoded values.

<Arguments>
...
    <Field key="ad:name" type="string">name</Field>
    <Field key="ad:name:replaced" type="expression" preScript="var tmp = [ 'abcd', 'efgh', 'ijkl' ]; tmp;">%ad:name%</Field>
...
</Arguments>

Example 2: Add ' example1' suffix to every user account name from AD.

<Arguments>
...
    <Field key="ad:accountName" type="string" scope="user">sAMAccountName</Field>
    <Field key="sys:dir:Account" type="expression" scope="user" preScript="var tmp = sys_dir_Account[0]; tmp += ' example1'; tmp;">%ad:accountName%</Field>
...
</Arguments>

Example 3: Generate base64 encoded universally unique identifier using concatination of 'sAMAccountName' and 'sAMAccountType'.

<Arguments>
...
    <Field key="sys:dir:Account" type="string">sAMAccountName</Field>
    <Field key="ad:sAMAccountType" type="string">sAMAccountType</Field>
    <Field key="sys:dir:UUID" type="expression" scope="user" preScript="var tmp = sys_dir_Account[0]; tmp += ad_sAMAccountType[0]; var b64encode = java.util.Base64.encoder.encodeToString(tmp.bytes); b64encode;">%sys:dir:Account%</Field>
...
</Arguments>

Example 4: Filter user 'cn', 'displayName', and 'name' AD attributes using java HashSet and script event.

<Arguments>
...
    <Field key="ad:cn" type="string" scope="user">cn</Field>
    <Field key="ad:displayName" type="string" scope="user">displayName</Field>
    <Field key="ad:name" type="string" scope="user">name</Field>
    <Field key="hashset:filtered" type="expression" scope="user" script="var HashSetType = Java.type('java.util.HashSet'); var unique_values = new HashSetType(); for (var i = 0; i &lt; ad_cn.length; i++) { unique_values.add(ad_cn[i]); } for (var i = 0; i &lt; ad_displayName.length; i++) { unique_values.add(ad_displayName[i]); } for (var i = 0; i &lt; ad_name.length; i++) { unique_values.add(ad_name[i]); } unique_values.toArray();">nonexisting_ad_field_59364728</Field>
...
</Arguments>

Related Documents:

https://en.wikipedia.org/wiki/Nashorn_(JavaScript_engine)
https://www.oracle.com/technical-resources/articles/java/jf14-nashorn.html
https://jcp.org/en/jsr/detail?id=223
https://jcp.org/en/jsr/detail?id=292
http://www.ecma-international.org/ecma-262/5.1/ECMA-262.pdf
http://openjdk.java.net/jeps/174

| Back | Main view