Apps documentation
Active Directory Attributes Sync
Active Directory Attributes Sync
Documentation
FAQ
Release notes
Last updated May 4, 2022

Java API for ScriptRunner

This page provides information on using synchronized data in the ScriptRunner app.

Active Directory Attributes Sync app provides its own Manager which can be used in ScriptRunner or any other external app. It is also possible to customize the synchronized data.

To get user attributes using the app, add the annotation @WithPlugin("com.intenso.jira.plugins.ad-integration-manager")to your code.

ConnectionManager

method description
List<ConnectionDTO> getConnections(); Returns a list of ConnectionDTOs with Active Directory Server defined in the app.
ConnectionDTO getConnection(Integer id); Returns a ConnectionDTO based on the connection ID.
ConnectionDTO getConnection(String name); Returns a ConnectionDTO based on the connection name.

ConnectionDTO

method description
int getId(); Returns the connection ID.
String getName(); Returns the connection name.
Long getDirectoryId(); Returns a directory ID in Jira if the connection has been imported from Jira. Otherwise returns null.
String getProfileTitle(); Returns a data title from Active Directory in the User Profile page.
boolean isEnabled(); Returns true if the connection ID is enabled. Otherwise returns false.
List<UserFieldDTO> getUserFields(); Returns a list of user fields added to this connection.
List<GroupFieldDTO> getGroupFields(); Returns a list of group fields added to this connection.

ConnectionManager example

import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.intenso.jira.plugins.admanager.api.ConnectionManager

@WithPlugin("com.intenso.jira.plugins.ad-integration-manager")
@PluginModule
ConnectionManager connectionManager

def connectionName = "Active_Directory_server"
def connection = connectionManager.getConnection(connectionName)

UserAttributeManager

method description
UserFieldDTO getField(Integer id); Returns a UserFieldDTO based on the field ID.
UserFieldDTO getField(Integer connectionId, String fieldNameInAD); Returns a UserFieldDTO based on the connection ID and the User Attribute field name in Active Directory.
UserFieldDTO getField(String connectionName, String fieldNameInAD); Returns a UserFieldDTO based on the connection name and the User Attribute field name in Active Directory.
Map<String, String> getAttributes(String userKeyOrName, Integer connectionId); Returns a Map of User Attributes (Field name in Jira, Value) for userKey or username with Connection based on the connection ID.
Map<String, String> getAttributes(String userKeyOrName, String connectionName); Returns a Map of User Attributes (Field name in Jira, Value) for userKey or username with Connection based on the connection name.
Map<String, String> getAttributes(ApplicationUser user, Integer connectionId); Returns a Map of User Attributes (Field name in Jira, Value) for user with Connection based on the connection ID.
Map<String, String> getAttributes(ApplicationUser user, String connectionName); Returns a Map of User Attributes (Field name in Jira, Value) for user with Connection based the connection name.
String getAttribute(String userKeyOrName, Integer fieldId); Returns a User Attribute for userKey or username and Field based on the field ID.
String getAttribute(ApplicationUser user, Integer fieldId); Returns a User Attribute for user and Field based on the field ID.
String getAttribute(String userKeyOrName, Integer connectionId, String fieldNameInJira); Returns a User Attribute value for userKey or username, Connection based on the connection ID, and Field based on the Attribute field name in Jira.
String getAttribute(ApplicationUser user, Integer connectionId, String fieldNameInJira); Returns a User Attribute value for user, Connection based on the connection ID, and Field based on the Attribute field name in Jira.
String getAttribute(String userKeyOrName, String connectionName, String fieldNameInJira); Returns a User Attribute value for userKey or username, Connection based on the connection id, and Field based on the Attribute field name in Jira.
String getAttribute(ApplicationUser user, String connectionName, String fieldNameInJira); Returns a User Attribute value for user, Connection based on the connection name, and Field based on the Attribute field name in Jira.

UserFieldDTO

method description
int getId(); Returns the field ID.
int getConfigurationId(); Returns the connection configuration ID in which it has been added.
String getNameInAd(); Returns the Attribute Name in Active Directory.
String getNameInJira(); Returns the Attribute Name in Jira.
String getDescription(); Returns the Attribute description.
boolean isReferenceToUser(); Returns true if the field is a reference to a user in Active Directory.
boolean isShowOnPanel(); Returns true if the field is shown in the User Profile page.
boolean isShowInHover(); Returns true if the field is shown in the User Hover page.

UserAttributeManager example

import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.intenso.jira.plugins.admanager.api.UserAttributeManager
import com.intenso.jira.plugins.admanager.api.dto.UserFieldDTO

@WithPlugin("com.intenso.jira.plugins.ad-integration-manager")
@PluginModule
UserAttributeManager userAttributeManager

def connectionName = "Active_Directory_server"
def userName = "jsmith"
def userFieldNameInJira = "Manager"

def attributesMap = userAttributeManager.getAttributes(userName, connectionName)
def attribute = userAttributeManager.getAttribute(userName, connectionName, userFieldNameInJira)
UserFieldDTO userFieldDTO = userAttributeManager.getField(0);

GroupAttributeManager

method description
GroupFieldDTO getField(Integer id); Returns a GroupFieldDTO based on the field ID.
GroupFieldDTO getField(Integer connectionId, String fieldNameInAd); Returns a GroupFieldDTO based on the connection ID and Group Attribute field name in Active Directory.
GroupFieldDTO getField(String connectionName, String fieldNameInAd); Returns a GroupFieldDTO based on the connection name and Group Attribute field name in Active Directory.
Map<String, String> getAttributes(String groupName, Integer connectionId); Returns a Map of Group Attributes (Field name in Jira, Value) for group name with Connection based on the connection ID.
Map<String, String> getAttributes(String groupName, String connectionName); Returns a Map of Group Attributes (Field name in Jira, Value) for group name with Connection based on the connection name.
String getAttribute(String groupName, Integer fieldId); Returns a Group Attribute for the group name and Field based on the field ID.
String getAttribute(String groupName, Integer connectionId, String fieldNameInJira); Returns a Group Attribute for the group name, Connection based on the connection ID, and Field based on the Attribute field name in Jira.
String getAttribute(String groupName, String connectionName, String fieldNameInJira); Returns a Group Attribute for the group name, Connection based on the connection ID, and Field based on the Attribute field name in Jira.

GroupFieldDTO

method description
int getId(); Returns the field ID.
int getConfigurationId(); Returns the connection configuration ID in which it has been added.
String getNameInAd(); Returns the Attribute Name in Active Directory.
String getNameInJira(); Returns the Attribute Name in Jira.
boolean isReferenceToUser(); Returns true if the field is a reference to a user in Active Directory.

GroupAttributeManager example

import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.intenso.jira.plugins.admanager.api.GroupAttributeManager

@WithPlugin("com.intenso.jira.plugins.ad-integration-manager")
@PluginModule
GroupAttributeManager groupAttributeManager

def connectionName = "Active_Directory_server"
def groupName = "IT Department"
def groupFieldName = "Group Manager"

def attributesMap = groupAttributeManager.getAttributes(groupName, connectionName)
def attribute = groupAttributeManager.getAttribute(groupName, connectionName, groupFieldName)

Interface ActiveDirectoryAttributeManager (deprecated)

The following table lists attributes included in the package com.intenso.jira.plugins.admanager.util; with short descriptions and examples.

Table: List of attributes

Modifier and type Method and description Example
List getConnections()
Returns a list of Connections with Active Directory Server defined in the app.
-
Connection getConnection(Integer connectionId)
Returns a Connection based on the connection ID.
getConnection(5)
Returns a Connection based on connection ID “5”.
Connection getConnection(String connectionName)
Returns a Connection based on connection name.
getConnection("myActiveDirectory")
Returns a Connection based on connection name “myActiveDirectory”.
Field getField(Integer Id)
Returns a Field based on the field ID.
getField(12)
Returns a Field based on the field ID “12”.
Field getField(Integer connectionId, String fieldNameInAD)
Returns a Field based on the connection ID and Attribute field name in Active Directory.
getField(5, "telephoneNumber")
Returns a Field based on connection ID “5” and Attribute name in Active Directory “telephoneNumber”.
Field getField(String connectionName, String fieldNameInAD)
Returns a Field based on the connection name and Attribute field name in Active Directory.
getField("myActiveDirectory", "telephoneNumber")
Returns a Field based on connection name “myActiveDirectory” and Attribute field name in Active Directory “myActiveDirectory”.
Map<String, String> getUserAttributes(String userKey, Integer connectionId)
Returns a Map of Attributes (Field name in Jira, Value) for userKey with Connection based on the connection ID.
def attributes = ADManager.getUserAttributes ("jSmith", 5)
attributes.get("Telephone Number")
Returns Map of Attributes equals “Telephone Number” for userKey “jSmith” and connection ID “5”.
Map<String, String> getUserAttributes (String userKey, String connectionName)
Returns a Map of Attributes (Field name in Jira, Value) for userKey with Connection based on the connection name.
getUserAttributes ("jSmith", "myActiveDirectory")
Returns Map of Attributes for userKey “jSmith” and connection name “myActiveDirectory”.
Map<String, String> getUserAttributes (ApplicationUser user, Integer connectionId)
Returns a Map of Attributes (Field name in Jira, Value) for user with Connection based on the connection ID.
getUserAttributes (user, 5)
Returns Map of Attributes for user “user” and connection ID “5”.
Map<String, String> getUserAttributes (ApplicationUser user, String connectionName)
Returns a Map of Attributes (Field name in Jira, Value) for user with Connection based connection name.
getUserAttributes (user, "myActiveDirectory")
Returns Map of Attributes for user “user” and connection name “myActiveDirectory”.
String getUserAttribute (String userKey, Integer fieldId)
Returns the User Attribute for userKey and Field based on the field ID.
getUserAttribute ("jSmith", 12)
Returns the User Attribute for userKey “jSmith” and field ID “12”.
String getUserAttribute (ApplicationUser user, Integer fieldId)
Returns the User Attribute for user and Field based on the field ID.
getUserAttribute(user, 12)
Returns the User Attribute for userKey “user” and field ID “12”.
String getUserAttribute (String userKey, Integer connectionId, String fieldNameInJira)
Returns the User Attribute for userKey, Connection based on the connection ID, and Field based on the Attribute field name in Jira.
getUserAttribute ("jSmith", 5, "Telephone Number")
Returns User Attribute for userKey “jSmith”, connection ID “5”, and field based on the Attribute field name in Jira “Telephone Number”.
String getUserAttribute(ApplicationUser user, Integer connectionId, String fieldNameInJira)
Returns the User Attribute for user, Connection based on the connection ID, and Field based on the Attribute field name in Jira.
getUserAttribute(user, 5, "Telephone Number")
Returns User Attribute for user “user”, connection ID “5”, and field based on the Attribute field name in Jira “Telephone Number”.
String getUserAttribute(String userKey, String connectionName, String fieldNameInJira)
Returns the User Attribute for userKey, Connection based on the connection ID, and Field based on the Attribute field name in Jira.
getUserAttribute("jSmith", "myAD", "Telephone Number")
Returns User Attribute for userKey “jSmith”, connection name “myAD”, and field based on the Attribute field name in Jira “Telephone Number”.
String getUserAttribute (ApplicationUser user, String connectionName, String fieldNameInJira)
Returns the User Attribute for user, Connection based on the connection name, and Field based on theAttribute field name in Jira.
getUserAttribute (user, "myAD", "Telephone Number")
Returns User Attribute for user “user”, connection name “myAD”, and field based on the Attribute field name in Jira “Telephone Number”.

Interface Connection

The following table lists methods used in the Interface Connection with short description.

Table: List of methods

Modifier and type Method and description
Integer getID()
Returns the connection ID.
String getName()
Returns the connection name.
String getDirectoryId()
Returns a directory ID in Jira if connection has been imported from Jira. Otherwise returns null.
String getProfileTitle()
Returns a data title from Active Directory in the User Profile page.
Boolean getEnabled()
Returns true if the connection ID is enabled. Otherwise returns false.
Field[] getFields()
Returns an array of fields added to this connection.

Interface Field

The following table lists methods used in the Interface Field.

Table: List of methods

Modifier and type Method and description
Integer getID()
Returns the field ID.
Connection getConfiguration()
Returns the connection configuration in which it has been added.
String getNameInAd()
Returns the Attribute Name in Active Directory.
String getNameInJira()
Returns the Attribute Name in Jira.
String getDescription()
Returns the Attribute description.
Boolean getReffToUser()
Returns true if the field is a reference to user in Active Directory.
Boolean getShowOnPanel()
Returns true if the field is shown in the User Profile page.
Boolean getShowInHover()
Returns true if the field is shown in the User Hover page.

Example

The following example shows how to get the user attribute.


import com.atlassian.jira.component.ComponentAccessor

Class activeDirectoryAttributeManagerClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.intenso.jira.plugins.admanager.util.ActiveDirectoryAttributeManager")
def activeDirectoryAttributeManager = ComponentAccessor.getOSGiComponentInstanceOfType(activeDirectoryAttributeManagerClass)

def userManager = ComponentAccessor.getUserManager()
 
def user = userManager.getUserByKey("jSmith")
 
def attributeFromADByFieldId = activeDirectoryAttributeManager.getUserAttribute(user, 15); //get AD Attribute for user from field with ID 15
def telephoneNumber = activeDirectoryAttributeManager.getUserAttribute(jSmith, "myActiveDirectory", "Telephone Number") // get AD Attribute for user with key jSmith, connection with name "myActiveDirectory" and for field with name "Telephone Number"
 
def userAttributeMap = activeDirectoryAttributeManager.getUserAttributes(user, "myActiveDirectory") //get Map of user Attibutes for connection "myActiveDirectory"
def telephoneNumber = userAttributeMap.get("Telephone Number") //get Attribute from Map`

Non-ScriptRunner scripts

In the non-ScriptRunner scripts (such as Insight Script Console) the following ScriptRunner annotations won’t work:


import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.customisers.PluginModule

That is why the API has to be imported as below:

ConnectionManager


import com.atlassian.jira.component.ComponentAccessor;

Class connectionManagerClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.intenso.jira.plugins.admanager.api.ConnectionManager")
def connectionManager = ComponentAccessor.getOSGiComponentInstanceOfType(connectionManagerClass)

def connectionName = "Active_Directory_server"
def connection = connectionManager.getConnection(connectionName)

UserAttributeManager


import com.atlassian.jira.component.ComponentAccessor;

Class userAttributeManagerClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.intenso.jira.plugins.admanager.api.UserAttributeManager")
def userAttributeManager = ComponentAccessor.getOSGiComponentInstanceOfType(userAttributeManagerClass)

def connectionName = "Active_Directory_server"
def userName = "jsmith"
def userFieldNameInJira = "Manager"

def attributesMap = userAttributeManager.getAttributes(userName, connectionName)
def attribute = userAttributeManager.getAttribute(userName, connectionName, userFieldNameInJira)
def userFieldDTO = userAttributeManager.getField(0);

GroupAttributeManager


import com.atlassian.jira.component.ComponentAccessor;

Class groupAttributeManagerClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.intenso.jira.plugins.admanager.api.GroupAttributeManager")
def groupAttributeManager = ComponentAccessor.getOSGiComponentInstanceOfType(groupAttributeManagerClass)

def connectionName = "Active_Directory_server"
def groupName = "IT Department"
def groupFieldName = "Group Manager"

def attributesMap = groupAttributeManager.getAttributes(groupName, connectionName)
def attribute = groupAttributeManager.getAttribute(groupName, connectionName, groupFieldName)

Need help?

If you can’t find the answer you need in our documentation, raise a support request.