grails / grails-spring-security-core

Grails Spring Security Core Plugin
Apache License 2.0
261 stars 223 forks source link

Using springSecurityService.getCurrentUserId() to grab currentUser's primary identifier? #1030

Open henryc-agr opened 1 month ago

henryc-agr commented 1 month ago

Issue description

Inside SpringSecurityService.groovy there is a getCurrentUserId() method that returns the id property from the principal. I see no reference to this method in the documentation.

Is this method the optimal way to fetch the currentUser's primary identifier of the applications User entity or should we always use the documented springSecurityService.getCurrentUser() and grab the identifier from this User instance?

The getCurrentUserId() has the benefit of not making an additional database call / transaction to fetch the entire user record (for cases where we just need the identifier).

My concern is that the getCurrentUserId() method is not referenced in any official documentation and therefore it may not be supported or included long term?

Thank you,

henryc-agr

codeconsole commented 3 weeks ago

if all you need is the user id, getCurrentUserId() would be the preferred way.