小编cab*_*ery的帖子

如何在Spring Security和ActiveDirectoryLdapAuthenticationProvider中使用自定义权限填充程序?

我已通过LDAP成功连接到Active Directory进行身份验证,并在我的ldap.xml中使用以下内容调用了自定义权限populator:

    <bean id="ldapAuthenticationProvider"
        class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
    <constructor-arg ref="ldapBindAuthenticator"/>
    <constructor-arg ref="ldapAuthoritiesPopulator"/>
</bean>

<bean id="ldapBindAuthenticator"
        class="org.springframework.security.ldap.authentication.BindAuthenticator">
    <constructor-arg ref="ldapServer"/>
    <property name="userSearch" ref="ldapSearch"/>
</bean>

<bean id="ldapSearch"
        class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
    <constructor-arg value="CN=Users"/>
    <constructor-arg value="(sAMAccountName={0})"/>
    <constructor-arg ref="ldapServer"/>
</bean>

<bean id="ldapAuthoritiesPopulator"
        class="my.project.package.ActiveDirectoryLdapAuthoritiesPopulator"/>

<bean id="ldapServer"
        class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
    <constructor-arg value="ldap://192.168.0.2/dc=test,dc=server"/>

    <property name="userDn" value="ldap@test.server"/>
    <property name="password" value="ldap"/>
    <property name="baseEnvironmentProperties">
        <map>
            <entry key="java.naming.referral">
                <value>follow</value>
            </entry>
        </map>
    </property>
</bean>
Run Code Online (Sandbox Code Playgroud)

这工作正常,我可以根据她的组成员资格确定用户的授权,但我宁愿通过内置的Active Directory LDAP身份验证提供程序执行此操作:

<bean id="ldapAuthenticationProvider"
        class="org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider">

        <constructor-arg value="test.server"/>
        <constructor-arg value="ldap://192.168.0.2:389"/>
        <property name="convertSubErrorCodesToExceptions" value="true"/>
</bean>
Run Code Online (Sandbox Code Playgroud)

上面的问题是我的自定义权限populator(显然)没有被调用,所以虽然我可以验证我的用户(使用上面的),但我没有组(我需要确定授权).

我觉得这是一个简单的问题,但对于我的生活,我无法在这里或其他任何地方找到答案.我是否必须扩展ActiveDirectoryLdapAuthenticationProvider类,并从那里调用我的权限populator?

(感谢本网站多年来给予我的所有帮助;这个网站的有效性可以通过我最近只是为创建帐户而烦恼来衡量,这是我的第一个问题.提前感谢你的帮助.)

java spring ldap active-directory spring-security

10
推荐指数
1
解决办法
8281
查看次数

如何通过LDAP over TLS对Active Directory进行身份验证?

我有一个工作概念验证应用程序,它可以在测试服务器上通过LDAP成功验证Active Directory,但生产应用程序必须通过TLS进行验证 - 域控制器关闭任何不通过TLS启动的连接.

我已经在Eclipse中安装了LDAP浏览器,我确实可以在其中使用TLS绑定,但我不能在我的生活中弄清楚如何让我的应用程序使用TLS.

ldap.xml:

<bean id="ldapAuthenticationProvider"
        class="my.project.package.OverrideActiveDirectoryLdapAuthenticationProvider">

    <!-- this works to authenticate by binding as the user in question -->
    <constructor-arg value="test.server"/>
    <constructor-arg value="ldap://192.168.0.2:389"/>

    <!-- this doesn't work, because the server requires a TLS connection -->
    <!-- <constructor-arg value="production.server"/> -->
    <!-- <constructor-arg value="ldaps://192.168.0.3:389"/> -->

    <property name="convertSubErrorCodesToExceptions" value="true"/>
</bean>
Run Code Online (Sandbox Code Playgroud)

OverrideActiveDirectoryLdapAuthenticationProvider是一个覆盖类,它扩展了Spring ActiveDirectoryLdapAuthenticationProvider类的副本,由于某种原因被指定final.我覆盖的原因与自定义用户对象上填充权限/权限的方式有关(我们将使用相关组的组成员身份来构建用户的权限,或者我们将从AD用户对象的字段中读取).在其中,我只是重写loadUserAuthorities()方法,但我怀疑我可能还需要覆盖bindAsUser()方法或可能的doAuthentication()方法.

XML和一个覆盖类是我的应用程序管理身份验证的唯一两个地方,而不是让Spring完成工作.我已经阅读了几个要启用TLS的地方我需要扩展DefaultTlsDirContextAuthenticationStrategy类,但是我在哪里连接它?是否有命名空间解决方案?我是否需要完全做其他事情(即放弃使用Spring ActiveDirectoryLdapAuthenticationProvider而改为使用LdapAuthenticationProvider)?

任何帮助表示赞赏.

java ldap active-directory spring-security spring-security-ldap

4
推荐指数
1
解决办法
6063
查看次数