V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
wwha
V2EX  ›  问与答

Spring Security 怎么实现普通用户和后台管理员认证分离?

  •  
  •   wwha · 2016-11-30 15:44:08 +08:00 · 2068 次点击
    这是一个创建于 2711 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我想用 Spring Security 实现普通用户使用一个登录入口和一个 AuthenticationProvider ,后台管理员使用另一个一个登录入口和另一个 AuthenticationProvider 。但是 Spring 官网上说,所有的 AuthenticationProvider 都是由 ProviderManager 管理的,有多个 provider ,他们将会被按顺序进行尝试(内部使用了一个 List),每个 provider 都可以尝试进行认证,或者简单的通过返回 null 来跳过认证。直到认证通过为止。我想问能不能一个 HttpSecurity 对应一个 AuthenticationProvider ,这样就不用做多余尝试了。

    现在我在一个类中定义了两个 HttpSecurity,请问有什么解决方法吗?:

    @Configuration
    public static class UserLoginWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
    ...
    @Override
    protected void configure(HttpSecurity http) throws Exception {

    http.authorizeRequests()
    .antMatchers("/")
    ...
    }

    //管理员登录配置
    @Configuration
    @Order(1)
    public static class AdminWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {
    ...

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

    http.authorizeRequests()
    .antMatchers("/admin/**")
    ...
    }
    }
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2175 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 02:10 · PVG 10:10 · LAX 19:10 · JFK 22:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.