(Quick Reference)

find

Purpose

The find method allows you to search for objects in the DIT as defined in grails.plugins.directoryService.dit. See the Configuration section on details of how grails.plugins.directoryService.dit is defined.

Currently, Where is implemented as a dynamic finder. I hope to be able to add the By dynamic finder in a future release (e.g., find*BySnAndDepartmentNumber).

Examples

These examples assume the following was defined in directoryService.dit:

grails.plugins.directoryService.dit = [
    'ou=people,dc=socialidm,dc=com':[
        singular: 'person',
        plural: 'people',
        rdnAttribute: 'uid',
        source: 'directory'
    ]
]

In the above configuration, we defined that the 'singular' version of this branch as 'person', and the 'plural' version as 'people'.

To understand how these work, see the examples, below:

// Find one 'person', i.e., person is 'singular'
directoryService.findPersonWhere('uid':'12345')

// Even if you use an attribute that would potentially return more than one, // you are only going to get one result with the 'singular' version! directoryService.findPersonWhere('sn':'rockwell')

// Find 'people', i.e., people is the 'plural' version directoryService.findPeopleWhere('departmentNumber':'12345', 'manager':'0128653')

// find also allows you to specify a simple string as a filter directoryService.findPeopleWhere('(|(sn=rockwell)(sn=smith))')

// You can not use a wildcard * or ? in a simple string filter because it will // get escaped, so you have to use an UnboundID LDAP SDK Filter if you want // a more complicated filter def filter = <an UnboundID LDAP SDK Filter> directoryService.findPeopleWhere(filter)

DirectoryService ANDs together the arguments to the find method. If you want OR, or more complicated filters, like ones with wildcards, then you will have to construct an UnboundID LDAP SDK Filter and supply that as the argument to find.

Description

Unlike GORM, with DirectoryService you do not define concrete classes which are then used to find objects. For instance, with GORM, you might have a Person domain class, and then you would find people like this:

// Returns zero or at most one
Person.findWhere('lastName':'rockwell')

// Returns zero or more than one Person.findAllWhere('lastName':'rockwell')

With DirectoryService, you use the singular and plural versions of the DIT branches (as defined in directoryService.dit) to determine if you want one or more results.

// Returns zero or at most one
directoryService.findPersonWhere('lastName':'rockwell')

// Returns zero or more than one directoryService.findPeopleWhere('lastName':'rockwell')

The table below compares the GORM and DirectoryService find differences.

Number of ResultsGORMDirectoryService
0 or 1findWherefindPersonWhere
0 or morefindAllWherefindPeopleWhere

In these examples, 'person' and 'people' are used only because they were defined in grails.plugins.directoryService.dit. If you define other names in grails.plugins.directoryService.dit, then you would have to use those names.