go to  ForumEasy.com   
LdapPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  Step 4) Extend target class
 
Subject: Step 4) Extend target class
Author: eLDAP
In response to: Step 3) Create new classes
Posted on: 09/28/2012 09:01:03 PM

try {
     
    // The initial directory context
    LdapContext ctx = new InitialLdapContext(env, null);
 
    //Modify the user class to add the hrHumanResources class as an auxilliary class
    ModificationItem[] mods = new ModificationItem[1];
    mods = new ModificationItem[1];
    mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE, 
    		new BasicAttribute("auxiliaryClass","hrHumanResources"));
    ctx.modifyAttributes("CN=User,CN=Schema,CN=Configuration,DC=example,DC=com", mods);

    //Force the change to be taken effect 
    mods = new ModificationItem[1];
    mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, 
    		new BasicAttribute("schemaupdatenow","1"));
    ctx.modifyAttributes("", mods);  // RootDSE
 
    System.out.println("Successfully modified schema");
    ctx.close();
		
}catch (NamingException e) {
    System.err.println("Problem modifying schema: " + e);
}


 

> On 09/28/2012 08:34:10 PM eLDAP wrote:

Create new auxilliary class:
try {
     
    // The initial directory context
    LdapContext ctx = new InitialLdapContext(env, null);
 
    // Create a new auxilliary class
    Attributes attrs = new BasicAttributes(true);
    attrs.put("adminDescription", "Human Resources Auxilliary Class");
    attrs.put("adminDisplayName", "hr-Human-Resources");
    attrs.put("governsID", 
    	"1.2.840.113556.1.4.7000.17"); // Must be registered in advance
    attrs.put("lDAPDisplayName", "hrHumanResources");
    attrs.put("cn", "hr-Human-Resources");
    attrs.put("objectCategory",
    	"CN=Class-Schema,CN=Schema,CN=Configuration,DC=example,DC=com");
    attrs.put("objectClass", "classSchema");
    attrs.put("objectClassCategory", "3");
    attrs.put("rDNAttID", "cn");
    attrs.put("possSuperiors", "organizationalUnit");
    attrs.put("possSuperiors", "container");
    attrs.put("subClassOf", "top");
    attrs.put("mayContain", "hrSocialSecurityNumber");
    attrs.put("mayContain", "hrSalaryLevel");

    // Attribute schema entry's dn
    String schema_dn = 
    	"CN=hr-Human-Resources,CN=Schema,CN=Configuration,DC=example,DC=com"; 

    // create the schema class entry
    ctx.createSubcontext(schema_dn, attrs);

    //Force the change to be taken effect 
    ModificationItem[] mods = new ModificationItem[1];
    mods = new ModificationItem[1];
    mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, 
    		new BasicAttribute("schemaupdatenow","1"));
    ctx.modifyAttributes("", mods);  // RootDSE
 
    System.out.println("Successfully modified schema");
    ctx.close();
		
}catch (NamingException e) {
    System.err.println("Problem modifying schema: " + e);
}




References:

 


 
Powered by ForumEasy © 2002-2022, All Rights Reserved. | Privacy Policy | Terms of Use
 
Get your own forum today. It's easy and free.