2013-02-11 132 views
3

我將Grails應用程序分成兩個應用程序 - 一個面向客戶的Web應用程序和一個託管REST API的單獨應用程序。我這樣做是因爲我正在構建一個iOS應用程序以使用我的網絡應用程序。我的應用程序使用Spring Security,我想保護REST API。令人驚訝的是,我發現很少有關於如何正確執行此操作的信息。我是否應該使用Spring Security實現oauth,從而使我的API應用成爲oauth提供者?在Grails和Spring Security中保護REST API

任何建議將是偉大的。

+1

http://stackoverflow.com/questions/11220359/grails-securing-rest-api-with-oauth2-0 http://stackoverflow.com/questions/7095925/grails-and-oauth http:// stackoverflow安全 - 使用 - 移動 - 應用程序 – Gregg 2013-02-11 20:56:22

+0

因此,基本上不提供完整的解決方案。 – RyanLynch 2013-02-13 02:33:35

回答

3

是的,我只是做了另一個應用程序。當訪問REST URL時,你必須告訴spring security的行爲不同。

添加到您的config.groovy

現在,你有你自己的應用程序,按以下方式認證與/ API

一)任何(假設這就是你怎麼有你的REST設立的兩個部分)在URL中,獲得基本身份驗證

b)其他所有內容都通過登錄頁面。

http://grails.org/plugin/spring-security-rest

看一看它,讓我知道,如果您有任何:

// making the application more secured by intercepting all URLs 
grails.plugins.springsecurity.useBasicAuth = true 
grails.plugins.springsecurity.basic.realmName = " REST API realm" 
grails.plugins.springsecurity.securityConfigType = SecurityConfigType.InterceptUrlMap 




//Exclude normal controllers from basic auth filter. Just the JSON API is included 
grails.plugins.springsecurity.filterChain.chainMap = [ 
'/api/**': 'JOINED_FILTERS,-exceptionTranslationFilter', 
'/**': 'JOINED_FILTERS,-basicAuthenticationFilter,-basicExceptionTranslationFilter' 
] 
3

我已經在過去幾週期間,涵蓋正是你想做的事插件工作問題。

+0

儘管這可能在理論上回答這個問題,但[這將是更可取的](http://meta.stackoverflow.com/q/8259)在這裏包含答案的基本部分,並提供了供參考的鏈接。 – 2014-06-11 11:11:01

相關問題