The best way is using @Grab to download in Runtime the LDAP library from servers.

More info about the class

@GrabResolver(name='apache-snapshot', root='')
@Grab(group='', module='groovyldap', version='0.1-SNAPSHOT')


log.debug "Connecting EXAMPLE LDAP..."
ldap = LDAP.newInstance('ldap://server:port/', 'CN=LDAP User, CN=Users,DC=example,DC=com', '******')
log.debug "Connection completed"
log.debug "Verifying if Raul Pelaez exists in the 9th dimension...."
exists = ldap.exists('cn=Raul Pelaez,dc=example,dc=com')
if (exists) {
log.debug "Yes... he exists!"
log.debug "Searching users"
results ='(objectClass=user)', 'DC=example,DC=com', SearchScope.SUB )
log.debug "# Entries found: ${results.size}"
//for (entry in results) {
// log.debug "User: "+;
// break;

heather = [
objectclass: ['top', 'person'],
sn: 'Nova',
cn: 'Heather Nova'

ldap.add('cn=Heather Nova,dc=example,dc=com', heather)
dn = 'cn=Heather Nova,dc=example,dc=com'

// Adding a single attribute
descr = [ description: 'a singer-songwriter' ]
ldap.modify(dn, 'ADD', descr)

// performing two operations atomically
mods = [
[ 'REPLACE', [description: 'a singer-songwriter, born in Bermuda'] ],
[ 'ADD', [userPassword: 'secret'] ]
ldap.modify(dn, mods)

Posted by:.

2 replies on “How to connect to LDAP with Groovy in JIRA

  1. i want to send mail alert to jira user who is not logged in last 30 days which sholud be automatic mail alert system how to write the groovy code or any polugins to this


    1. Hi Mahendar,

      Please use a mix with these lines:


      def loginManager = ComponentAccessor.getComponentOfType(LoginManager.class)
      Long lastLoginTime = loginManager.getLoginInfo(

      And to obtain the users of the Jira Directory (and send a mail):

      And to send a mail using groovy:

      Best regards


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s