使用 Shiro 保护 grails 中的服务
我正在使用 grails 构建一个主要作为服务框架运行的应用程序。我的问题是:服务能否以与控制器相同的方式得到保护?
基于 uri 的示例:
class SecurityFilters {
def filters = {
all(uri: "/**") {
before = {
// Ignore direct views (e.g. the default main index page).
if (!controllerName) return true
// Access control by convention.
accessControl()
}
}
}
}
I'm using grails to build an application that functions primarily as a service framework. My question is: Can services be secured in the same fashion as controllers?
uri-based example:
class SecurityFilters {
def filters = {
all(uri: "/**") {
before = {
// Ignore direct views (e.g. the default main index page).
if (!controllerName) return true
// Access control by convention.
accessControl()
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道 Shiro 插件是否支持此功能,但是 Acegi 插件< /a> 确实如此,尽管是以“实验”方式(无论这意味着什么)。
更新
正确阅读问题后,您似乎在问是否可以使用过滤器来保护服务。如果是这种情况,那么 Shiro 就有点无关紧要了,因为执行授权的是过滤器,而不是 Shiro。
因此,要回答您是否可以使用过滤器来保护服务的问题,答案是否定的,因为您只能从过滤器内访问控制器。但是,您可以使用 Groovy 元编程对服务执行 AOP 样式的方法拦截。
基本方法是:
invokeMethod
属性。旁白
如果可能的话,我强烈建议使用经过验证的安全性插件(例如 Shiro、Acegi)来执行授权检查,而不是按照上述方式自行进行。
I've no idea if the Shiro plugin supports this, but the Acegi plugin does, albeit in an "experimental" fashion (whatever that means).
Update
Having read the question properly, it seems you're asking whether you can use filters to secure services. If this is the case, then Shiro is somewhat irrelevant, because it's the filters that are performing authorisation, not Shiro.
So to answer your question about whether you can use filters to secure services, the answer is no, because you only have access to the controller from within a filter. However, you could use Groovy metaprogramming to do AOP-style method interception on services.
The basic approach is:
invokeMethod
property to the MetaClassAside
If at all possible, I would strongly recommend using a proven security plugin (e.g. Shiro, Acegi) to perform the authorization checks rather than rolling your own in the manner described above.