0

I am working on a use case where I have to dynamically add a new attribute to an existing object class in Apache DS.

1)Here is some code which defines my object class:--

        Attributes attrs = new BasicAttributes(true);
        attrs.put("NUMERICOID", "1.3.6.1.4.1.18060.0.4.3.3.1");
        attrs.put("NAME", "ship");
        attrs.put("DESC", "An entry which represents a ship");
        attrs.put("SUP", "top");
        attrs.put("STRUCTURAL", "true");

        Attribute must = new BasicAttribute("MUST");
        must.add("cn");
        attrs.put(must);

        Attribute may = new BasicAttribute("MAY");
        may.add("numberOfGuns");
        may.add("numberOfGuns2");
        may.add("description");
        attrs.put(may);

        //add
        schema.createSubcontext("ClassDefinition/ship", attrs);

2) Adding an object of that object class:

Attributes attributes=new BasicAttributes();
Attribute objectClass=new BasicAttribute("objectClass");
objectClass.add("ship");
attributes.put(objectClass);

Attribute g=new BasicAttribute("numberOfGuns");
Attribute g2=new BasicAttribute("numberOfGuns2");
Attribute cn=new BasicAttribute("cn");


g.add("2");
g2.add("3");
cn.add("four");


attributes.put(g);
attributes.put(cn);
attributes.put(g2);
;

ctx.createSubcontext("cn=four,dc=example,dc=com",attributes);

3) Add a new attribute -- 'mustA' to the object class

        Attributes attrs = new BasicAttributes(true);
        attrs.put("NUMERICOID", "1.3.6.1.4.1.18060.0.4.3.3.1");
        attrs.put("NAME", "ship");
        attrs.put("DESC", "An entry which represents a ship");
        attrs.put("SUP", "top");
        attrs.put("STRUCTURAL", "true");

        Attribute must = new BasicAttribute("MUST");
        must.add("cn");
        must.add("mustA");
        attrs.put(must);

        Attribute may = new BasicAttribute("MAY");
        may.add("numberOfGuns");
        may.add("numberOfGuns2");
        may.add("description");
        attrs.put(may);

        //modify
        schema.modifyAttributes("ClassDefinition/ship",DirContext.ADD_ATTRIBUTE ,attrs);

Once the new attribute is added(which means object class is modified), If i add a new object of that object class type, I can see the newly added attribute in the newly created object.

My Question is, What happens to the objects which were created before I added the new attribute? How can I make the new attribute to show up in the exiting objects automatically? For example, here will the new attribute "mustA" automatically show up in object "four"?

Or Will I have to manually go and modify that object to add that new attribute?

Neha
  • 225
  • 1
  • 5
  • 12

1 Answers1

0

You will need to update the schema. For ApacheDS the easiest method is to download Apache Studio and take a look at 2.3.1 - Adding Schema Elements

Oh, and you will always get great support from The Directory Users List for ApacheDS. The developers are very active.

AFIK, ApacheDs will support adding schema from LDAP calls, but I am not positive. (See The Directory Users List for ApacheDS)

If you insist doing this the hard way, check out the examples at: http://docs.oracle.com/javase/jndi/tutorial/ldap/schema/object.html

-jim

jwilleke
  • 10,467
  • 1
  • 30
  • 51
  • Thanks for your answer. I want to do all this with JNDI, without using Apache Directory Studio – Neha Oct 22 '14 at 06:28
  • So did you look at: http://docs.oracle.com/javase/jndi/tutorial/ldap/schema/object.html – jwilleke Oct 28 '14 at 11:05
  • Yes Jim, The link has information about how to create object class and modify it etc., but does not say anything about the impact on the existing entries of the modified object class. From what I tired, I figured out that after modifying the object class like adding a new attribute to it, one should modify each and every existing entry for that object class. I was wondering if their is a way to refresh the exiting entries so that they show up the new attribute automatically. – Neha Oct 30 '14 at 09:56
  • The attribute will be available on each entry which have the modified obujectClass. As with many LDAP server implementations, You must restart the server if you want to use the added AttributeTypes or ObjectClasses as the schema is currently not dynamic in ApacheDS. – jwilleke Oct 30 '14 at 11:11