4

我正在尝试使用 JNDI 向 LDAP 服务器添加一个条目。我可以成功地从 LDAP 服务器读取条目。但是当我尝试添加一个新条目时,我得到了错误。我检查了各种方法,但都失败了。

    private String getUserAttribs (String searchAttribValue) throws NamingException{
    SearchControls ctls = new SearchControls();
    ctls.setSearchScope(SearchControls.OBJECT_SCOPE);

    Attributes matchAttrs = new BasicAttributes(true);
    matchAttrs.put(new BasicAttribute("uid", searchAttribValue));
    NamingEnumeration answer = ctx.search("ou=People,ou=ABCLdapRealm,dc=abcdomain",matchAttrs);

    SearchResult item =(SearchResult) answer.next();
    // uid userpassword description objectclass wlsmemberof sn cn
    return item.toString();
}

这工作正常。

然后我向前迈了一步,尝试添加一个条目。代码如下。

    public static void bindEntry(DirContext dirContext)throws Exception{
    Attributes matchAttrs = new BasicAttributes(true);
    // uid userpassword description objectclass wlsmemberof sn cn
    matchAttrs.put(new BasicAttribute("uid", "defaultuser"));
    matchAttrs.put(new BasicAttribute("userpassword", "password"));
    matchAttrs.put(new BasicAttribute("description", "defaultuser"));
    matchAttrs.put(new BasicAttribute("cn", "defaultuser"));
    matchAttrs.put(new BasicAttribute("sn", "defaultuser"));

    matchAttrs.put(new BasicAttribute("objectclass", "top"));
    matchAttrs.put(new BasicAttribute("objectclass", "person"));
    matchAttrs.put(new BasicAttribute("objectclass", "organizationalPerson"));
    matchAttrs.put(new BasicAttribute("objectclass","inetorgperson"));
    matchAttrs.put(new BasicAttribute("objectclass", "wlsUser"));
    String name="uid=defaultuser";
    InitialDirContext iniDirContext = (InitialDirContext)dirContext;
    iniDirContext.bind(name,dirContext,matchAttrs);
}

但有了这个,我得到了一个例外。

Exception in thread "main" javax.naming.OperationNotSupportedException: [LDAP: error code 53 - Unwilling To Perform]; remaining name 'uid=defaultuser'

我肯定违反了什么。对此有任何想法吗?

4

3 回答 3

4

LDAP 53,不愿意执行,通常意味着它所说的。您试图从 LDAP 服务器的角度做一些“非法”的事情。

第一个猜测,但不太可能,您指的是 eDirectory 吗?如果是这样,添加 sn 很重要,因为在 eDirectory 的模式中必须在创建时提供姓氏值。在这种情况下,您可能会得到一个稍微不同的错误,更像是 608 或 611 错误。

第二个猜测,你指向 Active Directory,在这种情况下 fullName 是一个强制属性。但在这种情况下,您通常也会得到略有不同的结果代码。应该有更多的错误。(虽然这可能是 JNDI 的回报与我使用的工具相比)。

第三个猜测,您指向其他人的 LDAP 服务器,并且您错过了模式中的强制属性。

事实上,也许这是一个对象类问题。wlsUser 是辅助类还是真正的类?在您的目录中,inetorgperson 是一个真正的类吗(我对这种类型的类的名称没有兴趣,还有 aux、structural 和其他东西)类?

我的基本猜测是您错过了强制属性并且违反了目标目录中的模式,我希望上面列出的缺少强制属性的可能示例会有所帮助。

于 2009-07-02T11:42:05.943 回答
2

这是您尝试通过非 SSL 连接在 Active Directory 中设置密码时遇到的错误。在没有密码行的情况下再次尝试您的代码。

于 2009-07-02T13:47:03.397 回答
2

嗨,通过使用下面的代码,我可以将一个人从 jndi 程序插入 ldap

Attributes attributes=new BasicAttributes();
Attribute objectClass=new BasicAttribute("objectClass");
objectClass.add("inetOrgPerson");
attributes.put(objectClass);

Attribute sn=new BasicAttribute("sn");
Attribute cn=new BasicAttribute("cn");

sn.add("sahul");
cn.add("vetcha");

attributes.put(sn);
attributes.put(cn);
attributes.put("title","software engg")
ctx.createSubcontext("uid=sahul,ou=some organization7,o=some company7,ou=system",attributes);
于 2009-08-20T09:51:34.327 回答