directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Zoerner <>
Subject Using a CoreSession in embeded mode to perform a search
Date Thu, 21 May 2009 18:54:14 GMT
Hi all,

currently I implement an Apache Tomcat Realm which embeds ApacheDS and 
uses it for authentication and authorization. The thing already works 
and looks quite promising, I will post a first version at weekend on 
this list in order to get some feedback.

During implementation, I tried to avoid JNDI calls and used the 
CoreSession interface which I can get from DirectoryService.

Code (which searches a user entry by uid) goes like this:

CoreSession adminSession = directoryService.getAdminSession();

String base = "ou=system";
LdapDN basedn = new LdapDN(base);
SearchScope scope = SearchScope.SUBTREE;
MessageFormat f = new MessageFormat(
String sFilter = f.format(new Object[] { username });

ExprNode filter = FilterParser.parse(sFilter);
EntryFilteringCursor cursor =, scope,
		filter, AliasDerefMode.NEVER_DEREF_ALIASES, null, 0, 0);
CursorIterator iter = new CursorIterator(cursor);
if (iter.hasNext()) {
     ServerEntry entry = (ServerEntry);
     dn = entry.getDn();

I am not happy with the use of CursorIterator (especially the cast). 
Anybody a better idea how to perform a search and process the results 
from an embedded server?

If needed, complete code can be found here

Thanks in advance,

View raw message