2014-02-17 55 views
0

我學習的Spring Security的來龍去脈......它已經慢得要命......Grails的Spring Security的用戶名全球

現在我想從索引訪問當前登錄的用戶名.gsp頁面。我有代碼從控制器工作,但我不能得到任何其他網頁的代碼。我有一種感覺,我錯過了關於用戶對象的關鍵。

這是我用我的控制器:

class BookController { 

    def springSecurityService 

    static allowedMethods = [save: "POST", update: "POST", delete: "POST"] 


    def index() { 
     redirect(action: "list", params: params) 
    } 

    def list(Integer max) { 
     def userDetails = springSecurityService.principal 
     params.max = Math.min(max ?: 10, 100) 
     [bookInstanceList: Book.list(params), bookInstanceTotal: Book.count(), muds: userDetails] 
    } 
... 
... etc 
... 

然後在視圖(GSP),我可以簡單地這樣做:

Username: ${muds.getUsername() } 

我會怎麼做這index.gsp中?

回答

4

您最好使用插件附帶的內置標籤庫。 documentation顯示所有各種標籤,其中之一用於獲取當前登錄用戶的屬性。舉例:

<sec:loggedInUserInfo field="username"/> 
+0

我需要額外的taglib插件嗎?我得到這個錯誤:處理GroovyPageView時出錯:未知的JSP標記sec:loggedInUserInfo – Bean

+0

不是。你使用的是什麼版本的spring security core插件? –

+0

spring-security-core:1.2.7.3 – Bean

0

您是否在$ {muds.getUsername()}中遇到任何錯誤?嘗試只使用$ {muds}或更好地檢查$ {muds}的類

相關問題