使用"proxy"用户的 Spring Active Directory 身份验证



在我的项目中,我有一个特殊的需求,说明针对Active Directory的身份验证应该使用一个特殊的("代理")用户来完成。也就是说,首先我们必须使用这个特殊用户登录到AD,然后我们应该使用"代理"用户会话"查询"AD关于"真实"用户(正在尝试登录我的应用程序的用户)的凭据是否正确。

是否有一种方法可以使用spring安全性来做到这一点?…现在我用的是org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider

这些是我当前的依赖项:

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>3.2.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>3.2.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>3.2.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-ldap</artifactId>
        <version>3.2.5.RELEASE</version>
    </dependency>

这是通过弹簧的认证部分的配置:

<beans:bean id="ldapAuthProvider" class="org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider">
    <beans:constructor-arg>
        <beans:value>${security.ad.domain}</beans:value>
    </beans:constructor-arg>
    <beans:constructor-arg>
        <beans:value>${security.ad.url}</beans:value>
    </beans:constructor-arg>
</beans:bean>
<authentication-manager>
    <authentication-provider ref="ldapAuthProvider" />
</authentication-manager>

谢谢你的帮助!

我成功尝试了你的方案。也许晚了,但它可能会帮助别人。首先,我按照这里的描述设置我的项目。其次,我在我的WebSecurityConfig类中添加了以下内容:

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception 
{
    auth
        .ldapAuthentication()
            // User Base DN
            .userDnPatterns("cn={0},ou=...,ou=...,o=...,c=...") 
            .contextSource()
                // ldap server
                .url("ldaps://server:636") 
                // Bind credentials Bind DN
                .managerDn("cn=...,ou=...,o=...,c=...") 
                // Bind credentials Bind Password
                .managerPassword("...");
}

最新更新