2015-09-14 87 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("..."); 
} 
相關問題