Пользовательские провайдеры аутентификации, основанные на URL, всегда вызывают только одного провайдера. - PullRequest
0 голосов
/ 25 июня 2019

Я настроил несколько пользовательских auth providers, используя auth2 и spring boot, но он всегда выполняет только CustomInternalAuthenticationProvider. Можете ли вы объяснить, как применять правила сопоставления муравьев в порядке? Я использовал два WebSecurityConfigurerAdapter классов и один упорядочен, а другой по умолчанию. Укажите, как правильно обрабатывать правила antmatcher?

@EnableResourceServer
@EnableWebSecurity
public class WebSecurityConfig{

    @Autowired
    UserDetailsService userDetailsService;

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(userDetailsService);
    }


    @Configuration
    @Order(1)
    public static class ApiWebSecurityConfig extends WebSecurityConfigurerAdapter{

        @Override
        protected void configure(HttpSecurity http) throws Exception {
            System.out.println("@order");
                      http.antMatcher("/../main/**")
                      .requestMatchers()
                      .antMatchers("/","/login*", "/oauth/authorize**","/exit","**/logout")

                  .and().authenticationProvider(daoInternalAuthenticationProvider())
                   .formLogin().loginPage("/login")

                ;
        }

        @Bean
        public AuthenticationProvider daoInternalAuthenticationProvider() throws Exception {

            return new CustomInternalAuthenticationProvider();
        }

    }

    @Configuration
    public static class ApiTokenSecurityConfig extends WebSecurityConfigurerAdapter{

        @Override
        protected void configure(HttpSecurity http) throws Exception {
            System.out.println("default");

                  http.antMatcher("/../user/**")
                      .requestMatchers()
                      .antMatchers("/","/login*", "/oauth/authorize**","/exit","**/logout")


                          .and() .authenticationProvider(daoExternalAuthenticationProvider())
               .formLogin().loginPage("/login")

               ;


        }

        @Bean
        public AuthenticationProvider daoExternalAuthenticationProvider() throws Exception {

            return new CustomExternalAuthonticationProvider();
        }






    }


...