JAVA ldap 错误 NO_OBJECT

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24485722/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 12:30:36  来源:igfitidea点击:

JAVA ldap error NO_OBJECT

javaldap

提问by user840718

I'm in trouble with this error when I change a password or update user's info. I've tried so many codes that are similar each others, but I still got the error. The problem can be a bad CN definition, but should be correct in my case and I'm really sad about this because I cannot face the problem.

我在更改密码或更新用户信息时遇到此错误。我尝试了很多彼此相似的代码,但仍然出现错误。问题可能是一个糟糕的 CN 定义,但在我的情况下应该是正确的,我对此感到非常难过,因为我无法面对这个问题。

  • Connection to the server via LDAP: OK.
  • SSL and cacerts: OK.
  • Add user via code: OK.
  • Fetching all users info: OK.
  • Update user's info: BAD.
  • 通过 LDAP 连接到服务器:OK
  • SSL 和 cacerts:好的
  • 通过代码添加用户:OK
  • 获取所有用户信息:OK
  • 更新用户信息:BAD

Here is a simple code where I try, without success, to update the user's info (description). The user "batman" obviously, exists in AD.

这是一个简单的代码,我尝试更新用户的信息(描述),但没有成功。用户“batman”显然存在于AD中。

public class ADConnection {

DirContext ctx = null;
String baseName = ",OU=SoftwareV3,OU=SOFTWARE,DC=SOFTWAREDEV,DC=LOCAL";
String serverIP = "192.168.10.45";
boolean ssl = true;

public ADConnection() {
    try {
        Hashtable ldapEnv = new Hashtable(); 
        ldapEnv.put(Context.INITIAL_CONTEXT_FACTORY,             "com.sun.jndi.ldap.LdapCtxFactory"); 
        if(ssl==true)
        {
            ldapEnv.put(Context.PROVIDER_URL, "ldaps://192.168.10.45:636/dc=softwaredev,dc=local");
            ldapEnv.put(Context.SECURITY_PROTOCOL, "ssl");
        }
        else
        {
            ldapEnv.put(Context.PROVIDER_URL, "ldap://192.168.10.45:389/dc=softwaredev,dc=local");
        }
        ldapEnv.put(Context.SECURITY_AUTHENTICATION, "simple"); 
        ldapEnv.put(Context.SECURITY_PRINCIPAL, new String("softwaredev" + "\" +     "superadmin"));
        ldapEnv.put(Context.SECURITY_CREDENTIALS, "passw0rd");  
        ctx = new InitialDirContext(ldapEnv); 
    } 
    catch (Exception e) { 
        System.out.println(" bind error: " + e); 
        e.printStackTrace(); 
        System.exit(-1); 
    } 
}

public void updateDescription(String username) {
    try {
      System.out.println("updating...\n");
      ModificationItem[] mods = new ModificationItem[1];
      mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
        new BasicAttribute("description", "batman_description"));
      ctx.modifyAttributes("CN=" + username + baseName, mods);
      System.out.println("update successful!!!");
     }
      catch (Exception e) {
        System.out.println(" update error: " + e);
        System.exit(-1);
      }
  }

public static void main(String[] args) { 
    ADConnection adc = new ADConnection(); 
    adc.updateDescription("batman");
    } 
    }

ERROR:update error: javax.naming.NameNotFoundException: [LDAP: error code 32 - 0000208D: NameErr: DSID-0310020A, problem 2001 (NO_OBJECT), data 0, best match of:

错误:更新错误:javax.naming.NameNotFoundException:[LDAP:错误代码 32 - 0000208D:NameErr:DSID-0310020A,问题 2001(NO_OBJECT),数据 0,最佳匹配:

The crash is on the 6th line of code in the function updateDescription. Any suggestions?

崩溃发生在函数 updateDescription 中的第 6 行代码。有什么建议?

采纳答案by mvreijn

Looking at your code, and the error message, AD is saying that the DN CN=batman,OU=SoftwareV3,OU=SOFTWARE,DC=SOFTWAREDEV,DC=LOCALdoes not exist. This message pertains to the entireDN tree.

查看您的代码和错误消息,AD 说 DNCN=batman,OU=SoftwareV3,OU=SOFTWARE,DC=SOFTWAREDEV,DC=LOCAL不存在。此消息与整个DN 树有关。

This means that either of these objects does not exist:

这意味着这些对象中的任何一个都不存在:

  • DC=LOCAL
  • DC=SOFTWAREDEV,DC=LOCAL
  • OU=SOFTWARE,DC=SOFTWAREDEV,DC=LOCAL
  • OU=SoftwareV3,OU=SOFTWARE,DC=SOFTWAREDEV,DC=LOCAL
  • CN=batman,OU=SoftwareV3,OU=SOFTWARE,DC=SOFTWAREDEV,DC=LOCAL
  • 直流=本地
  • DC=软件开发,DC=本地
  • OU=软件,DC=软件开发,DC=本地
  • OU=SoftwareV3,OU=SOFTWARE,DC=SOFTWAREDEV,DC=LOCAL
  • CN=蝙蝠侠,OU=SoftwareV3,OU=SOFTWARE,DC=SOFTWAREDEV,DC=LOCAL

You should check the entire DN for correctness, using an LDAP browser, as the error message does not specify whichobject does not exist.

您应该使用 LDAP 浏览器检查整个 DN 的正确性,因为错误消息没有指定哪个对象不存在。

回答by Albino Vaz

According to your code the line would look like this:

根据您的代码,该行将如下所示:

ctx.modifyAttributes("CN=batman,OU=SoftwareV3,OU=SOFTWARE,DC=SOFTWAREDEV,DC=LOCAL", mods);

Try it like this, it works for me:

像这样尝试,它对我有用:

ctx.modifyAttributes("CN=batman,OU=SoftwareV3,OU=SOFTWARE", mods);

I followed the example that can be seen in this link:

我按照可以在此链接中看到的示例进行操作:

http://www.java2s.com/Code/JavaAPI/javax.naming.directory/DirContextmodifyAttributesStringnameintmodopAttributesattrs.htm

http://www.java2s.com/Code/JavaAPI/javax.naming.directory/DirContextmodifyAttributesStringnameintmodopAttributesattrs.htm