|
Page Edited :
DIRxSBOX :
Groovy LDAP
Groovy LDAP has been edited by Stefan Zoerner (Feb 16, 2009). Content:Groovy LDAPLearn about an attempt to make LDAP available from Groovy scripts in a way, LDAP people would expect. Feel free to provide feedback: dev@directory.apache.org
Mission StatementCreate a way to access LDAP from Groovy scripts, which is suitable for people familiar to LDAP. Primary audience are people who plan to write simple scripts against their LDAP servers. This is not about LDAP abstraction. The API should be comparable to the native LDAP library for C, in order to provide an easy start for the primary target group. Nevertheless it should "smell" like other Groovy integration solutions (namely GSQL) do. Especially the use of closures is planned. In order to reduce the number of dependencies, nothing besides Java SE and Groovy itself should be used. JNDI will therefore be used under the hood to communicate with LDAP.
How it looks like in GroovyHere are two examples script which use Groovy LDAP in order to give you a first impression. Learn more about how to use Groovy LDAP in the User Guide. Adding an entryThe attribute values of an LDAP entry can be defined with the help of the expressive Map syntax of Groovy ([...]). The following script uses the add operation to create a new entry in the directory: import org.apache.directory.groovyldap.LDAP
ldap = LDAP.newInstance('ldap://zanzibar:10389', 'uid=admin,ou=system', '******')
heather = [
objectclass: ['top', 'person'],
sn: 'Nova',
cn: 'Heather Nova'
]
ldap.add('cn=Heather Nova,dc=example,dc=com', heather)
In LDIF format, the entry in the directory looks like this afterwards. dn: cn=Heather Nova,dc=example,dc=com cn: Heather Nova sn: Nova objectClass: person objectClass: top Performing an LDAP search with a closureBesides the operations found in the classic LDAP API, Groovy LDAP provides advanced functionality with the help of features specific to the Groovy language. Here is an example which performs a search operation, and executes the behavior given via a closure for each entry found: import org.apache.directory.groovyldap.LDAP
ldap = LDAP.newInstance('ldap://zanzibar:10389/dc=example,dc=com')
ldap.eachEntry (filter: '(objectClass=person)') { entry ->
println "${entry.cn} (${entry.dn})"
}
The example also shows how to access attributes and the distinguished name (DN) of an entry (Map syntax, as well). The output looks like this: Tori Amos (cn=Tori Amos,dc=example,dc=com) Kate Bush (cn=Kate Bush,dc=example,dc=com) Heather Nova (cn=Heather Nova,dc=example,dc=com) ... Current statusCreation of the solution has just been started. We do not know, whether it will become an official project with releases and so (no official release yet). Even the name is not final yet. The current version only supports five of the LDAP operations (search, add, delete, compare, modify) explicitly. AlternativesThere are other efforts to bring the Groovy and the LDAP World together. Where to go from here
|