LoginSignup
2
2

More than 5 years have passed since last update.

[Grails3]のInterceptorでリダイレクトするには

Last updated at Posted at 2015-06-12

追記(2015/06/17)

こちらの現象は,Grails 3.0.2で解消されており、Interceptor内からredirect()を利用することができるようになったようです!!

課題

Grails3.0 では、FilterではなくInterceptorが利用されることになりましたが、Interceptor内でredirectするとエラーとなってしまうようです。

Interceptor内でリダイレクトできないと、Authの処理でいろいろとめんどくさいことになりそうなので、やり方を調べてみました。

方法

対応方法としては1つ見つけました。
* response.sendRedirectを実行する

// response.sendRedirectを利用する方法
class XXXInterceptor {

  boolean before() {
    // リダイレクトが必要かどうかをチェック
    if ( needRedirect() ) {    
        def url = grailsApplication.config.getProperty("myapp.redirect.url")
        response.sendRedirect(url)
    }
    true
  }

}
application.yaml
myapp:
    redirect:
        url: http://localhost:8080/

考察

sendRedirectでリダイレクト先のURLの取得は、コンフィグ(application.yml)から取得すべきでしょうね。

追記(2015/06/15)

application.yamlからリダイレクト先を取得するように変更

参考

[Grails]新しいInterceptorとアノテーションを利用してログイン機能を実装(仮)
http://qiita.com/saba1024/items/f4af87a1e4778f57b92a

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2