2014-06-09 222 views
0

我有一些問題,使此項目https://github.com/royclarkson/spring-rest-service-oauth運行。我克隆並運行mvn spring-boot:run和儘快的Tomcat在8080端口上推出,我訪問它從瀏覽器:安全REST與春季安全

http://localhost:8080/greeting 

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

+0

你看着[這](http://thoughtfulsoftware.wordpress.com/2013/12/08/adding-security-to-spring-guides-rest-service/ )? –

+1

403響應意味着您的應用程序正在運行並且它是安全的(我可能首選401未經身份驗證的請求)。所以有什麼問題? –

+0

@DaveSyer我的不好,我沒有去正確的過程..無論如何,X_X,我試過/移植這與Spring Boot GAE *應用引擎和安全性不啓動http://stackoverflow.com/questions/24109189 /彈簧安全認證 - 不燒起來 – xybrek

回答

0

解決的辦法是訪問資源:

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"