SINCE 3.3.13
This article shows how JEMH Notification Templates can embed or customise notification content based on data from LDAP queries, based on configurations created in the JEMH > LDAP section. This will work with:
Adhoc notifications
Postfunction notifications
Issue Event Notifications
Prerequisites
JEMH Version 3. 3.13 (Jira 8+)
You should already have a functioning LDAP configuration in JEMH.
Example: get default user data
The following script shows how you can access LDAP in notification templates, here for example, we are looking up the user with account name “Administrator“ (could be username in Jira). The default return type is LDAPUser which only has a limited set of attributes.
#set ($username = "Administrator") #set ($ldap = $jemhUtils.getLdap()) #set ($ldapUser = $ldap.getUserDetails($username)) #if ($!ldapUser) ## FYI see http://ppl-docs.s3-website-us-east-1.amazonaws.com/JEMH/3.3.12/com/javahollic/jira/emh/api/LDAPUser.html ldap user found with username=$username, email=$ldapUser.getEmail() #else no ldap user found with username=$username #end
In the JEMH TemplateSet ‘preview’ (available after setting the Preview Issue Key), the result is seen:
Example: get all attribute, extract value of one
For arbitrary LDAP attribute retrieval, you’ll need to use a raw LDAP filter and specify the attributes required. The result is a map of the attribute names to a List of possible values. The example below shows how to get the (typically) first value in the list with .get(0):
#set($filter = "(sAMAccountName=Administrator)") #set($userAtts = $ldap.getUserAttributes($filter, null)) #foreach ($anAttribute in $userAtts.keySet()) $anAttribute == $userAtts.get($anAttribute) #end ## showing how to get single value from result primaryGroupID = $userAtts.get("primaryGroupID").get(0)
Example output
Example to get nominated set of attributes
SINCE 3.3.46
<h3>Get Named Atts Only</h3> #set($requiredAttributes = ["sAMAccountName","distinguishedName","mail", "memberOf"]) #set($namedAttResults = $jemhUtils.getLdap(1).getUserAttributes("(sAMAccountName=andy)", $requiredAttributes)) <p>Got $namedAttResults.size() attributes:</p> <p> <UL> <LI>mail = $namedAttResults.get("sAMAccountName").get(0)</LI> <LI>distinguishedName = $namedAttResults.get("distinguishedName").get(0)</LI> <LI>mail = $namedAttResults.get("mail").get(0)</LI> <LI>memberOf = $namedAttResults.get("memberOf").get(0)</LI> </UL> </p>
Example output
Performance
Currently, retrieved data is not cached, every invocation triggers a call to the remote server. If your notifications are in response to interactive user actions, their user interfaces experience could be degraded as the user ‘submit’ doesn’t complete until the notifications have been rendered and queued for delivery.
A future feature has been logged to add cache support :