【问题标题】:LDAP SPRING : How to authenticate users belonging to different basesLDAP SPRING:如何对属于不同基础的用户进行身份验证
【发布时间】:2017-07-13 23:56:20
【问题描述】:

我想知道如何对属于 LDAP 目录中不同基础的用户进行身份验证

我的文件配置是:

<!-- LDAP -->

        <security:ldap-server url="ldap://192.168.10.220:389/o=org" manager-dn="uid=admin,ou=Admins,o=org" manager-password="password" />

        <bean id="ldapAuthProvider" class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
                <constructor-arg>
                        <bean class="org.springframework.security.ldap.authentication.BindAuthenticator">
                                <constructor-arg ref="contextSource" />
                                <property name="userDnPatterns">
                                        <list>
                                                <value>uid={0}</value>
                                        </list>
                                </property>
                        </bean>
                </constructor-arg>
                <constructor-arg>
                        <bean class="edu.mit.kit.userdetails.MappedLdapAuthoritiesPopulator">
                                <property name="admins">
                                        <set>
                                                <value>user1</value>
                                        </set>
                                </property>
                        </bean>
                </constructor-arg>
        </bean>

        <bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
                <property name="url" value="ldap://192.168.10.220:389" />
                <property name="base" value="ou=comp,ou=Users,o=org" />
                <property name="userDn" value="admin1,ou=Admins,o=org" />
                <property name="password" value="password" />
        </bean>

        <bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
                <constructor-arg name="contextSource" ref="contextSource" />
       </bean>

我的 LDAP 方案根是:o=org,每个用户都有一个不同的“ou”。

以 3 个用户为例:

  • user1 : uid=user1,ou=Users,o=org
  • user2: uid=user2,ou=comp, ou=Users,o=org
  • user3: uid=user3,ou=fi_Users,o=org

所以,我正在寻找一种方法,可以在不将所有 LDAP 方案放入此 xml 文件配置中的情况下对这些用户进行身份验证。

【问题讨论】:

    标签: templates authentication ldap spring-ldap dn


    【解决方案1】:

    定义一个'searchbean'

    <beans:bean id="ldapUserSearch" class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
     <beans:constructor-arg value=""/>
     <beans:constructor-arg value="uid={0}"/>
     <beans:constructor-arg ref="contextSource"/>
    </beans:bean>
    

    并使用

    <beans:property name="userSearch" ref="ldapUserSearch"/>
    

    而不是

    <property name="userDnPatterns">
     <list>
       <value>uid={0}</value>
     </list>
    </property>
    

    这将首先搜索条目,这被认为是 LDAP 最佳实践,而不是构建用于 LDAP 绑定操作的 DN。

    旁注:由于密码在 LDAP 绑定操作期间以明文形式通过网络传输,因此不要使用 LDAP,而应使用 LDAPS。即使使用 StartTLS 扩展 LDAP 操作也允许以明文形式向客户端发送密码,尽管您可以在服务器端强制实施安全通道……但为时已晚,密码可能已经被窃听。

    【讨论】:

    • @jwilleke StartTLS 本身不是,但是 StartTLS 操作是通过普通端口启动的,因此您不必强制在安全通道中发送密码,而只需在普通端口上使用 LDAP 绑定操作,然后密码以明文形式通过网络传输。当然可以将 LDAP 服务器配置为拒绝此操作,但这无济于事,因为密码已经转移。 --> 仅当您担心安全性时才使用 LDAPS。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-02
    • 2020-07-05
    • 2011-08-21
    • 2016-03-03
    • 1970-01-01
    • 1970-01-01
    • 2012-07-14
    相关资源
    最近更新 更多