我正尝试使用JNDI将条目添加到LDAP服务器。我可以成功读取来自LDAP服务器的条目。但是,当我尝试添加新条目时,我收到错误。我检查了各种方法,但我失败了。使用JNDI添加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'
当然,我违反了一些东西。对此有何想法?
嗨geoffc,我也想我违反了原来的架构..你有一个工具的任何想法我可以转储模式或进行验证? – 2009-07-07 04:48:52
你能得到cn = schema节点吗? Schema认为每个系统都是这样。寻找你的对象类,找出它继承的东西(SUP我认为),然后看看必须的属性。 (必须)。 – geoffc 2009-07-07 11:26:34