这有点烦人,因为我已经解决了最初的问题(就是这样),但现在这是另一件我不能完全调试的事情。
我在我的项目中使用JHispter 6.10 (Spring Boot2.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()这似乎工作得很好,但当我第一次加载应用程序(在dev模式下)时,它抛出了下一个错误:
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是否遗漏了什么,或者配置的顺序是否需要不同才能正常工作。
发布于 2021-07-13 05:19:42
您必须在Spring Boot Configuration (SecurityConfiguration.java)中为您的端点提供权限
在HttpSecurity.authorizeRequests()中添加一个新的antMatchers参数,如下所示:
http
.authorizeRequests()
.antMatchers("/api/yourEndpoint").permitAll()当然,您必须选择谁有权调用此端点
希望它能为您工作:)
https://stackoverflow.com/questions/64275716
复制相似问题