簡體   English   中英

全球范圍內使用Grails Spring Security用戶名

[英]Grails Spring Security Username globally

我正在學習Spring Security的來龍去脈...進展緩慢...

現在,我正在嘗試從index.gsp頁面訪問當前登錄的用戶用戶名。 我有可以從Controllers正常工作的代碼,但是我無法正確獲取任何其他頁面的代碼。 我感覺我缺少關於User對象的關鍵信息。

這是我用於控制器的內容:

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
...

然后,在View(gsp)中,我可以簡單地執行以下操作:

Username: ${muds.getUsername() }

我將如何在index.gsp中做到這一點?

您最好使用插件隨附的內置標記庫。 文檔顯示了所有各種標簽,其中之一是用於獲取當前登錄用戶的屬性。 舉個例子:

<sec:loggedInUserInfo field="username"/>

$ {muds.getUsername()}是否出現任何錯誤? 嘗試僅使用$ {muds}或更好地檢查$ {muds}的類別

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM