Java 访问此资源需要Jhipster网关完全身份验证
大家好,我正在ubuntu操作系统上开发Jhipster。 我的项目成功地完成了。 但当尝试测试API时,它会给我身份验证错误 下面是测试API时发生的错误。如果有人能帮助我,那将是我的荣幸 错误:Java 访问此资源需要Jhipster网关完全身份验证,java,api,web-services,authentication,jhipster,Java,Api,Web Services,Authentication,Jhipster,大家好,我正在ubuntu操作系统上开发Jhipster。 我的项目成功地完成了。 但当尝试测试API时,它会给我身份验证错误 下面是测试API时发生的错误。如果有人能帮助我,那将是我的荣幸 错误: rExceptionResolver : Resolved exception caused by Handler execution: org.springframework.security.authentication.InsufficientAuthenticationException:
rExceptionResolver : Resolved exception caused by Handler execution: org.springframework.security.authentication.InsufficientAuthenticationException: Full authentication is required to access this resource
网络浏览器
{
"type" : "https://www.jhipster.tech/problem/problem-with-message",
"title" : "Unauthorized",
"status" : 401,
"detail" : "Full authentication is required to access this resource",
"path" : "/api/account",
"message" : "error.http.401"
}
解决方案:
我找到了解决办法
Jhipster用户创建的默认配置存在问题。当我们使用Jhipster创建应用程序和实体时,它也会创建用户身份验证作为其功能。
但在我的例子中,用户不是在我在创建过程中选择的数据库中创建的 责任表:-
密码:admin 确保密码为加密形式 在我的情况下(在dev概要文件中),我更新了JWT令牌,在所有应用程序(微服务、网关和注册表)中更改为base64,此外,注释旧属性“secret”,并在所有应用程序中使用相同的键。然后在没有授权问题的情况下,从网关正确测试API
jh版本5.7.1看起来您在执行JHipster注册表时使用了身份验证,而应用程序则不使用身份验证。 如果您没有更改JHipster jwt密钥,则必须使用以下参数执行应用程序(微服务):
--spring.security.user.password=admin --jhipster.security.authentication.jwt.secret=my-secret-key-which-should-be-changed-in-production-and-be-base64-encoded --spring.cloud.config.server.composite.0.type=native --spring.cloud.config.server.composite.0.search-locations=file:./central-config
您可以在application.yml文件的中央配置包中找到JWT密钥
有关更多详细信息,请参阅JHipster文档:
请编辑您的问题,并提供更多详细信息,如JHipster版本、身份验证类型、应用程序类型等。。。你为什么认为这是个错误?401对于未经身份验证的受保护端点来说是正常的。@GaëlMarziou了解此错误还需要什么…?只需回答我在上面评论中提出的问题以及如何测试即可。编辑您的问题,而不是在评论中回答,这样更容易read@GaëlMarziou我得到了解决方案谢谢你给我宝贵的时间。好的,请在这里为其他人添加解决方案或删除问题