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(
"(&(objectClass=person)(uid={0}))");
String sFilter = f.format(new Object[] { username });
ExprNode filter = FilterParser.parse(sFilter);
EntryFilteringCursor cursor = adminSession.search(basedn, scope,
filter, AliasDerefMode.NEVER_DEREF_ALIASES, null, 0, 0);
CursorIterator iter = new CursorIterator(cursor);
if (iter.hasNext()) {
ServerEntry entry = (ServerEntry) iter.next();
dn = entry.getDn();
}
adminSession.unbind();
...
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
https://svn.apache.org/repos/asf/directory/sandbox/szoerner/apacheds-tomcatrealm
Thanks in advance,
StefanZ