grails - 使用@Secured闭包时如何获取 Controller 方法参数?

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

我已经成功设置了Grails应用程序以对用户进行身份验证。

我在UrlMappings.groovy中使用URL参数映射 Controller 方法参数:

"/$source/owner/$ownerId/show"(controller:"myController", action: "show", method: "GET")

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

我的 Controller 方法如下所示:
@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) {
    ...
}

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

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

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:'
    }

最佳答案

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

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

关于grails - 使用@Secured闭包时如何获取 Controller 方法参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38753105/

相关文章:

grails - Geb + cucumber : Restart Browser Between Scenarios

grails - 戈尔姆 : hasMany of the same domain class

spring - 在grails应用程序中使用Spring Security限制页面 View

spring security oauth2 java config - 处理程序调度失败;嵌套异常是 java.lang.StackOverflowError

grails - 私有(private)方法在 Grails 2.5.1 中没有被 mock

java - Json 作为 Grails Controller 的参数

grails - 设置来自 Controller 的字段错误消息

java - 使用 GWT 获取/j_spring_security_check 的 HTTP 状态 404

pdf - grails无法使用渲染插件生成PDF

grails - spring-security-core Grails插件