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

Spring Active Directory Authentication using "proxy" user

我在我的项目中有特殊要求,即针对 Active Directory 的身份验证应使用特殊 ("proxy") 用户完成。也就是说,首先我们必须使用这个特殊用户登录到 AD,然后我们应该 "query" AD 关于 "real" 用户(试图登录我的用户)的凭据应用程序)是正确的,使用 "proxy" 用户会话。

有没有办法使用 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>

这是认证部分的配置 spring:

<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>

感谢您的帮助!!

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

@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("...");
}