我正在尝试使用 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'
我肯定违反了什么。对此有任何想法吗?