Spring Security : Multiple HTTP Config not working

后端 未结 2 901
深忆病人
深忆病人 2020-11-22 13:27

I am trying to use Spring Security and I have a use case where I want different login pages and different set of URLs to be secured.

Here is my configuration:

<
2条回答
  •  旧巷少年郎
    2020-11-22 13:57

    Your first WebSecurityConfigurerAdapter's

    http
                .authorizeRequests()
    

    matches all the URLs, limit it to only URLs start with /admin by using antMatcher:

    @Configuration
    @Order(1)
    public static class ProviderSecurity extends WebSecurityConfigurerAdapter{
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http
                .antMatcher("/admin/**")
                    .authorizeRequests()
                    .antMatchers("/admin/login").permitAll()
                    .antMatchers("/admin/**").access("hasRole('BASE_USER')")
                    .and()
    
                    ...
    

提交回复
热议问题