Java 如何使用SpringLDAP授权获取操作属性

Java 如何使用SpringLDAP授权获取操作属性,java,spring,spring-ldap,Java,Spring,Spring Ldap,我很难从spring中ldap身份验证提供的用户数据中读取一些操作属性。我知道已经有很多关于这个话题的问答,但是没有一个能真正帮助我。我需要的是获取isMemberOfattrs。我们公司的LDAP管理员说,“isMemberOf是一个操作属性,因此它不会与LDAP身份验证响应中的常规属性一起提供。因此,您需要按名称请求它们,他给了我一个shell命令,他使用这个命令来给我一个获取它们的想法: -bash-3.2$ ldapsearch -h XXX -p 10389 -b dc=entp,dc

我很难从spring中ldap身份验证提供的用户数据中读取一些操作属性。我知道已经有很多关于这个话题的问答,但是没有一个能真正帮助我。我需要的是获取
isMemberOf
attrs。我们公司的LDAP管理员说,“isMemberOf是一个操作属性,因此它不会与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>
用于身份验证的bean定义:

<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>
因此,我的问题是,如何使用这些属性获得
isMemberOf
attrs


到目前为止,我所尝试的:

1-在
.properties
中添加另一个筛选器以包括ismemberof

app.ldap.user.filter=(&(uid={0})(ismemberof=*))
2-使
isMemberOf
成为角色的关键字

app.ldap.user.role.key=isMemberOf
3-尝试从populator类中的userData显式获取它

userData.getObjectAttributes("isMemberOf")

您需要将属性
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
):

  • 如果不指定属性名称,它将返回所有用户属性
  • 如果指定属性名称,它将准确返回这些属性(无论是用户属性还是操作属性)
  • 如果需要所有用户属性和一些操作属性,则为所有用户属性指定
    *
    ,并列出所需的所有操作属性

谢谢你的回答,但运气不好。即使我删除
*
并仅使用
ismemberof
,它仍然只返回基本属性
userData.getObjectAttributes("isMemberOf")
<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>