How to extend schema using JNDI in Active Directory
Hi,
I am a newbie to JNDI and schema extension. I have an Active Directory setup on win2k3. I was trying the following example to add an attribute to the schema, but i am getting the following error.
javax.naming.NameNotFoundException: [LDAP: error code 32 - 0000208D: NameErr: DSID-031001C6, problem 2001 (NO_OBJECT), data 0, best match of:
'CN=Schema,CN=Configuration,DC=ric,DC=com';
remaining name 'CN=fooattr,CN=Schema,CN=Configuration,DC=ric,DC=com'
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.c_createSubcontext(Unknown Source)
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_createSubcontext(Unknown Source)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.createSubcontext(Unknown Source)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.createSubcontext(Unknown Source)
at AddAttr.main(AddAttr.java:52)
Here is the code is was trying
import java.util.Hashtable;
import javax.naming.ldap.LdapContext;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.*;
import javax.naming.directory.*;
publicclass AddAttr{
publicstaticvoid main(String[] args){
// Open an LDAP association
try
{
Hashtable env =new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL,"ldap://schema-test:389");
env.put(Context.SECURITY_PRINCIPAL,"cn=administrator,cn=users,dc=ric,dc=com");
env.put(Context.SECURITY_CREDENTIALS,"notallowed");
LdapContext ctx =new InitialLdapContext(env,null);
String snc ="schemaNamingContext";// DSE attribute
Attributes attrs = ctx.getAttributes("",new String[]{ snc});
DirContext schema = (DirContext)ctx.lookup((String) attrs.get(snc).get());
String dn = schema.getNameInNamespace();
Attributes attr =new BasicAttributes(true);
attr.put("cn","fooattr");
attr.put("objectClass","attributeSchema");
attr.put("ldapDisplayName","fooattr");
attr.put("isSingleValued","TRUE");
attr.put("attributeID","1.3.6.1.4.1.791.2.3.5.5.1.4.4");
attr.put("attributeSyntax","2.5.5.9");
schema.createSubcontext("CN=fooattr," + dn,attr);
// Close the LDAP association
ctx.close();
}
catch(Exception exc)
{
exc.printStackTrace();
}
}
}
Can anyone suggest what am i doing wrong here. Also, please suggest me any documentation for schema extension using jndi.
Thanks & Regards,
kelloogo

