An Attribute Transformer is used to transform a set of data, or attributes, into a possibly different set of data.
It can be used to add, change or remove attributes.
The following s Attribute Transformer types are supported:
All Attribute Transformers have the following common properties:
In the following sections, more details are given about each different Attribute Transformer type.
The Regex Transformer can be used to perform substitutions in the values of a set of attributes, dependent on whether the attribute values match a predefined regular expression.
The Regex Transformer specifies only one property:
Each entry must specify the following:
The base path of the attribute is specified using the dot notation. For example, to transform the email of an user account, the attribute-base-path would have the value emails.email, and in this case, the attribute-name would be simply value.
emails.email
value
If the base path of the attribute is the root itself, attribute-base-path must be set to “$root”. In all other cases, explicitly declaring the root is optional, hence $root.emails.email is equivalent to emails.email.
$root.emails.email
attribute-name is the simple name of the attribute, not including its path, as seen above.
attribute-name
If provided, transformed-attribute-name is the new name of the attribute after the transformation is applied. If not provided, the attribute’s name is kept unchanged.
transformed-attribute-name
The value of matching-regex is the regular expression that will be used to match against the value of the attribute being transformed. If the regex matches, the value is transformed using the provided replacement-value, otherwise the value is kept unchanged.
matching-regex
replacement-value
Notice that the replacement-value may contain parts of the original value by referring to the matching regex groups (see the examples below).
Note
If an empty replacement-value is provided, the attribute will be removed rather than transformed in case it is single-valued, or the items matching the regex will be removed in case it is multi-valued (and if all items are removed, the attribute itself gets removed). Only String values can be replaced using the Regex Transformer.
The following examples should make it clear how you can use regular expressions effectively to transform attributes.
Given the following attributes, in JSON format:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
{ "name": { "givenName": "Joe", "familyName": "Doe" }, "subject": "joe_doe", "emails": [ { "value": "joe@acme.com", "type": "work", "primary": true }, { "value": "joe@doe.com", "type": "home" } ] }
Example 1. A Regex Transformer that removes the name attribute and replaces the value of the subject attribute when a value matches the simple joe_doe regex:
name
subject
joe_doe
1 2 3 4 5 6 7 8 9 10 11 12
<attribute-transformer> <id>regexTransformer1</id> <excluded-attributes>name</excluded-attributes> <regex-transformer> <attributes> <attribute-base-path>$root</attribute-base-path> <attribute-name>subject</attribute-name> <matching-regex>joe_doe</matching-regex> <replacement-value>Joe_Doe</replacement-value> </attributes> </regex-transformer> <attribute-transformer>
Result:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
{ "subject": "Joe_Doe", "emails": [ { "value": "joe@acme.com", "type": "work", "primary": true }, { "value": "joe@doe.com", "type": "home" } ] }
Example 2. A Regex Transformer that replaces all email attribute values ending with @acme.com to a value ending with @foo.org instead:
email
@acme.com
@foo.org
1 2 3 4 5 6 7 8 9 10 11
<attribute-transformer> <id>regexTransformer1</id> <regex-transformer> <attributes> <attribute-base-path>emails</attribute-base-path> <attribute-name>value</attribute-name> <matching-regex>(*.@)acme\.com</matching-regex> <replacement-value>$1foo.org</replacement-value> </attributes> </regex-transformer> <attribute-transformer>
{ "name": { "givenName": "Joe", "familyName": "Doe" }, "subject": "joe_doe", "emails": [ { "value": "joe@foo.org", "type": "work", "primary": true }, { "value": "joe@doe.com", "type": "home" } ] }
The Data Source Transformer uses a Data Source to lookup new values for pre-defined attributes. If for some reason the result of the data source lookup doesn’t contain the attribute, the original value is used.
Only attributes defined in the attribute list are replaced with data source values. Other attributes are passed through without change.
The Data Source Transformer only uses the first record returned by the data source.
The following properties may be set:
Some data sources can be customized by configuring a custom-attribute-query, which is used for this lookup.
custom-attribute-query
Each attribute entry may specify the following:
account_id
1 2 3 4 5 6 7 8 9 10 11 12 13
<attribute-transformer> <id>dsTransformerSqlForSecondaryDomain</id> <excluded-attributes>accountid</excluded-attributes> <data-source-transformer> <attribute-data-source>DefaultHSQLDBAttributeNameLookupSecondaryDomain</attribute-data-source> <attributes> <attribute-name>subject</attribute-name> <use-value-of-attribute-named>account_id</use-value-of-attribute-named> </attributes> <additional-attributes-to-include>linked_account_domain_name</additional-attributes-to-include> <additional-attributes-to-include>linked_account_id</additional-attributes-to-include> </data-source-transformer> </attribute-transformer>
The Script Transformer simply invokes a transformation procedure script to transform attributes.
The only property that is specific to the Script Transformer is:
transformation-procedure
This is the most powerful attribute transformer, as it allows any change at all to be performed on the original attributes. But in most cases, the other, simpler to maintain transformers, might be a better fit.