I have a basic Grails 2 application which I setup along with the SpringSecurityCore plugin. This seems to be working fine. However, when I try to add additional properties to my User.groovy file by way of an extended class, I cannot seem to reference those properties in my controllers.
To better illustrate this problem, please take a look at my basic class which extends the User.groovy:
UserInfo.groovy:
class UserInfo extends User {
String firstname
String lastname
}
On my page where I want to reference the current user's firstname, I am simply writing a method as follows:
def index() {
def uname = springSecurityService.currentUser.username
def firstname = springSecurityService.currentUser.firstname
render uname
}
This works fine for rendering the username, and I believe that this is because the username is referenced in the base User.groovy file:
class User {
transient springSecurityService
String username
String password
However, the above "def index()" method fails when I try to define the firstname as part of the springSecurityService.currentUser.firstname.
If I inject extra properties into the base User.groovy class, then I can reference them by way of springSecurityService.currentUser.[property]
To illustrate this:
class User {
transient springSecurityService
String username
String password
String firstname
...
I am then able to reference the firstname property of my user in the aforementioned index method.
Is it possible to reference the extended properties of my User without injecting values in the base User class? My goal here is to try and keep the User class as clean as possible while still being able to call upon the values referenced in the UserInfo.groovy file.
Thank you in advance for your time.