dcsimg
Creating SubContexts In JNDI but trying to hide from LDAP
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Nicholas_Whitehead
Posted On:   Tuesday, February 26, 2002 11:27 AM

I am writing an interface that binds objects into a JNDI tree using a supplied and arbitrary name, as well as an arbitrary JNDI connection. So for example, I may be connected to WebLogic JNDI, in which case I might be passed a name/object pair of "/nicholas/myObj" / object This works fine in most cases as most JNDI implementations are very tolerant. It was very easy to parse the name and create the subcontext, if required. My problem started when I started to do the same for LDAP, because even though the names passed to me were compliant, and I was able to parse and build names correctly, subcontexts in LDAP must have ayttributes that are compliant with the schema.    More>>

I am writing an interface that binds objects into a JNDI tree using a supplied and arbitrary name, as well as an arbitrary JNDI connection.

So for example, I may be connected to WebLogic JNDI, in which case I might be passed a name/object pair of


"/nicholas/myObj" / object

This works fine in most cases as most JNDI implementations are very tolerant. It was very easy to parse the name and create the subcontext, if required.

My problem started when I started to do the same for LDAP, because even though the names passed to me were compliant, and I was able to parse and build names correctly, subcontexts in LDAP must have ayttributes that are compliant with the schema.

I am wondering if there is a flexible and open way to determine what the restrictions in the schema are, and transparently add attributes accordingly. I have resorted to doing this:



Context ctx2 = null;

if(ctx.getEnvironment().get(Context.INITIAL_CONTEXT_FACTORY).toString().toUpperCase().indexOf("LDAP")!=-1) {

ldap = true;

ctx2 = new InitialDirContext(ctx.getEnvironment());

} else {

ctx2 = new InitialContext
(ctx.getEnvironment());
ldap=false;

}



and then later



if(ldap) {

((DirContext)ctx2).createSubcontext(part, new BasicAttributes("objectclass", "organizationalUnit"));

} else {

ctx2 = ctx2.createSubcontext(part);

}



This works, but it is a hack and I am sure it will break eventually. Does anyone have any suggestions for improvement ?


//Nicholas

   <<Less
About | Sitemap | Contact