我正嘗試使用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