Back Forum Reply New

How to modify objectclass?

If I have a ldap schema that defines an object hierarchy of Alt;-Blt;-C and then create an instance of B in the directory is it then possible to change the objectclass to C???

I have tried the following but get an exception:Code:
try {   DirContextOperations ops = template.lookupContext(new DistinguishedName(quot;cn=admin2quot;));
   ops.setAttributeValues(quot;objectclassquot;, new String[] { quot;testInetOrgpersonquot;,quot;inetOrgPersonquot;,quot;organizationalPersonquot;,quot;personquot;, quot;topquot;});   template.modifyAttributes(new DistinguishedName(quot;cn=admin2quot;), ops.getModificationItems());
} catch (org..ldap.NamingException e) {   e.printStackTrace();
}

Code:
org..ldap.SchemaViolationException: [LDAP: error code 69 - structural object class modification from 'inetOrgPerson' to 'testInetOrgperson' not allowed]; nested exception is javax.naming.directory.SchemaViolationException: [LDAP: error code 69 - structural object class modification from 'inetOrgPerson' to 'testInetOrgperson' not allowed]; remaining name 'cn=admin2'
at org..ldap.support.LdapUtils.convertLdapException(LdapUtils.java:178)
at org..ldap.core.LdapTemplate.executeWithContext(LdapTemplate.java:786)
at org..ldap.core.LdapTemplate.executeReadWrite(LdapTemplate.java:779)
at org..ldap.core.LdapTemplate.modifyAttributes(LdapTemplate.java:951)
Any ideas?

Judging from the lack of replies my guess is that LDAP doesn't support objectclass changes and I'll have to delete the object and recreate it with the new objectclass. Damn.

As you've discovered, the change breaks the LDAP/X.500 information model. You can modify the list of objectClass values as long as it doesn't imply a change to the object's structural class. That is, if you have an organizationalPerson object whose objectClass attribute lists only organizationalPerson but not person, you can modify objectClass to also contain person. But if you have a person object, you cannot change the list of objectClass values to also include organizationalPerson, as that implies a change to the structural class of the object from person to organizationalPerson.
¥
Back Forum Reply New