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

More info about the class


@GrabResolver(name='apache-snapshot', root='http://repository.apache.org/snapshots/')
@Grab(group='org.apache.directory', module='groovyldap', version='0.1-SNAPSHOT')

import org.apache.directory.groovyldap.*

log.setLevel(org.apache.log4j.Level.DEBUG)
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 = ldap.search('(objectClass=user)', 'DC=example,DC=com', SearchScope.SUB )
log.debug "# Entries found: ${results.size}"
//for (entry in results) {
// log.debug "User: "+ entry.cn;
// break;
//}
}

/*
ADD NEW USER
heather = [
objectclass: ['top', 'person'],
sn: 'Nova',
cn: 'Heather Nova'
]

ldap.add('cn=Heather Nova,dc=example,dc=com', heather)
*/
/*
MODIFY NEW USER
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:.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s