3.6.2.2 Assignments with template strings
The [Identity Provider Mapping] window is used to configure mapping rules between IdP user information and Ops I user information. Using template strings to assign values allows you to specify mapping targets even if the group, role, and attributes in Ops I do not perfectly match the values of conditions, Claim (for OIDC), or attributes (for SAML). As a result, you can set mapping targets that meet various conditions in one operation without having to register multiple mappings.
This section describes the following items:
- Description rules and examples
- Errors that occur when configuring the identity provider
- Common mistakes
(1) Description rules and examples
When assigning values by using template strings, you can use directives, output expressions, conditional expressions, operators, string functions, and sequence functions.
In the following, “var” represents a variable, “str” represents a string, and “list” represents a sequence.
[Directives]
The available directives are as follows:
| Directive | Description | Example |
|---|---|---|
| <#-- Comment --> | Writing a comment | <#-- Comment --> |
| <#if>...</#if> <#if>...<#elseif>...<#else>...</#if> |
Conditional branching | <#if>...<#elseif>...<#else>...</#if> |
| <#assign var = "A"> | Defines the variable | <#assign var = "A"> |
| <#list items as item>...</#list> | Defines individual processing for values in a list | <#list items as item>...</#list> |
[Output expressions]
The available output expressions are as follows:
(Table) Available output expressions
| Output expression | Description | Example |
|---|---|---|
| ${} | Outputs variables | ${} |
[Conditional expressions]
The available conditional expressions are as follows:
(Table) Available conditional expressions
| Conditional expression | Description | Example |
|---|---|---|
| var?? | Checks whether the variable exists | var?? |
| var?has_content | Checks whether the variable exists and whether its value is not empty | var?has_content |
[Operators]
The available operators are as follows:
| Operator | Description | Example |
|---|---|---|
| == | Equal to | == |
| ! | Negation | ! |
| != | Not equal | != |
| || | Or | || |
| && | And | && |
| lt | <(Less than) | lt |
| lte | <=(Equal to or less than) | lte |
| gt | >(Greater than) | gt |
| gte | >=(Equal to or greater than) | gte |
[String functions]
The available string functions are as follows:
(Table) Available string functions
| String function | Description | Example |
|---|---|---|
| str?c_lower_case | Converts to lowercase | str?c_lower_case |
| str?c_upper_case | Converts to uppercase | str?c_upper_case |
| str?replace("A", "B") | Replaces string A with string B | str?replace("A", "B") |
| str?split("A") | Splits the specified string at A, and outputs as a list | str?split("A") |
| str?date("yyyy-MM-dd") | Converts the string to date type, and compares dates by using the operator lt or gt | str?date("yyyy-MM-dd") |
| str?number | Converts the string to a numeric type | str?number |
| str?trim | Deletes the leading and trailing spaces | str?trim |
| str?contains("A") | Checks whether the string contains A | str?contains("A") |
| str?starts_with("A") | Checks whether the string starts with A | str?starts_with("A") |
| str?ends_with("A") | Checks whether the string ends with A | str?ends_with("A") |
| str?matches("A") | Checks whether the string is the regular expression of the format of A | str?matches("A") |
[Sequence (array, list) functions]
The available sequence functions are as follows:
(Table) Available sequence functions
| Sequence function | Description | Example |
|---|---|---|
| list?seq_contains("A") | Checks whether the sequence contains specific element A | list?seq_contains("A") |
| list?join("A") | Combines sequence elements with A, and outputs a single string | list?join("A") |
Used to view IdP user information.
The user information available in authn_info and its method of use differ between SAML and OIDC. The characteristics of authn_info in SAML and OIDC are as follows:
①For SAML:
- You can use information contained in attributes.
For mapping using templates, the Attribute Name is used as the key, and the corresponding value is stored in authn_info as an array. Single values are also treated as arrays.Example: When the IdP information "preferred_username" is equal to "test_user"
<#if authn_info["preferred_username"][0]=="test_user"> - Use an index (example: [0]) only when you want to specify which element of the array to use.
Example: ${authn_info["email"][0]}
If the array has multiple elements, [1] or other indices can also be specified in addition to [0]. An index does not need to be specified in the following cases:- Conditional expressions, such as existence checks (??) and empty checks (?has_content):
These are applied to the entire expression rather than to individual elements of the array. - Functions for arrays (sequences):
Values are stored in authn_info as arrays.
Example: authn_info["groups"]?seq_contains("admin")
- Conditional expressions, such as existence checks (??) and empty checks (?has_content):
Notes
- Specifying an index when it is not necessary results in an error.
- Since the order in which values are stored from the IdP is unknown, the use of ?seq_contains() or similar functions is recommended.
②For OIDC:
- You can use properties included in the user information obtained from the ID token or the UserInfo endpoint.
<#if authn_info["preferred_username"]=="test_user">
Notes
- When setting "Customer" as a user attribute, specify the customer ID.
When setting "Customer", be sure to assign one of the following roles:- Pre-Installed role "Customer Manager"
- Pre-Installed role "Customer User"
- Primitive roles "customer" and "free_user"
- Primitive roles "customer" and "manager"
- A custom role with one of the above roles set as a related role
- Do not create multiple mapping configurations for a single attribute.
Because the mapping order is indeterminate, attribute settings might not result in the intended values. - Specify the hierarchical structure of keys by using bracket notation.
Example: Upper-level hierarchy [lower-level hierarchy] - You can specify multiple group attributes and role attributes. In this case, separate the specified values with line breaks. Also, do not specify multiple user attributes, because you will never need to specify more than one user attribute.
- The maximum number of characters that can be specified in a template is 10,000.
- The maximum number of characters that can be output in a template is 10,000. If more than 10,000 characters are output, an error message will appear and you will no longer be able to log in. If this happens, the Ops I security administrator will need to review and modify the template string with a focus on the loop processing.
- The leading and trailing spaces will be deleted.
- Inside a directive, enclose strings with double quotation marks (") or single quotation marks (').
- Outside a directive, do not enclose strings with double quotation marks (") or single quotation marks ('). If you use quotation marks, there might be a risk of unintended assignments.
- The value returned from authn_info might be of string type rather than numeric type. If a string-type value is returned, operations that can be performed on numeric types will not be available.
- Do not use the output expression "${}" within a directive.
The following shows examples using directives, output expressions, conditional expressions, operators, string functions, and sequence functions:
Adding the following comment: Output the role with a line break
<#if authn_info["role"]??>
${authn_info["role"]?join("\n")}
</#if>
<#if>...<#elseif>...<#else>...</#if>
Assigning the “adminGroup1” role when the IdP’s “id” is “1”, “adminGroup2” when the IdP’s “id” is “2”, and “customerGroup” for all other cases
adminGroup1
<#elseif authn_info["id"] == "2">
adminGroup2
<#else>
customerGroup
</#if>
Assigning the “portal_subscriber” role when the IdP’s “department” is not the string “abc”
<#if !condition1>
portal_subscriber
</#if>
<#list items as item>...</#list>
Checking each IdP’s “role” information stored in list format, and assigning “user_admin” and “customer_admin” when part of the string contains “admin”
<#if rolename?contains("admin")>
user_admin
customer_admin
</#if>
</#list>
Assigning the “email” information as is when the “email” information on the IdP side is not empty
${authn_info["email"]}
</#if>
Assigning the “idp_user” group when the IdP is linked
idp_user
</#if>
Assigning the “email” information as is when the “email” information on the IdP side is not empty
${authn_info["email"]}
</#if>
Assigning the “portal_subscriber” role when “customer.group” in “groups” of the IdP is the string “portal”
portal_subscriber
</#if>
Assigning the “portal_subscriber” role when the IdP’s “department” is not the string “abc”
<#if !condition1>
portal_subscriber
</#if>
Assigning the “customer_group” group when the IdP’s “customer” is not the string “123”
customer_group
</#if>
Assigning the “portal_author” role when the IdP’s “groups” list contains “group 1” or the “role” list contains “author”
portal_author
</#if>
Assigning the “portal_site_admin” role when the IdP’s “groups” list contains “group 2” and the “email” information is “abc.com”
portal_site_admin
</#if>
When the string-type “customer (customer code)” of the IdP is a numeric value, converting it to numeric type, and assigning the “customer_group” group if the value is less than 2000
customer_group
</#if>
When the string-type “customer (customer code)” of the IdP is a numeric value, converting it to numeric type, and assigning the “customer_group” group if the value is 2000 or less
customer_group
</#if>
When the string-type “customer (customer code)” of the IdP is a numeric value, converting it to numeric type, and assigning the “customer_group” group if the value is greater than 2000
customer_group
</#if>
When the string-type “customer (customer code)” of the IdP is a numeric value, converting it to numeric type, and assigning the “customer_group” group if the value is 2000 or greater
customer_group
</#if>
Converting the IdP’s “username” to lowercase, and assigning the “customer_admin” role when the value is equal to “hitachi_taro”
customer_admin
</#if>
Converting the IdP’s “username” to uppercase, and assigning the “customer_admin” role when the value is equal to “HITACHI_TARO”
customer_admin
</#if>
Assigning a role with a name where the “hitachi” part of the name is replaced with “test” when “customer.group” in “groups” of the IdP contains the string “hitachi”
${authn_info["groups"]["customer.group"]?replace("hitachi", "test")}
</#if>
Treating the first separated value as the surname when the IdP has the “name” information and the “name” value is not empty but is separated by " "
${authn_info["name"]?split(" ")[0]}
</#if>
Assigning the “century_group” group when the IdP’s date of birth information (stored in yyyy-MM-dd format) is earlier than January 1, 2000
century_group
</#if>
When the string-type “customer (customer code)” of the IdP is a numeric value, converting it to numeric type, and assigning the “customer_group” group if the value is greater than 2000
customer_group
</#if>
Assigning the “idp_user” group when the IdP’s customer information is not empty and its value is equal to 2000
idp_user
</#if>
Assigning the “hitachi_group” group when the IdP’s “email” information contains the string “hitachi”
hitachi_group
</#if>
Assigning the “itsm_admin” role when the IdP’s “username” information starts with the string “admin”
itsm_admin
</#if>
Using the IdP’s “email” information as Ops I’s “email” information when the IdP’s “email” ends with the string “.com”
${authn_info["email"]}
</#if>
Assigning the customer code when the IdP’s “customer (customer code)” consists of numbers
${authn_info["customer"]}
</#if>
Assigning the “itsm_admin” role when one of the multiple roles held by the IdP is the “admin” role
itsm_admin
</#if>
Assigning the “role with the same name in Ops I when the IdP has the “role” information
${authn_info["role"]?join("\n")}
</#if>
(2) Errors that occur when configuring the identity provider
When there are issues with the identity provider settings or the template definitions, errors are displayed at the following times.
[When saving the identity provider]
If there is a grammatical mistake, an error message will be displayed when saving the identity provider.
You can identify the problematic line by checking the “[Details]” provided in the error message.
[Details] Line where the error occurred
[When a user logs in]
When assigning a role but the corresponding role does not exist
When assigning a group but the corresponding group does not exist
When assigning a customer but the corresponding customer does not exist or is [invalid] or [invalid-temporarily]
For details about the valid/invalid status of customers, see "[Customers] > [Customer Administration] > Customer registration" in "JP1 Cloud Service/Operations Integration User's Guide (ITSM Operation Manual)".
When an attempt is made to assign multiple values to a single user attribute
When an attempt is made to assign the email address of a reserved user when assigning an email address
When an attempt is made to assign an empty value to a required attribute*
When the character count exceeds 10,000, which is the maximum output limit for templates
The following messages will be displayed depending on the nature of the deficiency. For details on the authentication process of assigned email addresses, see "(Figure) Logging in through an IdP when the user is determined the same between Ops I and the IdP".
(3) Common mistakes
The following shows examples of common mistakes in template descriptions and their correct counterparts.
- When specifying a customer, use the customer ID, instead of the customer name.
<Incorrect><#if authn_info["customer"] == "customer1"><Correct>
customer1
</#if><#if authn_info["customer"] == "customer1">
1001
</#if> - When assigning groups, specify them on separate lines.
<Incorrect><#if authn_info["group"]??><Correct>
${authn_info["group"]}
</#if><#if authn_info["group"]??>
${authn_info["group"]?join("\n")}
</#if> - When assigning roles, specify them on separate lines.
<Incorrect><#if authn_info["id"] == "1"><Correct>
System Security Administrator, user_admin
</#if><#if authn_info["id"] == "1">
System Security Administrator
user_admin
</#if> - For SAML, specify the index to indicate which element in the array to reference.
- When assigning an attribute (customer) by using a template
<Incorrect><#if authn_info["customer"] == "customer1"><Correct>
1001
</#if><#if authn_info["customer"][0] == "customer1">
1001
</#if> - When assigning a role by using the template
<Incorrect><#if authn_info["username"]?c_upper_case == "HITACHI_TARO"><Correct>
customer_admin
</#if><#if authn_info["username"][0]?c_upper_case == "HITACHI_TARO">
customer_admin
</#if>
- When assigning an attribute (customer) by using a template