我很难从春季使用ldap身份验证的用户数据中读取一些操作性问题。我知道那里已经有很多Q&关于这个主题但是没有一个真正帮助过我。我需要的是获得isMemberOf
个人。我们公司的LDAP管理员说' isMemberOf是一个可操作的attr,所以它没有来自ldap认证响应的常规。因此,您需要按名称'并且他给了我这个shell命令,用它来给我一个想法来获取它们:
-bash-3.2$ ldapsearch -h XXX -p 10389 -b dc=entp,dc=tgc -e -1 -T -D "uid=XXX,ou=SpecialUsers,dc=entp,dc=tgc" -w XXX uid=XXX ismemberof
dn: uid=XXX,ou=people,o=XXX,dc=entp,dc=tgc
ismemberof: cn=3G01,ou=functionGroups,ou=Groups,dc=entp,dc=tgc
我项目中的Spring版本:
<spring.version>3.1.1.RELEASE</spring.version>
<spring.security.version>3.1.0.RELEASE</spring.security.version>
<spring.data.commons.version>1.3.1.RELEASE</spring.data.commons.version>
<spring.ldap.version>1.3.1.RELEASE</spring.ldap.version>
存储ldap配置的 .properties
文件:
app.ldap.url=ldap://XXX
app.ldap.manager.base=uid=XXX,ou=SpecialUsers,dc=entp,dc=tgc
app.ldap.manager.password=XXX
app.ldap.user.base=dc=entp,dc=tgc
app.ldap.user.filter=(uid={0})
app.ldap.user.role.key=ApplicationProfile
Beans definitons for authentication:
<beans>
<s:authentication-manager alias="authenticationManager">
<s:authentication-provider ref="ldapAuthProvider" />
</s:authentication-manager>
<bean id="contextSource"
class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<constructor-arg value="${ldap.url}" />
<property name="userDn" value="${ldap.manager.base}" />
<property name="password" value="${ldap.manager.password}" />
</bean>
<bean id="ldapAuthProvider"
class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
<constructor-arg ref="bindAuthenticator" />
<constructor-arg ref="authoritiesPopulator" />
<property name="userDetailsContextMapper" ref="userDetailsContextMapper" />
</bean>
<bean id="bindAuthenticator"
class="org.springframework.security.ldap.authentication.BindAuthenticator">
<constructor-arg ref="contextSource" />
<property name="userSearch" ref="userSearch"/>
</bean>
<bean id="userSearch"
class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
<constructor-arg value="${ldap.user.base}" />
<constructor-arg value="${ldap.user.filter}" />
<constructor-arg ref="contextSource" />
</bean>
<bean id="authoritiesPopulator"
class="core.spring.security.ldap.AttributeBasedLDAPAuthoritiesPopulator">
<constructor-arg value="${ldap.user.role.key}" />
</bean>
<bean id="userDetailsContextMapper"
class="core.spring.security.ldap.CustomUserDetailsContextMapper" />
</beans>
当我调试填充getGrantedAuthorities(DirContextOperations userData, String username)
课程中的权限的AttributeBasedLDAPAuthoritiesPopulator
函数时,userData
仅包含这些attrs而不包含其他isMemberOf
(XXXs实际上是一些真实数据):
birthdate=birthdate: 06/28/1983,
givenname=givenName: Dummy User,
mobile=mobile: XXX,
workflowaccess=WorkflowAccess: 0,
objectclass=objectClass: mdsMVLink, top, person, inetOrgPerson, organizationalPerson, inetUser, inetAdmin, iplanet-am-managed-person, iPlanetPreferences, iplanet-am-user-service,
mdsmvlinktype=mdsMVLinkType: MV#CV1#A,
userpassword=userPassword: XXX,
mdsentityowner=mdsEntityOwner: MV,META,
ou=ou: XXX,
applicationprofile=ApplicationProfile: XXX
uid=uid: XXX,
mail=mail: XXX,
cn=cn: XXX,
managername=managerName: XXX,
manager=manager: uid=XXX,ou=people,o=XXX,dc=entp,dc=tgc,
employeenumber=employeeNumber: TEST15,
functionalgroupname=functionalgroupname: dummy-functionalgroupname,
mdslinktocv=mdsLinkToCV: MV#CV1#uid=DUMMY,ou=Employees,
status=status: 1,
mdsmvmembership=mdsMVMembership: CV1#True,
inetuserstatus=inetUserStatus: Active,
description=description: XXX,
sn=sn: for TEA project,
organization=Organization: XXX
所以我的问题是如何才能使isMemberOf
与这些人接触?
到目前为止我尝试了什么:
1-在.properties
中添加另一个过滤器以包含ismemberof
app.ldap.user.filter=(&(uid={0})(ismemberof=*))
2-为角色
制作isMemberOf
关键字
app.ldap.user.role.key=isMemberOf
3-尝试从populator类
中的userData显式获取它userData.getObjectAttributes("isMemberOf")
答案 0 :(得分:0)
您需要将属性ismemberof
添加到userSearch
bean的请求属性中:
<bean id="userSearch"
class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
<constructor-arg value="${ldap.user.base}" />
<constructor-arg value="${ldap.user.filter}" />
<constructor-arg ref="contextSource" />
<property name="returningAttributes">
<list>
<value>*</value>
<value>ismemberof</value>
</list>
</property>
</bean>
由于ldap服务器的行为,您需要指定两个值(*
和ismemberof
):
*
并列出您想要的所有操作属性