21

Java 構成で Spring Security を使用してカスタム認証プロバイダーを定義するにはどうすればよいですか? 自分のデータベースで認証情報をチェックするログインを実行したいと考えています。

4

2 に答える 2

45

以下は、必要なことを行います(CustomAuthenticationProviderSpring で管理する必要がある実装です)

@Configuration
@EnableWebMvcSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private CustomAuthenticationProvider customAuthenticationProvider;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        /**
         * Do your stuff here
         */
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.authenticationProvider(customAuthenticationProvider);
    }
}
于 2014-03-24T10:33:00.667 に答える