簡體   English   中英

使用JNDI添加LDAP條目

[英]Adding LDAP entries using JNDI

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM