Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3
Note

This package is not actively maintained, but it will be re-released once it has been reworked as time permits.

Gldapwrap - Usage

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
java
java
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
java
java
import gldapwrap.GldapwrapTemplate

def template = new GldapwrapTemplate(
	url: "ldap://example.com",
	base: "dc=example,dc=com",
	userDn: "cn=admin,dc=example,dc=com",
	password: "secret"
)

Next you need to inject the template into your schema class.

Code Block
java
java
import gldapwrap.GldapwrapInjector(MyLdapEntry, template)

Now you can do searches.

Code Block
java
java
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.