【问题标题】:Spring Boot: Full authentication is required to access this resourceSpring Boot:访问此资源需要完全身份验证
【发布时间】:2016-10-03 10:01:53
【问题描述】:

我在这篇文章https://github.com/angel-git/wso2is-springoauth 中使用 wso2is 服务器做 Spring Boot Security 示例,当我尝试使用访问令牌访问资源时,我得到了

{"error":"unauthorized","error_description":"访问此资源需要完全认证"}

我正在通过以下方式生成访问令牌:

curl -u CLIENT_ID:CLIENT_SECRET -k -d “授予类型=密码&用户名=管理员&密码=管理员”-H “内容类型:应用程序/x-www-form-urlencoded” https://localhost:9443/oauth2/token

并通过以下方式访问资源:

curl -H GET "授权:ACCESS_TOKEN" http://localhost:8080/greeting

我在 stackoverflow 上找到了很多解决方案,但遗憾的是无法解决我的问题

请帮忙,谢谢

【问题讨论】:

  • 使用Authorization: Bearer ACCESS_TOKEN格式发送不记名令牌
  • 谢谢回复,我还是遇到同样的问题
  • 你用过curl -H "Authorization: Bearer ACCESS_TOKEN" http://localhost:8080/greeting吗?删除GET
  • 现在给出 {"error":"access_denied","error_description":"Access is denied"}
  • 我猜你没有所需的角色

标签: security spring-boot access-token wso2is


【解决方案1】:

非常感谢帮助我解决问题的 Angel Gavalda。我使用以下命令生成访问令牌和访问资源

用于生成访问令牌:-

卷曲 -k -d 'grant_type=client_credentials&client_id=yourClientId&client_secret=yourClientSecret' https://localhost:9443/oauth2/token

对于访问资源:-

curl -k -H "授权:承载 $ACCESS_TOKEN" http://localhost:8080/greeting

【讨论】:

  • 当我尝试访问资源时,我收到“请联系您的管理员”。我使用了错误的请求网址吗?我尝试了另一个 url,我收到了操作正在获取的错误消息。
  • @Jesse 你是如何访问资源的?
  • @GelSisaed 来自邮递员,这很简单。从 wso2 获取令牌,然后通过提供 Authz 类型作为承载令牌来访问您的服务。
【解决方案2】:

我收到了同样的错误消息

"curl http://localhost:8080/spring4/beans" :
{"timestamp":1493591079040,"status":401,"error":"Unauthorized","message":"Full authentication is required to access this resource.","path":"/spring4/beans"}

application.properties 中设置以下属性绕过了安全检查,我可以使用所有 acuator 端点:

management.security.enabled=false

【讨论】:

  • 不知何故,我怀疑绕过安全性对于尝试使用 Spring 安全性的人来说是正确的答案。
  • 是的,我只是用它来测试。必须使用令牌等以获得完全的安全性。
【解决方案3】:

如果上述答案不能解决此问题,请将文件api-manager.xml 中的OAuthConfigurations/RemoveOAuthHeadersFromOutMessage 更改为false

【讨论】:

    猜你喜欢
    • 2018-09-11
    • 2019-01-01
    • 2020-11-21
    • 2020-10-25
    • 1970-01-01
    • 2016-11-11
    • 2015-01-08
    • 2020-03-30
    • 2022-01-03
    相关资源
    最近更新 更多