我已成功設置我的Grails應用程序來驗證用戶。如何使用@Secured閉包時獲得控制器方法參數?
我映射使用網址參數控制方法的參數,在我UrlMappings.groovy:
"/$source/owner/$ownerId/show"(controller:"myController", action: "show", method: "GET")
我如何得到我的@Secured關閉$源和值$ 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) {
...
}
我如何獲得這些價值?我在做什麼錯,在這裏?
我認爲,這一職位將提供一個解決方案,但鑑於那裏的答案並沒有爲我工作:
我使用下面的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:'
}
如果你簡單地執行'def owner = request.ownerId',會發生什麼?那也是空的? – Gregg
@Gregg謝謝你的回覆!但是這也返回null。 – RMorrisey
試試'println params'看看它們是否全部通過。如果是這樣,你可以從數組中找到值。 –