You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@directory.apache.org by Shing Hing Man <ma...@yahoo.com> on 2007/04/15 20:21:51 UTC

Problem adding new object class

I am trying to add a new object class in Java using
the 
sample code at 
http://java.sun.com/products/jndi/tutorial/ldap/schema/object.html#ADD
(or see the listing  below).
But I get the following exception.



javax.naming.NameNotFoundException: [LDAP: error code
32 - failed to modify entry
2.5.4.3=schema,2.5.4.11=system: Attempt to lookup
non-existant entry: 2.5.4.3=schema,2.5.4.11=system];
remaining name ''
	at
com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3010)
	at
com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2931)
	at
com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2737)
	at
com.sun.jndi.ldap.LdapCtx.c_modifyAttributes(LdapCtx.java:1370)
	at
com.sun.jndi.toolkit.ctx.ComponentDirContext.p_modifyAttributes(ComponentDirContext.java:235)
	at
com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.modifyAttributes(PartialCompositeDirContext.java:147)
	at
com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.modifyAttributes(PartialCompositeDirContext.java:136)
	at
com.sun.jndi.ldap.LdapSchemaCtx$SchemaInfo.modifyAttributes(LdapSchemaCtx.java:413)
	at
com.sun.jndi.ldap.LdapSchemaCtx.addServerSchema(LdapSchemaCtx.java:276)
	at
com.sun.jndi.ldap.LdapSchemaCtx.doCreateSubcontext(LdapSchemaCtx.java:196)
	at
com.sun.jndi.toolkit.dir.HierMemDirCtx.createSubcontext(HierMemDirCtx.java:375)
	at
com.sun.jndi.toolkit.dir.HierMemDirCtx.createSubcontext(HierMemDirCtx.java:368)
	at
sunTrail.AddObjectClass.main(AddObjectClass.java:56)

=================================

class AddObjectClass {
   public static void main(String[] args) {

	// Set up environment for creating initial context
	Hashtable env = new Hashtable(11);
	env.put(Context.INITIAL_CONTEXT_FACTORY, 
	    "com.sun.jndi.ldap.LdapCtxFactory");
	env.put(Context.PROVIDER_URL,
"ldap://localhost:10389/o=JNDITutorial");

	// Must authenticate as directory administrator in
order to update schema
	String dns = "uid=admin,ou=system";
	env.put(Context.SECURITY_PRINCIPAL, dns);
	env.put(Context.SECURITY_CREDENTIALS, "jrisk");
	env.put(Context.SECURITY_AUTHENTICATION, "simple");

	// This is required when using Netscape Directory
Server 3.x
	// env.put("com.sun.naming.netscape.schemaBugs",
"true");

	try {
	    // Specify attributes for schema object
	    Attributes attrs = new BasicAttributes(true); //
ignore case
	    attrs.put("NUMERICOID",
"1.3.6.1.4.1.42.2.27.4.2.3.1.1.1");
	    attrs.put("NAME", "fooObjectClass");
	    attrs.put("DESC", "for JNDITutorial example
only");
	    attrs.put("SUP", "top");
	    attrs.put("STRUCTURAL", "true");
	    Attribute must = new BasicAttribute("MUST",
"cn");
	    must.add("objectclass");
	    attrs.put(must);

	    // Create the initial context
	    DirContext ctx = new InitialDirContext(env);
	    // Get the schema tree root
	    DirContext schema = ctx.getSchema("");
	
	  
	    // Add new schema object for "fooObjectClass"
   	   DirContext newClass = schema.createSubcontext( 
 //<-- line 56
		"ClassDefinition/fooObjectClass", attrs);

	    // Get new initial context to avoid seeing cached
data
	    ctx.close();
	    ctx = new InitialDirContext(env);
	    schema = ctx.getSchema("");

	    // See what was added
	    System.out.println(
	
schema.getAttributes("ClassDefinition/fooObjectClass"));

	    // Close the context when we're done
	    ctx.close();
	} catch (NamingException e) {
	    e.printStackTrace();
	}
   }
}
=======================
It would be appreciated if some kind soul can tell me 
to how to resolve the above the exception.

Thanks!

Shing

Home page :
  http://uk.geocities.com/matmsh/index.html


      ___________________________________________________________ 
Yahoo! Mail is the world's favourite email. Don't settle for less, sign up for
your free account today http://uk.rd.yahoo.com/evt=44106/*http://uk.docs.yahoo.com/mail/winter07.html 

Re: Problem adding new object class

Posted by Shing Hing Man <ma...@yahoo.com>.
I was using version 1.0.0.
I have just tested adding new object class 
in version 1.5.0 and it works.

Thanks!
Shing

--- Stefan Zoerner <st...@labeo.de> wrote:

> Shing Hing Man wrote:
> > I am trying to add a new object class in Java
> using
> > the 
> > sample code at 
> >
>
http://java.sun.com/products/jndi/tutorial/ldap/schema/object.html#ADD
> > (or see the listing  below).
> > But I get the following exception.
>  > ...
> 
> Which version of ApacheDS do you use? 1.0.x does not
> support dynamic 
> changes of the schema like described in the
> Tutorial. You need the 
> upcoming 1.5 to do something like that.
> 
>
http://www.apache.org/dyn/closer.cgi/directory/apacheds/unstable/1.5/1.5.0
> 
> I have tested the code of the JNDI tutorial against
> this version and it 
> works just fine.
> 
> The most strange in your stacktrace is the line
> Attempt to lookup
> non-existant entry: 2.5.4.3=schema,2.5.4.11=system
> 
> The schema in the 1.5 is located in its own
> partition ou=schema, and not 
> below ou=system.
> 
> Greetings from Hamburg,
>      Stefan
> 
> 
> 
> 
> 
> 


Home page :
  http://uk.geocities.com/matmsh/index.html


      ___________________________________________________________ 
Yahoo! Mail is the world's favourite email. Don't settle for less, sign up for
your free account today http://uk.rd.yahoo.com/evt=44106/*http://uk.docs.yahoo.com/mail/winter07.html 

Re: Problem adding new object class

Posted by Stefan Zoerner <st...@labeo.de>.
Shing Hing Man wrote:
> I am trying to add a new object class in Java using
> the 
> sample code at 
> http://java.sun.com/products/jndi/tutorial/ldap/schema/object.html#ADD
> (or see the listing  below).
> But I get the following exception.
 > ...

Which version of ApacheDS do you use? 1.0.x does not support dynamic 
changes of the schema like described in the Tutorial. You need the 
upcoming 1.5 to do something like that.

http://www.apache.org/dyn/closer.cgi/directory/apacheds/unstable/1.5/1.5.0

I have tested the code of the JNDI tutorial against this version and it 
works just fine.

The most strange in your stacktrace is the line
Attempt to lookup
non-existant entry: 2.5.4.3=schema,2.5.4.11=system

The schema in the 1.5 is located in its own partition ou=schema, and not 
below ou=system.

Greetings from Hamburg,
     Stefan