in this article i gonna show java code sample that explain how to create user in OID grammatically .
before taking the code you have to do the following two steps :
before taking the code you have to do the following two steps :
- Create custom project
- add reference for the following jar ldapjclnt11
now Create Class and copy the following code :
import oracle.ldap.util.*;
import oracle.ldap.util.jndi.*;
import javax.naming.NamingException;
import javax.naming.directory.*;
import java.io.*;
import java.util.*;
public class OIDConnect {
public OIDConnect() {
super();
}
final static String ldapServerName = "xx.xx.xx.xx";
final static String ldapServerPort = "3060";
final static String rootdn = "cn=orcladmin";
final static String rootpass = "password";
public static void main(String[] args) throws NamingException {
// Create the connection to the ldap server
InitialDirContext ctx = ConnectionUtil.getDefaultDirCtx(ldapServerName, ldapServerPort, rootdn, rootpass);
// Create the subscriber object using the default subscriber
Subscriber mysub = null;
String[] mystr = null;
try
{
RootOracleContext roc = new RootOracleContext(ctx);
mysub = roc.getSubscriber(ctx, Util.IDTYPE_DN, "dc=xx,dc=xx,dc=xx", mystr);
}
catch (UtilException e) {
e.printStackTrace();
}
// Create ModPropertySet
ModPropertySet mps = new ModPropertySet();
mps.addProperty(LDIF.ATTRIBUTE_CHANGE_TYPE_ADD, "cn", "John");
mps.addProperty(LDIF.ATTRIBUTE_CHANGE_TYPE_ADD, "sn", "John");
mps.addProperty(LDIF.ATTRIBUTE_CHANGE_TYPE_ADD, "objectclass", "person");
mps.addProperty(LDIF.ATTRIBUTE_CHANGE_TYPE_ADD, "objectclass", "organizationalPerson");
mps.addProperty(LDIF.ATTRIBUTE_CHANGE_TYPE_ADD, "objectclass", "inetOrgPerson");
mps.addProperty(LDIF.ATTRIBUTE_CHANGE_TYPE_ADD, "objectclass", "orclUser");
mps.addProperty(LDIF.ATTRIBUTE_CHANGE_TYPE_ADD, "objectclass", "orclUserv2");
mps.addProperty(LDIF.ATTRIBUTE_CHANGE_TYPE_ADD, "givenname", "John");
mps.addProperty(LDIF.ATTRIBUTE_CHANGE_TYPE_ADD, "userPassword", "xxx");
mps.addProperty(LDIF.ATTRIBUTE_CHANGE_TYPE_ADD, "uid", "John");
// Create the user
User newUser = null;
try {
newUser = mysub.createUser(ctx, mps, false);
System.out.println("New User DN: " + newUser.getDN(ctx));
} catch (UtilException e) {
e.printStackTrace();
}
}
}
No comments:
Post a Comment