带有 Spring Security 和 Java Config 的自定义身份验证提供程序 [英] Custom Authentication provider with Spring Security and Java Config

查看:30
本文介绍了带有 Spring Security 和 Java Config 的自定义身份验证提供程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 Spring Security 和 Java 配置来定义自定义身份验证提供程序?我想对我自己的数据库执行登录检查凭据.

How can I define a custom Authentication provider by using Spring Security with Java Configurations? I would like to perform a login checking credentials on my own database.

推荐答案

下面做你需要的(CustomAuthenticationProvider 是你的实现,需要由 Spring 管理)

The following does what you need (CustomAuthenticationProvider is your implementation which needs to be managed by Spring)

@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);
    }
}

这篇关于带有 Spring Security 和 Java Config 的自定义身份验证提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆