DirStateFactory and Active Directory
Hi,
is it possible to use DirObjectFactory/DirStateFactory to implement object bindings with an Active Directory Server? I havent found any code example using this approach. Or is it impossible because of Microsofts implementation of LDAP?
Thanks in advance.
[277 byte] By [
azillya] at [2007-11-27 11:43:37]

# 1
I will readily admit that I am not a Java developer, but from my scant reading, it appears as though the two interfaces are implemented when developers write their own object factories.
Do you have any samples of using DirObjectFactory or DirStateManager with other LDAP directories ?
There certainly aren't any problems in accessing Active Directory via the JNDI LDAP provider, but I don't know whether that answers yoru question.
# 2
//...
public class ExStateFactory implements DirStateFactory {
@Override
public Result getStateToBind(Object obj, Name name, Context nameCtx,
Hashtable<?, ?> environment, Attributes inAttrs)
throws NamingException {
if (obj instanceof Employee) {
Employee mdb = (Employee) obj;
Attributes outAttrs;
outAttrs = new BasicAttributes(true);
Attribute ocls = new BasicAttribute("objectClass");
ocls.add("top");
ocls.add("person");
ocls.add("organizationalPerson");
ocls.add("inetOrgPerson");
outAttrs.put(ocls);
outAttrs.put("sn", mdb.getSurname());
outAttrs.put("cn", mdb.getCommonname());
outAttrs.put("uid", mdb.getUserID());
//...
return new DirStateFactory.Result(null, outAttrs);
}
return null;
}
}
public static void main(String[] args) throws NamingException {
InitialDirContext ctx = new InitialDirContext();
// Creating an Employee-Object
// ...
String name =" ... ";//the name to bind; may not be empty
ctx.bind(name , EmployeeObject );
}
The advantage of this approach is encapsulation of the mapping. This way its possible to
imlement different StateFactories depending on the current context.
With OpenLDAP for example a new user is created or -if it already exists - modifiyed.
Most examples creating users in an Active Directory work like this:
//...
Context result = ictContext.createSubcontext(userName, outAttributes);
So my question:
is it possible - given the correct context - implementing StateFactory with an Active Directory (given the difference between bind() and createSubcontext())
Thanks in advance
Andreas