[英]Spring-security creates malformed ldap-query
我正在嘗試使用單點登錄解決方案,該解決方案以前曾與Novell eDirectory作為LDAP提供程序一起使用。 現在,我正在嘗試使其與OpenLDAP一起使用。 在登錄過程中,步驟之一是從LDAP檢索實際用戶。 這是由Spring-security完成的,但似乎有一個錯誤。
為了獲取用戶, LdapUserDetailsService#loadUserByUsername
。 這使用預定義的LdapUserSearch
查找具有給定用戶名的用戶。 就我而言,配置看起來像這樣:
base:ou=something,ou=somethingElse,dc=oh,dc=my,dc=god
filter:cn={0}
其中{0}
被替換為實際的用戶名。 到目前為止,此方法有效,並且以FilterBasedLdapUserSearch#searchForUser
返回的userdata的形式檢索了用戶。 但是,userdata在dn和base之間不分開,因此具有:
base: (empty)
dn:cn=someUsername,ou=something,ou=somethingElse,dc=oh,dc=my,dc=god
該userdata對象又用於檢索用戶的權限,因此它嘗試使用上面的基數和dn作為過濾器來進行另一次搜索。 但是,此查詢失敗,因為OpenLDAP不允許以空字符串為基礎的任何查詢。
我已經嘗試使用3.1.3.RELEASE,3.1.7.RELEASE和3.2.7.RELEASE,它們都有相同的問題。
這是spring-security中的錯誤嗎? 還是我在這里做錯了什么?
通過擺脫定義ldap用戶服務的“模板”方式來設法解決該問題:
之前:
<sec:ldap-user-service id="ldapUserDetailsService"
server-ref="contextSource"
user-search-filter="${my.ldap.filter}"
user-search-base="${my.ldap.base}"
user-context-mapper-ref="myUserDetailsContextMapper"/>
后:
<bean id="userSearch"
class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
<constructor-arg index="0" value="${my.ldap.base}"/>
<constructor-arg index="1" value="${my.ldap.filter}"/>
<constructor-arg index="2" ref="contextSource"/>
</bean>
<bean id="ldapAuthoritiesPopulator" class="org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator">
<constructor-arg ref="contextSource"/>
<constructor-arg value="${my.ldap.usersearch.base}"/>
<property name="groupSearchFilter" value="${my.group.filter}" />
<property name="groupRoleAttribute" value="${my.group.attribute}" />
<property name="searchSubtree" value="true" />
</bean>
<bean id="ldapUserDetailsService" class="org.springframework.security.ldap.userdetails.LdapUserDetailsService">
<constructor-arg ref="userSearch"/>
<constructor-arg ref="ldapAuthoritiesPopulator"/>
</bean>
不要問我這是如何或為什么起作用的..
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.