我有一個基本的Grails 2應用程序,我與SpringSecurityCore插件一起安裝。這似乎工作正常。但是,當我嘗試通過擴展類向我的User.groovy文件添加其他屬性時,似乎無法在控制器中引用這些屬性。Grails SpringSecurity用戶對象
爲了更好地說明這個問題,請看看我的基本類,它擴展了User.groovy:
UserInfo.groovy:
class UserInfo extends User {
String firstname
String lastname
}
在我的頁面,在這裏我想引用當前用戶的名字,我只是寫一個方法如下:
def index() {
def uname = springSecurityService.currentUser.username
def firstname = springSecurityService.currentUser.firstname
render uname
}
這工作正常進行渲染的用戶名,而我認爲,這是因爲用戶名參照的文CED在基座User.groovy文件:
class User {
transient springSecurityService
String username
String password
然而,上述「DEF指數()」當我嘗試定義姓名作爲springSecurityService.currentUser.firstname的一部分方法失敗。 。
如果我注入額外的屬性到基User.groovy類的話,我可以通過springSecurityService.currentUser的方式引用它們[屬性]
爲了說明這一點:
class User {
transient springSecurityService
String username
String password
String firstname
...
我再能夠在前面提到的索引方法中引用我的用戶的firstname屬性。
是否有可能引用我的用戶的擴展屬性而不在基類User類中注入值?我的目標是儘可能保持User類的清潔,同時仍然可以調用UserInfo.groovy文件中引用的值。
預先感謝您的時間。