2016-08-03 7 views
0

Grails 애플리케이션을 성공적으로 설정하여 사용자를 인증했습니다.@ Secure 클로저를 사용할 때 컨트롤러 메서드 매개 변수를 얻으려면 어떻게해야합니까?

내 UrlMappings.groovy에서 URL의 PARAMS를 사용하여 컨트롤러 메소드의 인수를,지도 :

"/$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 2.5.1 
    compile ":spring-security-core:2.0-RC5" 
    compile ":spring-security-rest:1.5.3", { 
     excludes 'com.fasterxml.jackson.core:jackson-databind:' 
    } 
: 나는 다음과 Grails의와 플러그인 버전을 사용하고

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

+0

단순히 'def owner = request.ownerId'를하면 어떻게됩니까? 그것도 null입니까? – Gregg

+0

@Gregg 귀하의 회신에 감사드립니다! 그러나이 또한 null을 반환합니다. – RMorrisey

+0

그냥'println params'를 시도해보세요. 그럴 경우 배열 값에서 찾을 수 있습니다. –

답변

1

개요 :

사용 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 
}) 

돌아 truefalse은 액세스를 거부, 액세스 할 수 있도록 문서에 간단한 작성자 및 예제가있다.

+0

request.getParameter()도 null을 반환합니다. URL 매개 변수는 요청 매개 변수로 맵핑되지 않습니다. – RMorrisey