2016-08-01 3 views
0

ユーザーが自分のUIDとメールの両方でログインできるようにしたいですか?私の春のセキュリティ設定を使用してこれを達成する方法?春のセキュリティでメールとuidに基づいてLDAPからユーザーを認証する方法は?

@Configuration 
@EnableWebSecurity 
public class SecurityConfiguration extends WebSecurityConfigurerAdapter { 
    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http 
       .authorizeRequests() 
       .anyRequest().fullyAuthenticated() 
       .and() 
       .formLogin().passwordParameter("password"); 
    } 

    @Configuration 
    protected static class AuthenticationConfiguration extends GlobalAuthenticationConfigurerAdapter { 

     @Autowired 
     LdapContextSource contextSource; 

     @Override 
     public void init(AuthenticationManagerBuilder auth) throws Exception { 
      auth 
        .ldapAuthentication() 
        .userDnPatterns("uid={0}") 
        .contextSource(contextSource); 
     } 
    } 
} 

userDnPatternsでは、uidと一緒に別の属性を指定できますか?または、uidによる認証が標準ですか?

答えて

1

カスタムユーザー検索フィルタを使用する必要があります。次のコードでは、ユーザーがログイン画面で入力した値にuidまたはメールを照合しようとするORフィルタを使用しています。

関連する問題