我用的是Grails和spring-security-core:2.0-RC4
我试图在@Secured表达式中执行一些自定义安全检查,如下所示:
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。
我该怎么做呢?
发布于 2014-10-28 17:47:08
经过大量的挖掘,我想我找到了一个解决办法。
我在某个地方看到,如果我在使用Spring时必须重写类和方法,那么我可能做错了什么。
我所需要做的就是将@组件添加到我的服务中。
这是我来的结果,我做的是:
我的控制器:
import grails.plugin.springsecurity.annotation.Secured;
class AdminController {
def myCustomSecService;
@Secured("@myCustomSecService.customCheck()")
def index() {
render(view:"index")
}
}我的服务是:
import org.springframework.stereotype.Component;
@Component("myCustomSecService")
class MyCustomSecService {
def customCheck() {
/*do checks here*/
return true;
}
}https://stackoverflow.com/questions/26607183
复制相似问题