我正在用这篇文章中的 wso2is 服务器做 Spring Boot Security 的示例 https://github.com/angel-git/wso2is-springoauth,当我尝试使用访问令牌访问资源时,我得到
{"error":"未经授权","error_description":"需要完全身份验证才能访问此资源"}
我通过以下方式生成访问令牌:
curl -u CLIENT_ID:CLIENT_SECRET-k -d “grant_type=密码&用户名=admin&密码=admin”-H “内容类型:application/x-www-form-urlencoded” https://localhost:9443/oauth2/token
并通过以下方式访问资源:
curl -H GET“授权:ACCESS_TOKEN” http://localhost:8080/greeting
我在 stackoverflow 上找到了很多解决方案,但不幸的是无法解决我的问题
请帮忙,谢谢
我收到了相同的错误消息
"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
中设置以下属性绕过了安全检查,我可以使用所有执行器端点:
management.security.enabled=false
非常感谢 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
当上述答案无法解决此问题时,请将文件中的
OAuthConfigurations/RemoveOAuthHeadersFromOutMessage
更改为 false
api-manager.xml
。
我遇到此问题是因为我没有在身份验证过滤器中正确验证用户身份。请检查用户是否确实经过身份验证并且角色是否已正确填写。
UsernamePasswordAuthenticationToken authentication =
new UsernamePasswordAuthenticationToken(
userDetails,
null,
userDetails.getAuthorities());
System.out.println("Is user authenticated? " + authentication.isAuthenticated())