Reputation: 2402
In a previous application, we were able to access the session.user.PROPERTY
from our controllers which we were using annotation for the security. In a new application, we decided to use the RequestMap
for storing the rules. When checking for a value from the user domain class in the controller, we get an NullPointerException
error stating that session.user
is a null object.
In the previous application it was convenient to access session.user.WHATEVER
and have access to user info directly from the session without having to query the user info with the principal.id
.
Upvotes: 0
Views: 355
Reputation: 187499
If you're trying to retrieve the currently logged-in user, the easiest way to do this is to use the springSecurityService
bean, e.g.
class MyController {
def springSecurityService
def myAction() {
def currentUser = springSecurityService.currentUser
}
}
Upvotes: 1