我已经成功设置了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/