2014-06-19 34 views
1

我在spring-security中使用LDAP身份驗證。出於某種原因,我沒有LDAP服務器,並且已配置我的spring-security.xml以使用LDIF文件。如何將對象類和自定義屬性添加到LDIF文件?

我需要爲用戶添加一個自定義屬性,名爲type。所以我創建了objectclassattributetypes,如here所述。

LDIF文件看起來像:

dn: cn=subschemasubentry 
changetype: modify 
add: attributetypes 
attributetypes: (1.2.3.4.5.6.7 NAME 'type' DESC 'New attribute definition' 
EQUALITY caseIgnoreMatch SYNTAX '1.3.6.1.4.1.1466.115.121.1.15') 

dn: cn=subschemasubentry 
changetype: modify 
add: objectClasses 
objectClasses: (1.2.3.4.56789.1.0.200 NAME 'testUser' 
SUP (inetOrgPerson) STRUCTURAL 
MUST cn 
MAY type) 

dn: ou=users,dc=springframework,dc=org 
objectclass: top 
objectclass: organizationalUnit 
ou: users 

dn: uid=testuser1,ou=users,dc=springframework,dc=org 
objectclass: top 
objectclass: person 
objectclass: organizationalPerson 
objectclass: testUser 
mail: [email protected] 
cn: Some Name 
sn: someName 
uid: someId 
type: someType 
userPassword: pass1 

然而,這種失敗NameNotFoundException,當我嘗試使用一些REST調用(由spring-security保護)與錯誤:

LDAP: error code 32 - NO_SUCH_OBJECT: 
... 
... 
Attempt to search under non-existant entry: ou=users,dc=springframework,dc=org]; 
nested exception is javax.naming.NameNotFoundException: 

如果我刪除自定義屬性和自定義對象類,並將用戶數據更改爲objectclass: inetOrgPerson,它工作正常。如何添加objectclass和屬性呢?

回答

2

我試圖在LDIF文件中使用模式,這是錯誤的。我使用ApacheDS來創建具有自定義屬性和自定義對象類的新模式。然後將它們導出到LDIF。

生成的LDIF添加到用於spring-security的LDIF文件中。

另一個問題是,即使讀取對象類,spring仍然不會從條目中讀取新屬性。

+0

你終於找到了解決方案嗎? – Aure77

相關問題