Spring Security 3.2.1 Multiple login forms with distinct WebSecurityConfigurerAdapters

后端 未结 4 2251
我寻月下人不归
我寻月下人不归 2020-12-15 02:05

I\'m using Spring Security 3.2.1.RELEASE with Spring MVC 4.0.4.RELEASE

I\'m trying to setup Spring Security for a web application that will have two distinct login

4条回答
  •  一生所求
    2020-12-15 02:52

    I also encountered this problem and found out that I missed the first filtering part.

    This one:

    http.csrf().disable()
        .authorizeRequests()
        .antMatchers("/admin/**").hasRole("ADMIN")
    

    Should be:

    http.csrf().disable()
        .antMatcher("/admin/**")
        .authorizeRequests()
        .antMatchers("/admin/**").hasRole("ADMIN")
    

    Adding the first filtering .antMatcher("/admin/**") will first filter it so that it will use the AdminFormLoginWebSecurity instead of the other one.

提交回复
热议问题