Всегда становится неавторизованным после весенней загрузки - PullRequest
1 голос
/ 02 июля 2019

Я работаю над обновлением fron Spring boot 1 до Spring boot 2, но я застрял 2 дня назад.

Аутентификация раньше работала очень хорошо в моем загрузочном приложении React / Spring, но после миграции все было в порядке, но всегда получалось 401 (неавторизовано) на моем ресурсе api / authenticate.

Здесь мойконфигурация безопасности после некоторых изменений:

@Override
    public void configure(HttpSecurity http) throws Exception {
        http.httpBasic()
                //.authenticationEntryPoint(authenticationEntryPoint)
                .and()
                .authorizeRequests()
                .antMatchers(PERMIT_ALL_GET_URLS).permitAll()
                .antMatchers(HttpMethod.POST, PERMIT_ALL_POST_URLS).permitAll()
                .anyRequest().authenticated()
                .and()
                .logout().clearAuthentication(true)
                .logoutRequestMatcher(new AntPathRequestMatcher("/api/logout")).invalidateHttpSession(true).and().csrf()
                .requireCsrfProtectionMatcher(new RequestMatcher() {
                    private Pattern allowedMethods = Pattern.compile("^(GET|HEAD|TRACE|OPTIONS)$");
                    @Override
                    public boolean matches(HttpServletRequest request) {
                        // No CSRF due to public requests
                        if (stringContainsItemFromList(request.getRequestURI(), PERMIT_ALL_POST_URLS_PATTERN_PREFIX))
                            return false;
                        if (Arrays.asList(PERMIT_ALL_POST_URLS).contains(request.getRequestURI()))
                            return false;
                        // No CSRF due to allowed methods
                        if (allowedMethods.matcher(request.getMethod()).matches())
                            return false;
                        // CSRF for everything else
                        return true;
                    }
                }).csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
                .ignoringAntMatchers("/api/external/uploadBulkVerifications/*");
        http.exceptionHandling().authenticationEntryPoint(authenticationEntryPoint);
        http.headers().xssProtection().xssProtectionEnabled(true);
        http.headers().xssProtection().block(false);
        http.headers().defaultsDisabled().contentTypeOptions();
        http.sessionManagement().maximumSessions(2).expiredUrl("/");
        http.addFilterBefore(authenticationFilter(), UsernamePasswordAuthenticationFilter.class);
    }

Я что-то упустил или мне нужно также просмотреть метод authenticate()

РЕДАКТИРОВАТЬ :

С неправильными учетными данными я получил:

2019-07-02 11:02:13.100 DEBUG 79640 --- [nio-8080-exec-7] o.s.s.w.a.www.BasicAuthenticationFilter : Authentication request for failed: org.springframework.security.authentication.BadCredentialsException: gaca.api.errors.authentication.0001 2019-07-02 11:02:13.100 DEBUG 79640 --- [nio-8080-exec-7] s.w.a.DelegatingAuthenticationEntryPoint : Trying to match using RequestHeaderRequestMatcher [expectedHeaderName=X-Requested-With, expectedHeaderValue=XMLHttpRequest] 2019-07-02 11:02:13.100 DEBUG 79640 --- [nio-8080-exec-7] s.w.a.DelegatingAuthenticationEntryPoint : Match found! Executing org.springframework.security.web.authentication.HttpStatusEntryPoint@17b900b4 2019-07-02 11:02:13.101 DEBUG 79640 --- [nio-8080-exec-7] w.c.HttpSessionSecurityContextRepository : SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession. 2019-07-02 11:02:13.101 DEBUG 79640 --- [nio-8080-exec-7] s.s.w.c.SecurityContextPersistenceFilter : SecurityContextHolder now cleared, as request processing completed

Я хотел бы знать, какой фильтр блокирует меня

И с правильными учетными данными я получаю:

2019-07-02 11:07:06.397 DEBUG 79640 --- [nio-8080-exec-3] e.g.c.S.LimitLoginAuthenticationProvider : User account credentials have expired

У меня нет учетных данных с истекшим сроком действия

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...