Spring security 5 / Spring boot 2.2: не найден AuthenticationProvider для org.springframework.security.authentication.UsernamePasswordAuthenticationToken - PullRequest
0 голосов
/ 26 мая 2020

Мы обновляем наши приложения с Spring boot 1.5.x до 2.2.x и Spring Security 4.x до 5.3.2. У нас есть следующие определения для нашей веб-безопасности:

 @EnableWebSecurity
 @Configuration
 @EnableGlobalMethodSecurity(prePostEnabled = true)
 @Profile("uno")
 public class UnoSecurityConfig extends AbstractSecurityConfig {

 @Autowired
 private ServletContext servletContext;

 @Override
 protected void configure(HttpSecurity http) throws Exception {
    BasicAuthFilter basicAuthFilter = new BasicAuthFilter();
    basicAuthFilter.init(new BasicAuthSSOFilterConfig(servletContext));
    http
            .csrf().disable()
            .authorizeRequests()
            .antMatchers(HttpMethod.GET, "/ping").permitAll()
            .antMatchers(HttpMethod.POST, "/ping").permitAll()
            .antMatchers("/**").hasAuthority(OurPrivileges.ALL_MEASURE)
            .antMatchers(HttpMethod.OPTIONS, "/**").permitAll()//allow CORS option calls
            .and()
            .addFilter(securityContextPersistenceFilter())
            .addFilterAfter(new RequestContextFilter(), SecurityContextPersistenceFilter.class)
            .addFilterAfter(new CrossFramePreventionFilter(), RequestContextFilter.class)
            .addFilterAfter(basicAuthFilter, CrossFramePreventionFilter.class)
            .addFilterAfter(preAuthenticationFilter(), BasicAuthFilter.class)
            .addFilterAfter(exceptionTranslationFilter(), PreAuthenticatedUserDetailsFilter.class);
    http.headers().contentSecurityPolicy(SecurityUtility.getContentSecurityPolicy());
}

Когда я пытаюсь попасть в конечную точку / ping, он должен просто впустить меня, но вместо этого я получаю всплывающее окно аутентификации, а затем мне отказывают. Я вижу это в журналах:

2020-05-26 09:56:39.881-0500 DEBUG APP=829 COMP=782 [https-jsse-nio-30062-exec- 
2:OrRequestMatcher:[]] -Trying to match using Ant [pattern='/actuator/health/**']
2020-05-26 09:56:39.881-0500 DEBUG APP=829 COMP=782 [https-jsse-nio-30062-exec- 
2:AntPathRequestMatcher:[]] -Checking match of request : '/ping'; against '/actuator/health/**'
2020-05-26 09:56:39.881-0500 DEBUG APP=829 COMP=782 [https-jsse-nio-30062-exec-2:OrRequestMatcher:[]] -Trying to match using Ant [pattern='/actuator/info/**']
2020-05-26 09:56:39.881-0500 DEBUG APP=829 COMP=782 [https-jsse-nio-30062-exec-2:AntPathRequestMatcher:[]] -Checking match of request : '/ping'; against '/actuator/info/**'
2020-05-26 09:56:39.881-0500 DEBUG APP=829 COMP=782 [https-jsse-nio-30062-exec-2:OrRequestMatcher:[]] -Trying to match using Ant [pattern='/actuator']
2020-05-26 09:56:39.881-0500 DEBUG APP=829 COMP=782 [https-jsse-nio-30062-exec-2:AntPathRequestMatcher:[]] -Checking match of request : '/ping'; against '/actuator'
2020-05-26 09:56:39.881-0500 DEBUG APP=829 COMP=782 [https-jsse-nio-30062-exec-2:OrRequestMatcher:[]] -Trying to match using Ant [pattern='/actuator/']
2020-05-26 09:56:39.881-0500 DEBUG APP=829 COMP=782 [https-jsse-nio-30062-exec-2:AntPathRequestMatcher:[]] -Checking match of request : '/ping'; against '/actuator/'
2020-05-26 09:56:39.881-0500 DEBUG APP=829 COMP=782 [https-jsse-nio-30062-exec-2:OrRequestMatcher:[]] -No matches found
2020-05-26 09:56:39.881-0500 DEBUG APP=829 COMP=782 [https-jsse-nio-30062-exec-2:AntPathRequestMatcher:[]] -Request '/ping' matched by universal pattern '/**'

Другие конечные точки, требующие аутентификации, не пропускают меня и выдают ошибки 401/403, при этом выбрасывается исключение, являющееся заголовком сообщения. Кажется очевидным, что spring не использует наш собственный logi c. Ничего из нашего кода не изменилось, только зависимости. Как мне выйти за рамки этого?

1 Ответ

0 голосов
/ 26 мая 2020

Переопределение конфигурации создает новую цепочку фильтров, которая идет за SpringSecurityFilterChain по умолчанию по приоритету и, следовательно, принимает все запросы и все отклоняет. Я добавил @Order (1) в свой класс конфигурации безопасности, который решил проблему.

...