Grails: How do you retrieve the UserDetails object from a controller?
grails, spring-security
Solution
I'm using 2.0.4 and spring security plugin, it kind of looks like you are using the plugin?
If so try:
// Inject
def springSecurityService
// Action
def index() {
UserDetails currentUser = springSecurityService.principal
}
Problem
I'm using Grails 1.3.7. I have a custom `UserDetails` object that gets created in my `customUserDetailsService` during authentication. I assume that this custom `UserDetails` object is then stored in the session somewhere. However, I cannot find how to retrieve it. I thought that `SecurityContextHolder.getContext().getAuthentication().getDetails()` would do it, but that returns an object of type: `org.springframework.security.web.authentication.WebAuthenticationDetails`, and not my custom UserDetails.