Wednesday, August 26, 2009

Java Code to add New Group in OID

import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.*;
import java.util.*;

public class NewGroup
{
final static String ldapServerName = "dr.test.org";
final static String ldapServerPort = "389";
final static String rootdn = "cn=orcladmin";
final static String rootpass = "abcd1234";
final static String entryDn = "cn=newgroup,dc=gov,dc=in";

public static void main(String argv[]) throws NamingException
{
Properties env = new Properties();
env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" );
env.put( Context.PROVIDER_URL, "ldap://" + ldapServerName + ":" + ldapServerPort + "/");
env.put( Context.SECURITY_PRINCIPAL, rootdn );
env.put( Context.SECURITY_CREDENTIALS, rootpass );
DirContext ctx = new InitialDirContext(env);

// Create the objclassSet to hold all the entry's objectClasses.
BasicAttribute objclassSet = new BasicAttribute("objectclass");
objclassSet.add("top");
objclassSet.add("orclgroup");
objclassSet.add("groupofuniquenames");

// load the attributes
BasicAttributes attrs = new BasicAttributes();
attrs.put(objclassSet);
attrs.put("cn", "newgroup");
attrs.put("uniquemember", "cn=orcladmin");
ctx.creat>
}

No comments:

Post a Comment