无法从OpenDS活动目录中创建和获取java中的用户

时间:2012-07-30 14:02:04

标签: java ldap

DirContext ldapContext;

String baseName = "dc=MyCompany,dc=com";

String serverIP = "xx.xxx.xxx.xxx";

public ADConnection() {

try {

  Hashtable ldapEnv = new Hashtable(11);

  ldapEnv.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");

  ldapEnv.put(Context.PROVIDER_URL,  "ldap://xx.xx.xx.xx:389");

  ldapEnv.put(Context.SECURITY_AUTHENTICATION, "simple");

  ldapEnv.put(Context.SECURITY_PRINCIPAL, "cn=Directory Manager");

  ldapEnv.put(Context.SECURITY_CREDENTIALS, "xxxx");

  ldapContext = new InitialDirContext(ldapEnv);

  System.out.println(ldapContext);



 }
  catch (Exception e) {

    System.out.println(" bind error: " + e);

    e.printStackTrace();

    System.exit(-1);

 }

}

try { Hashtable ldapEnv = new Hashtable(11); ldapEnv.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); ldapEnv.put(Context.PROVIDER_URL, "ldap://xx.xx.xx.xx:389"); ldapEnv.put(Context.SECURITY_AUTHENTICATION, "simple"); ldapEnv.put(Context.SECURITY_PRINCIPAL, "cn=Directory Manager"); ldapEnv.put(Context.SECURITY_CREDENTIALS, "xxxx"); ldapContext = new InitialDirContext(ldapEnv); System.out.println(ldapContext); } catch (Exception e) { System.out.println(" bind error: " + e); e.printStackTrace(); System.exit(-1); }




while creating user and after fetching user I am getting below error in the console.

javax.naming.directory.InitialDirContext@18eb9e6

Name: user1, Attributes: {displayname=displayName: user1 User, givenname=givenName: user1,

objectclass=objectclass: top, person, organizationalperson, user,

samaccountname=sAMAccountName: user1,, sn=sn: User, userprincipalname=userPrincipalName:

user1,@xx.xxx.xxx.xxx, cn=cn: user1,}

create error: javax.naming.NameNotFoundException: [LDAP: error code 32 - The provided entry

cn=user1,dc=MyCompany,dc=com cannot be added because its suffix is not defined as one of the

suffixes within the Directory Server]; remaining name 'cn=user1,dc=MyCompany,dc=com'

javax.naming.NameNotFoundException: [LDAP: error code 32 - The provided entry

cn=user1,dc=MyCompany,dc=com cannot be added because its suffix is not defined as one of the

suffixes within the Directory Server]; remaining name 'cn=user1,dc=MyCompany,dc=com'

1 个答案:

答案 0 :(得分:0)

dc=mycompany,dc=com的后端是否存在?如果没有,则必须创建它并至少填充基础对象dc=mycompany,dc=com