gpt4 book ai didi

java - JHipster/React - 匿名从服务器获取数据(登录前)

转载 作者:行者123 更新时间:2023-11-30 07:43:10 24 4
gpt4 key购买 nike

我已经生成了一个 JHipster 应用程序(使用 ReactJs 的客户端)。我正在尝试向服务器创建一个匿名请求以在未经身份验证的情况下获取数据,但我收到了

{
"error": "unauthorized",
"error_description": "Full authentication is required to access this resource"
}

我在服务器端使用网关和游戏服务。我已经添加到网关 SecurityConfiguration.java 文件中

.and()
.authorizeRequests()
.antMatchers("/api/published-games").permitAll()

和游戏服务SecurityConfiguration.java文件

.and()
.authorizeRequests()
.antMatchers("/api/published-games").permitAll()

但仍然出现未经授权的错误。

最佳答案

我认为您没有编写所有的 SecurityConfiguration.java。

您需要指定允许所有人使用的完整端点路径:

.and()
.authorizeRequests()
.antMatchers("/app/test").permitAll()
....

您需要像在方法 LogoutResource.logout 中看到的那样实现服务,有些像这样:

    @RestController
@RequestMapping("/app")
public class PublicResource {

private final Logger log = LoggerFactory.getLogger(PublicResource.class);
private final UserService userService;
public PublicResource(UserService userService) {

this.userService = userService;
}

@GetMapping("/test")
public ResponseEntity<?> getATest(Pageable pageable) {
Map<String, String> logoutDetails = new HashMap<>();
logoutDetails.put("A", "One");
logoutDetails.put("B", "Two");
return ResponseEntity.ok().body(logoutDetails);
}
...

关于java - JHipster/React - 匿名从服务器获取数据(登录前),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53716322/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com