2
我想創建一個領域類的新實例與一個字段女巫將是當前登錄用戶的用戶名。我使用Spring Security & Spring Security UI。請給我一些代碼示例。如何在域類中保存當前登錄的用戶名?
我想創建一個領域類的新實例與一個字段女巫將是當前登錄用戶的用戶名。我使用Spring Security & Spring Security UI。請給我一些代碼示例。如何在域類中保存當前登錄的用戶名?
要訪問當前登錄的用戶,可以在控制器中使用依賴項注入來訪問springSecurityService,並從那裏獲取當前登錄用戶的用戶名。
def springSecurityService // will be injected by DI
... in controller method,
def currentUsername = new MyDomainClassWithUsername(springSecurityService.currentUser.username)
currentUsername.save()
這是我的錯誤:錯誤500:執行控制器[com.test.IncidentController]引起的異常動作[創建]:沒有這樣的特性:用戶名類:org.springframework.security.authentication。 RememberMeAuthenticationToken – drago
我試圖獲得Spring Security User類的用戶名。 – drago
嘗試:springSecurityService.getCurrentUser()。用戶名 – socha23