2016-08-03 5 views
0

Grailsアプリケーションを設定してユーザを認証することに成功しました。@ Secure Closureを使用するときにコントローラメソッドのパラメータを取得するにはどうすればよいですか?

私は私の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) { 
    ... 
} 

は、どのように私は、これらの値を得るのですか?私は何を間違えているのですか?

私はこのポストは解決策を提供すると思ったが、そこに与えられた答えは私のために動作しませんでした:

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

'def owner = request.ownerId'を実行するとどうなりますか?それもヌルですか? – 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は、アクセスを拒否するために、アクセスを許可するようにドキュメントでの簡単なWRITEUPと例があります。

+0

request.getParameter()もnullを返します。 URLパラメーターは要求パラメーターとしてマップされていません。 – RMorrisey

関連する問題