java - Spring引导迁移后总是未经授权
问题描述
我正在努力将 Spring boot 1 升级到 Spring boot 2,但我已经卡住了 2 天。
身份验证过去在我的 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 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
我没有处理任何类型的过期凭据
解决方案
推荐阅读
- macos - GateKeeper 拒绝允许在 MacOS 上执行经过公证和装订的应用程序
- python - PyGame 没有检测到 Button 6 按下?
- javascript - 使用 chart.js 动态添加新图表
- python - 使用一种有效的方法以给定的顺序根据参数调用 python 函数以最小化 if-else 语句的使用
- excel - 如何使用 VBA 模块计算新工作表中输出中的重复值
- python - 如何在魔术函数定义中引用“In”?
- python - 如何以最佳方式替换数据框
- arrays - Swift如何过滤2个数组
- multithreading - 在不使用 OMP TASK 的情况下如何做到这一点?
- vue.js - 当我尝试使用组件中的方法更改数据时,为什么我的 vuex 存储状态更改?