2015-09-14 90 views
0

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

有没有办法做到这一点使用弹簧安全? ...现在我正在使用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> 

感谢您的帮助!

回答

0

我试着成功了你的场景。也许晚了,但它可能会帮助别人。 首先,我按照here的描述设置我的项目。其次,我在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("..."); 
} 
相关问题