Invalid DN Syntax (34) Invalid DN Syntax
往ldap中添加节点,出现一下错误(认证已成功):
Error: LDAPException: Invalid DN Syntax (34) Invalid DN Syntax
LDAPException: Server Message: invalid DN
LDAPException: Matched DN:
import com.novell.ldap.*;
import
java.io.UnsupportedEncodingException;
public class LDAPAdd {
public static void main(String[] args) {
int ldapPort = LDAPConnection.DEFAULT_PORT;
int ldapVersion = LDAPConnection.LDAP_V3;
String ldapHost = "localhost";
String loginDN = "cn=Manager,dc=lily,dc=com";
String password = "lily";
LDAPConnection lc = new LDAPConnection();
String newUserName = "helin";
try {
// connect to the server
lc.connect(ldapHost, ldapPort);
// authenticate to the server
lc.bind(ldapVersion, loginDN, password.getBytes("UTF8"));
//long start = System.currentTimeMillis();
LDAPAttributeSet attrSet = new LDAPAttributeSet();
attrSet.add(new LDAPAttribute("objectclass","person"));
attrSet.add(new LDAPAttribute("cn",newUserName));
attrSet.add(new LDAPAttribute("sn",newUserName));
LDAPEntry entry = new LDAPEntry("cn=" + newUserName + "dc=lily,dc=com",attrSet);
lc.add(entry);
System.out.println("ok");
//System.out.println(System.currentTimeMillis() - start);
//lc.add( newEntry );
//System.out.println( "\nAdded object: " + dn + " successfully." );
// disconnect with the server
lc.disconnect();
}
catch (LDAPException e) {
System.out.println("Error: " + e.toString());
}
catch (Unsupported
EncodingException e) {
System.out.println("Error: " + e.toString());
}
System.exit(0);
}
}
------解决方案--------------------
看错误的样子是说:无效的DN语法,你在查查语法有没有什么问题