首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在@Secured表达式中使用服务方法?

如何在@Secured表达式中使用服务方法?
EN

Stack Overflow用户
提问于 2014-10-28 11:27:56
回答 1查看 434关注 0票数 0

我用的是Grailsspring-security-core:2.0-RC4

我试图在@Secured表达式中执行一些自定义安全检查,如下所示:

代码语言:javascript
复制
import grails.plugin.springsecurity.annotation.Secured;

class AdminController {
    def myCustomSecService;

    @Secured("@myCustomSecService.customCheck()")
    def index() {
        render(view:"index")
    }
}

这看起来一点也不管用。我见过类似的示例@PreAuthorize,但这(显然)需要spring-security-acl插件,我想避免使用(除非我真的必须使用)。

奇怪的是,spring-security-core插件包括一个带有@PreAuthorize@PostAuthorize注释的jar

我该怎么做呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-28 17:47:08

经过大量的挖掘,我想我找到了一个解决办法。

我在某个地方看到,如果我在使用Spring时必须重写类和方法,那么我可能做错了什么。

我所需要做的就是将@组件添加到我的服务中。

这是我来的结果,我做的是:

我的控制器:

代码语言:javascript
复制
import grails.plugin.springsecurity.annotation.Secured;

class AdminController {
    def myCustomSecService;

    @Secured("@myCustomSecService.customCheck()")
    def index() {
        render(view:"index")
    }
}

我的服务是:

代码语言:javascript
复制
import org.springframework.stereotype.Component;

@Component("myCustomSecService")
class MyCustomSecService {
    def customCheck() {
        /*do checks here*/
        return true;
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26607183

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档