Java Spring引导迁移后总是未经授权

Java Spring引导迁移后总是未经授权,java,spring,rest,spring-boot,Java,Spring,Rest,Spring Boot,我正在努力从SpringBoot1升级到SpringBoot2,但我已经被困了两天了 身份验证过去在我的React/Spring启动应用程序上运行得很好,但是在迁移之后一切都很好,但是在我的api/authenticate资源上总是得到401(未经授权) 以下是经过一些更改后我的安全配置: @Override public void configure(HttpSecurity http) throws Exception { http.httpBasic()

我正在努力从SpringBoot1升级到SpringBoot2,但我已经被困了两天了

身份验证过去在我的React/Spring启动应用程序上运行得很好,但是在迁移之后一切都很好,但是在我的api/authenticate资源上总是得到401(未经授权)

以下是经过一些更改后我的安全配置:

@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调试79640---[nio-8080-exec-7]o.s.s.w.a.www.BasicAuthenticationFilter:失败的身份验证请求:org.springframework.security.Authentication.BadCredentialsException:gaca.api.errors.Authentication.0001
2019-07-02 11:02:13.100调试79640---[nio-8080-exec-7]s.w.a.DelegatingAuthenticationEntryPoint:尝试使用RequestHeaderRequestMatcher进行匹配[expectedHeaderName=X-Requested-With,expectedHeaderValue=XMLHttpRequest]
2019-07-02 11:02:13.100调试79640---[nio-8080-exec-7]s.w.a.DelegatingAuthenticationEntryPoint:找到匹配项!正在执行org.springframework.security.web.authentication。HttpStatusEntryPoint@17b900b4
2019-07-02 11:02:13.101调试79640---[nio-8080-exec-7]w.c.HttpSessionSecurityContextRepository:SecurityContext为空或内容为匿名-上下文将不会存储在HttpSession中。
2019-07-02 11:02:13.101调试79640---[nio-8080-exec-7]s.s.w.c.SecurityContextPersistenceFilter:SecurityContextHolder现在已清除,请求处理已完成

我想知道哪个过滤器挡住了我

有了正确的证书,我得到:

2019-07-02 11:07:06.397调试79640---[nio-8080-exec-3]例如c.S.LimitLoginAuthenticationProvider:用户帐户凭据已过期


我没有处理任何类型的过期凭证

在碰撞Spring Boot版本时,心态发生了变化,这意味着对于Spring Boot 1(Spring Security 4),默认情况下所有内容都是不安全的,您必须明确定义安全端点。在SpringBoot2(SpringSecurity5)中,默认情况下一切都是安全的,您必须明确定义哪些端点应该是不安全的。最简单的调试方法是在Spring安全筛选器中设置断点,并确定哪个筛选器拒绝您的请求。感谢@BogdanSucaciu,我已经做了一些更新,该
LimitLoginAuthenticationProvider
来自何处?它似乎不是标准Spring安全包的一部分。在升级Spring启动版本时,人们的心态发生了变化,这意味着对于Spring启动1(Spring Security 4),默认情况下一切都是不安全的,您必须明确定义安全端点。在SpringBoot2(SpringSecurity5)中,默认情况下一切都是安全的,您必须明确定义哪些端点应该是不安全的。最简单的调试方法是在Spring安全筛选器中设置断点,并确定哪个筛选器拒绝您的请求。感谢@BogdanSucaciu,我已经做了一些更新,该
LimitLoginAuthenticationProvider
来自何处?它似乎不是标准Spring安全包的一部分。