2017-10-04 9 views
1

私はapplication.yml上でこれを持っている:私が手に自分のアプリケーションでadminように私にログインすると春のセキュリティ - Grailsは3.2.2 - ERR_TOO_MANY_REDIRECTS

def loggedIn() { 
    User user = springSecurityService.currentUser 

    def roleDefault = Role.findByAuthority("ROLE_DEFAULT") 
    if(user.authorities.contains(roleDefault)) 
     redirect(controller: 'foo', action:'index') 

    def roleAdmin = Role.findByAuthority("ROLE_ADMIN") 
    if(user.authorities.contains(roleAdmin)) 
     redirect(view: 'index') 

} 

grails.plugin.springsecurity.successHandler.alwaysUseDefault = true 
grails.plugin.springsecurity.successHandler.defaultTargetUrl = '/l/loggedIn' 

そしてl/loggedInがどのように見えますERR_TOO_MANY_REDIRECTSエラーです。

これを修正する方法はありますか?


更新

@Secured(["ROLE_ADMIN", "ROLE_DEFAULT"]) 
class FooController { 

    def index() {} 
} 
+0

リダイレクト(uri: "/")を使用しているadminユーザー@AdeelAnsari –

答えて

1

redirectrenderはない、アカウントにviewを負いません。

可オプションは、あるactioncontrolleruriurlparamsfragment、および/またはドメインインスタンス。

だから、あなたはあなたのコントローラで、その後

def loggedIn() { 
    User user = springSecurityService.currentUser 

    def roleDefault = Role.findByAuthority("ROLE_DEFAULT") 
    if(user.authorities.contains(roleDefault)) 
     redirect(controller: 'foo', action:'index') 

    def roleAdmin = Role.findByAuthority("ROLE_ADMIN") 
    if(user.authorities.contains(roleAdmin)) 
     redirect(controller: 'foo', action:'adminIndex') 
} 

、のような何かを行うことができます利用できる適切な景色を眺めながら、両方actionsを定義します。

@Secured(["ROLE_ADMIN", "ROLE_DEFAULT"]) 
class FooController { 

    def index() {} 

    def adminIndex() {} 

} 

docsをお読みください。

+1

でのみ発生しますが、問題は解決しました。 –

+1

うれしかったです。 –

関連する問題