java - 启动应用程序时“未经授权:访问此资源需要完全身份验证”
问题描述
这有点烦人,因为我已经解决了最初的问题(就是这个),但现在这是我自己无法调试的另一件事。
我正在为我的项目使用 JHispter 6.10 (Spring Boot 2.2.7.RELEASE) + React。我最近开始需要将实体用作目录(以便管理员可以轻松管理它们),并且需要在注册页面上使用它们。我的第一个问题是他们不会在注册页面中出现下拉菜单,但这个问题与SecurityConfiguration.java
,所以我将允许的实体添加到所有:
.antMatchers("/api/comunidad-famdals").permitAll()
.antMatchers("/api/ciudads").permitAll()
.antMatchers("/api/estados").permitAll()
.antMatchers("/api/ladrillo-famdals").permitAll()
.antMatchers("/api/pais").permitAll()
.antMatchers("/api/**").authenticated()
这似乎工作得很好,但是我第一次加载应用程序(在开发模式下)时,它会引发下一个错误:
2020-10-09 02:03:33.337 DEBUG 63312 --- [ XNIO-1 task-9] c.f.m.r.CustomAuditEventRepository : Enter: add() with argument[s] = [AuditEvent [timestamp=2020-10-09T07:03:33.302498Z, principal=anonymousUser, type=AUTHORIZATION_FAILURE, data={details=org.springframework.security.web.authentication.WebAuthenticationDetails@b364: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: null, type=org.springframework.security.access.AccessDeniedException, message=Access is denied}]]
2020-10-09 02:03:33.342 DEBUG 63312 --- [ XNIO-1 task-9] c.f.m.r.CustomAuditEventRepository : Exit: add() with result = null
2020-10-09 02:03:33.473 WARN 63312 --- [ XNIO-1 task-9] o.z.problem.spring.common.AdviceTraits : Unauthorized: Full authentication is required to access this resource
2020-10-09 02:03:33.564 WARN 63312 --- [ XNIO-1 task-9] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.security.authentication.InsufficientAuthenticationException: Full authentication is required to access this resource]
尝试注册时,下拉列表仍然没有显示任何内容:
但是如果我再次回家,终端显示所有查询都已正确完成,如果我回到注册页面,果然:
我想知道我是否遗漏了某些东西,SecurityConfiguration.java
或者配置的顺序是否需要不同才能正常工作。
解决方案
您必须在 Spring Boot 配置 (SecurityConfiguration.java) 中授予端点权限
向它添加一个新antMatchers
参数HttpSecurity.authorizeRequests()
应该如下所示:
http
.authorizeRequests()
.antMatchers("/api/yourEndpoint").permitAll()
当然你必须选择谁有权调用这个端点
希望这对你有用 :)
推荐阅读
- c++ - 无法编译 CMake
- c - C 中的自动函数指针
- flutter - Flutter 如何将数据从 sqflite 填充到下拉列表
- rx-java - fromIterable 之后如何保证订阅的顺序?
- c# - 使用特定数据填充组合框的功能一次不适用于超过 1 个组合框,没有明确的错误
- java - 应用字体中的 Android 操作系统覆盖
- node.js - 如何在节点 js 中等待子查询结果?
- r - 如何使用 GGPlot 绘制两条虚线回归线
- amazon-web-services - 如何使用 AWS CDK 将 Internet 网关添加到 VPC?
- javascript - gulp 构建失败,粉笔版本:3.0.0