使用JNDI添加LDAP条目

我正在尝试使用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' 

我肯定是在违反某些事情。 对此有何想法?

LDAP 53,不愿意执行,通常意味着它所说的。 您尝试从LDAP服务器角度执行“非法”操作。

首先猜测,不太可能,你指的是eDirectory吗? 如果是这样,添加sn非常重要,因为eDirectory架构中必须在创建时提供Surname值。 在这种情况下,您可能会得到稍微不同的错误,更像是608或611错误。

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

第三个猜测,你指的是别人的LDAP服务器,你错过了架构中的强制属性。

实际上,也许它是一个对象类问题。 wlsUser是辅助类还是真正的类? 在你的目录中,inetorgperson是真实的(我正在为这类类的名称消隐,还有aux,structural和其他东西)类吗?

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

这是尝试通过非SSL连接在Active Directory中设置密码时出现的错误。 无需密码行即可再次尝试使用您的代码。

嗨,通过使用下面的代码我能够从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);