使用@Secured闭包时如何获得控制器方法参数?

时间:2016-08-03 20:32:36

标签: grails spring-security grails-2.5 spring-security-rest

我已成功设置Grails应用程序以验证用户身份。

我使用URL params在我的UrlMappings.groovy:

中映射控制器方法参数
"/$source/owner/$ownerId/show"(controller:"myController", action: "show", method: "GET")

如何在@Secured关闭中获取$ source和$ ownerId的值?

我的控制器方法如下所示:

@Secured(closure = {
    //null
    def testSource = params.source

    //also null
    def testOwnerId = params.ownerId

    //null
    def owner = request.ownerId

    //null
    def owner2 = request.getParameter('ownerId')

    //contains only query string params
    def grailsParams = request['org.codehaus.groovy.grails.WEB_REQUEST']?.params

    return true
})
def show(String source, String ownerId) {
    ...
}

我如何获得这些值?我在做什么错了,在这里?

我认为这篇文章会提供一个解决方案,但那里给出的答案对我不起作用:

Is it possible to hack the spring-security-core plugin @Secured annotation to be able to reference request params given to a controller?

我使用以下grails和插件版本:

    grails 2.5.1
    compile ":spring-security-core:2.0-RC5"
    compile ":spring-security-rest:1.5.3", {
        excludes 'com.fasterxml.jackson.core:jackson-databind:'
    }

1 个答案:

答案 0 :(得分:1)

简要说明:

使用axis.text

详情:

在2.0中,您可以使用闭包作为注释的检查;文档中有一个简短的文章和示例:https://grails-plugins.github.io/grails-spring-security-core/v2/guide/newInV2.html

你这样表达你的例子:

request.getParameter

返回@Secured(closure={ request.getParameter('ownerId') >=123 //this is example }) 以允许访问,true拒绝访问。

相关问题