...
Gldapwrap - Usage
| Info | ||
|---|---|---|
| ||
All Gladwrap Gldapwrap classes are in the gldapwrap.* namespace. |
There are three main components to Gladwrap:
- Gladwrap Schemas
- Templates
- Gladwrap Injection
– TODO: Above points need to link to relavant pages
Injection
Before you can use a Gladwrap schema you must inject it. You can either inject it with a template ...To use Gldapwrap, you need to make sure the Gldapwrap jar is in your classpath as well as the Spring LDAP jars (provided in the download). An easy way to do this is to to put the jars in ~/.groovy/lib/.
First thing you need to do is define a schema class. A schema class is just an ordinary POGO.
| Code Block | ||
|---|---|---|
| ||
class MyLdapEntry
{
List objectclass
String distinguisheName
}
|
That's all you need to do to define a schema.
Next is to create a GldapwrapTemplate which is basically the details of the LDAP server you want to connect to.
| Code Block | ||
|---|---|---|
| ||
import gladwrapgldapwrap.*GldapwrapTemplate def template = new GladwrapTemplateGldapwrapTemplate( userDnurl: "cn=user,dc=example,dc=ldap://example.com", passwordbase: "secret", url: "ldap://example.dc=example,dc=com", baseuserDn: "cn=admin,dc=example,dc=com", password: "secret" ) GladwrapInjector.inject(SomeGladWrapSchema |
Next you need to inject the template into your schema class.
| Code Block | ||
|---|---|---|
| ||
import gldapwrap.GldapwrapInjector(MyLdapEntry, template)
|
or inject it and add the template later ...Now you can do searches.
| Code Block | ||
|---|---|---|
| ||
GladwrapInjector.inject(SomeGladWrapSchema) GladwrapInjector.setLdapTemplate(template) List entries = MyLdapEntry.find() // Find all entries at base entries = MyLdapEntry.find( filter: "(objectclass=person)", searchScope: javax.naming.directory.SearchControls.SUBTREE_SCOPE ) // Find all people in the whole directory entries = MyLdapEntry.find( filter: "(objectclass=person)", searchScope: javax.naming.directory.SearchControls.SUBTREE_SCOPE base: "ou=People" countLimit: 50 ) // Find the first 50 people in the directory under the people OU |
See Searching for more detail about searching.