2013-02-11 127 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

相关问题