2017-06-02 10 views
0

タイトルのように、ここに私の認証コードは次のとおりです。Spring Security Ldap、指定されたグループのユーザのみログイン

public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 

    auth.ldapAuthentication().userSearchFilter("(sAMAccountName={0})") 
    .contextSource(contextSource()); 
} 

私はgroupSearchFiltergroupSearchBaseまたはgroupRoleAttributeのような機能があることがわかったが、私はそれはあなたのグループメンバーシップの設定方法にどのように依存するか、それらを

答えて

0

を使用するには考えています。次のようなものは、あなたのグループのDNを交換し、作業し、必要に応じてオブジェクト・クラスがあります

groupSearchBase("cn=yourgroup,ou=groups") 
groupSearchFilter("(uniqueMember={0})") 
0
"(sAMAccountName={0})" 

は、以下に置き換えてくださいCNは、OU、DCグループの仕様です

"(&(objectCategory=Person)(sAMAccountName=*)(memberOf=cn=entergroup,ou=users,dc=company,dc=com))" 

ディレクトリ内

0

メガの解決策をいくつか修正しました

@Configuration 
@EnableWebSecurity 
public class SecurityConfig extends WebSecurityConfigurerAdapter { 

    @Configuration 
    protected static class AuthenticationConfiguration extends GlobalAuthenticationConfigurerAdapter { 

     @Override 
     public void init(AuthenticationManagerBuilder auth) throws Exception {    
      DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource("ldap://ip:port/DC=xxxx,DC=yyyy"); 
      contextSource.setUserDn("user_service_account"); 
      contextSource.setPassword("password_user_service_account"); 
      contextSource.setReferral("follow"); 
      contextSource.afterPropertiesSet(); 

      LdapAuthenticationProviderConfigurer<AuthenticationManagerBuilder> ldapAuthenticationProviderConfigurer = auth.ldapAuthentication(); 

      ldapAuthenticationProviderConfigurer 
       .userSearchBase("OU=Users,OU=Servers") 
       .userSearchFilter("(&(cn={0})(memberOf=CN=GROUP_NAME,OU=Groups,OU=Servers,DC=xxxx,DC=yyyy))") 
       .contextSource(contextSource); 
     } 
    } 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 

     http.authorizeRequests() 
      .antMatchers("/admin/**").authenticated().and() 
      .httpBasic(); 
    } 
} 
関連する問題