繁体   English   中英

通过Spring Security保护REST

[英]Secure REST with Spring Security

我在使该项目https://github.com/royclarkson/spring-rest-service-oauth运行时遇到问题。 我克隆了它并运行mvn spring-boot:run并且在端口8080上启动了Tomcat之后,我就从浏览器访问了它:

http://localhost:8080/greeting

但是它说, An Authentication object was not found in the SecurityContextunauthorized

解决方案是访问资源:

curl -X POST -vu clientapp:123456 http://localhost:8080/oauth/token -H "Accept: application/json" -d "password=spring&username=roy&grant_type=password&scope=read%20write&client_secret=123456&client_id=clientapp"

响应将类似于:

{"access_token":"ff16372e-38a7-4e29-88c2-1fb92897f558","token_type":"bearer","expires_in":43199,"scope":"read write"}

并放置令牌:

curl http://localhost:8080/greeting -H "Authorization: Bearer ff16372e-38a7-4e29-88c2-1fb92897f558"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM