2012-12-13 45 views
0

我試圖用Spring LDAPTemplate來控制OpenLDAP。Spring LdapTemplate - 屬性'gidNumber'不允許異常

在LDAP中,我有組和用戶組織單位。我試圖通過組關聯將新用戶綁定到LDAP中。 (通用用戶帳戶)所以當我嘗試綁定一個新用戶時,我也會將gidNumber attiribute放入屬性對象中。但我發現了這樣的錯誤:

[LDAP: error code 65 - attribute 'gidNumber' not allowed]; nested exception is javax.naming.directory.SchemaViolationException: [LDAP: error code 65 - attribute 'gidNumber' not allowed]; remaining name 'ou=staff' 

這裏是我試過到目前爲止:

DistinguishedName dn = new DistinguishedName(); 
dn.add("ou", "staff"); 
Attributes attributes = new BasicAttributes(); 
attributes.put("objectClass", "inetOrgPerson"); 
attributes.put("uid", username); 
attributes.put("givenName", name); 
attributes.put("gidNumber", gidNumber.toString()); 
attributes.put("sn", surname); 
attributes.put("cn", name + " " + surname); 
attributes.put("userPassword", password); 
ldapTemplate.bind(dn, null, attributes); 

這裏是我的架構:

+--> dc=ibu,dc=edu,dc=tr (5) 
    ---> cn=admin 
    +--> ou=group (1) 
    | ---> cn=Academic 
    ---> ou=guest 
    +--> ou=staff (2) 
    | ---> cn=John Clark 
    ---> ou=student 

回答

0

您必須添加另一個對象類叫做posixAccount。因爲屬性gidNumber屬於這個類。因此,嘗試增加一個對象類,如下所示:

attributes.put("objectClass", "posixAccount"); 
+0

感謝您的回覆;但現在我得到另一個異常:'LDAP:錯誤代碼65 - 沒有提供結構對象類' – talha06

0

的LDAP條目必須只是一個且只有一個結構對象類。不過,一些破碎的服務器確實允許多個結構對象類。添加結構對象類(要添加的結構對象取決於使用條目的用途)。

+0

我更新了問題,添加了我的LDAP模式。你能更簡單地解釋一下如何使用Spring LDAP **添加這個依賴關係**?例如,如果我想將用戶添加到** Academic **組中,我該如何表達這一點? – talha06