Grails上的spring-security-oauth2-provider提供程序

时间:2012-06-26 14:29:25

标签: grails oauth-2.0

我需要公开Grails网络应用程序的特定URL。但是,我希望它受OAuth2客户端凭据流(grant_type)的保护。 确切地说,外部代理会向

之类的内容发送请求
http://server-url/oauth/token?client_id=clientId&client_secret=clientSecret&grant_type=client_credentials

并获取access_token。然后,我的URL(受保护资源)应该可以访问类似

的内容
http://server-url/resource?access_token={access-token obtained before}

到目前为止,我的方法是使用这个grails插件(spring-security-oauth2-provider:http://grails.org/plugin/spring-security-oauth2-provider)。

根据https://github.com/adaptivecomputing/grails-spring-security-oauth2-provider提供的文档,我已经能够设置授予access_token部分(注册客户端可以通过提供其id和秘密来获取访问令牌。但是,我无法理解从教程中了解如何保护给定资源(仅限访问具有访问令牌的客户端)。

上面的文档链接仅提到设置访问令牌分发的阶段,然后转移到用户批准(我不需要)。

关于如何进行的任何指示都会很好。或者,也欢迎有关满足要求的任何其他选项的建议。

2 个答案:

答案 0 :(得分:1)

grails插件是spring安全插件spring-security-oauth的包装,请查看spring-security-oauth文档。我假设您已经熟悉ouath2规范,如果没有阅读enter link description here,甚至google oauth2 API都是google文档示例。 你正在使用的插件没有更新到spring-security-oauth的最后一个版本,如果你想看看我已经分叉并在github上更新它

答案 1 :(得分:0)

您可以使用spring-security-core保护资源。示例:您可以在Requestmap中列出网址路径。

new Requestmap(url: '/api/v1/states/**', configAttribute: 'ROLE_USER,ROLE_USER').save()
new Requestmap(url: '/api/v1/subscriptions/**', configAttribute: 'ROLE_USER,ROLE_USER').save()
new Requestmap(url: '/api/v1/surveys/**', configAttribute: 'ROLE_USER,ROLE_USER').save()

我已经使用grails插件测试了“spring-security-oauth2-provider:1.0.0.M5.1”。

相关问题