5 Usage - Reference Documentation
Authors: Lucas Rockwell
Version: 0.5.0
5 Usage
Overview
As noted in the Introduction,DirectoryService
is inspired by GORM. Therefore, the methods should be intuitive. This section gives you a brief overview, but please see the Reference Guide for details of each method.How it Works
For more in-depth details of howDirectoryService
works, please see the other sections of this guide, including the ref:DirectoryService pages.Add DirectoryService to your class
Once you haveDirectoryService
configured, you can add it to a class the way you would any other service:def directoryService
Search for an object
Now you can search for something in your directory (again, see the Configuration section) like this:def people = directoryService.findPeopleWhere('departmentNumber':'12345', 'manager':'3786258')
DirectoryServiceEntry
objects. A DirectoryServiceEntry
object is a wrapper around an UnboundID Entry
object, so everything you can do with an Entry
object is available to you.Use the results
Once you perform a search, you can then use the object the way you would use a GORM object:people.each { person ->
println "${person.displayName}, ${person.telephoneNumber}"
}
telephoneNumber
defined in their entry? Nothing! The attribute doesn't exist, it doesn't print anything. This is possible because DirectoryService
is based on the UnboundID LDAP SDK, and that SDK allows you to ask for attribute values on attributes that do not exist in the entry, with no ill effects, i.e., no exceptions are thrown. However, the call does return null
if there is no attribute with the provided name, so it is best to use the "?" operator if you plan to do something with the value, if that something you plan to do does not like null
objects.To see how the UnboundID LDAP SDK is being used here, the above person.displayName
could also be accomplished with the following:person.getEntry().getAttributeValue("displayName")
getAttributeValue
, so if you want the attribute values, then you would have to use the special Values()
method:person.cnValues()
Operations Implemented
As of the current release,find
(search
), and save
(modify
) are implemented. add
and delete
will be added in upcoming releases. See the roadmap for details.