Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
spring security java配置-多重身份验证管理器_Java_Spring Mvc_Spring Security - Fatal编程技术网

spring security java配置-多重身份验证管理器

spring security java配置-多重身份验证管理器,java,spring-mvc,spring-security,Java,Spring Mvc,Spring Security,我正在开发一个JavaSpringMVC应用程序。下面是我的setAuthenticationManager的SecurityConfig类的一部分: ... @Autowired private SecurityDAO securityDAO; ... @Override protected void configure(AuthenticationManagerBuilder registry) throws Exception { registry.userDetailsServi

我正在开发一个JavaSpringMVC应用程序。下面是我的set
AuthenticationManager
SecurityConfig
类的一部分:

...
@Autowired
private SecurityDAO securityDAO;
...
@Override
protected void configure(AuthenticationManagerBuilder registry) throws Exception {
    registry.userDetailsService(securityDAO).passwordEncoder(new BCryptPasswordEncoder());
}
SecurityDAO
是一个实现
UserDetailsService
接口的类

现在,我需要有两种不同的
UserDetailsService
接口实现。
一个用于
admin
用户的url
/admin/login
,另一个用于
customer
用户的url
/customer/login

我找到了一些使用spring实现多身份验证管理器的示例,但它们都使用XMLConfig,我找不到使用JavaConfig的示例


事实上,我想将此配置转换为java配置。

扩展AbstractAutowiringFactoryBean并在该类中添加您的实现

它有两个方法,doCreateInstance()知道需要实例化谁的对象,getObjectType()知道这是哪个接口实现

比如说

@Configuration
public class CLass extends AbstractAutowiringFactoryBean<Object> {

    public enum Env {
        devloper, production
    }

    Env envType = Env.devloper;

    @Override
    protected Object doCreateInstance() {
        switch (envType) {
            case devloper:

                return new ClassImpl1();
            case production:
                rreturn new ClassImpl2();

        }
        throw new RuntimeException("Unsupported implementation type");
    }

    @Override
    public Class<?> getObjectType() {
        return SecurityDAO.class;
    }

}
@配置
公共类扩展了AbstractAutowiringFactoryBean{
公共枚举环境{
开发、生产
}
Env envType=Env.devloper;
@凌驾
受保护对象doCreateInstance(){
开关(ENV型){
案例开发者:
返回新的ClassImpl1();
案例制作:
r返回新的ClassImpl2();
}
抛出新的RuntimeException(“不支持的实现类型”);
}
@凌驾
公共类getObjectType(){
返回SecurityDAO.class;
}
}