wwha
V2EX  ›  问与答

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

  •  
  •   wwha · Nov 30, 2016 · 2810 views
    This topic created in 3460 days ago, the information mentioned may be changed or developed.
    我想用 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/**")
    ...
    }
    }
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3060 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 02:37 · PVG 10:37 · LAX 19:37 · JFK 22:37
    ♥ Do have faith in what you're doing.