2011-12-07 82 views
0

我正在構建簡單的Grails應用程序。爲了安全起見,我使用了Spring Security插件和Spring Security UI。 我想有三類用戶:使用Grails Spring Security插件進行無限重定向

  • 標準用戶(客戶端),
  • 支持用戶
  • 管理用戶

客戶端將登錄並提出一些要求,支持將得到這些請求和迴應。管理員將負責管理用戶權限和角色以及其他一些內容。

所以基本上我有三個作用:

  • ROLE_USER
  • ROLE_SUPPORT
  • ROLE_ADMIN

當他一個用戶登錄/她是根據用戶角色不同的頁面上的重定向。我按照 link的建議做了這個。

This Works。但有時我得到以下錯誤:

Firefox has detected that the server is redirecting the request for this address in a way that will never complete. This problem can sometimes be caused by disabling or refusing to accept cookies.

這是我UrlMappings.groovy:

class UrlMappings { 

    static mappings = { 
     "/$controller/$action?/$id?"{ 
      constraints { 
       // apply constraints here 

      } 

     } 

     "/"(controller:'login', action:'auth') 
     "500"(view:'/error') 

    } 
} 

什麼是正確的形式給出了呢?我應該爲每個角色製作不同的控制器,還是應該製作一個RequestController(大多數工作都是通過請求域類完成的),例如爲每個角色指定不同的操作 - 例如userList,supportList,adminList等。

+0

@Antoine感謝您的編輯。現在好多了。 – drago

+0

當你有時說,到底什麼時候?我的意思是你可以在某些情況下重現它嗎?那些情況是什麼? – omarello

+0

@omarello它正常工作,但當我做了一些小的改變,它只是進入這個循環。我不記得有什麼確切的變化。因此,直到我進一步研究它時,我將使用請求控制器的索引操作進行重定向。 – drago

回答

2

我有類似的需求與我的Grails應用程序稍有不同的角色。我做的是以下幾點:在UrlMappings.groovy

"/"(controller: "home") 

然後在我的HomeController

(這不正是我的代碼,但你的想法)

def user 

def index = { 
    user = springSecurityService?.getAuthentication()?.details 

    def role = user.getRole() 
    if ('admin'.equals(role)) { 
     redirect(view:'admin') 
    } else if ('support'.equals(role)) { 
     redirect(view:'support') 
    } else { 
     redirect(view:'home') 
    } 
} 

我的猜測是你的當登錄頁面出現錯誤時會發生重定向問題。我會檢查你是如何處理異常,並確保它們不會嘗試重定向到導致錯誤的登錄頁面。

相關問題