Skip to content
Browse files

use get() if the UserDetails is a GrailsUser and the id is available,…

… otherwise use username
  • Loading branch information...
1 parent 790bf1e commit b7728c864e8e3a10f4a38312a4cf5e8d9bbf251e @burtbeckwith burtbeckwith committed
Showing with 12 additions and 2 deletions.
  1. +12 −2 grails-app/services/grails/plugin/springsecurity/SpringSecurityService.groovy
View
14 grails-app/services/grails/plugin/springsecurity/SpringSecurityService.groovy
@@ -14,11 +14,14 @@
*/
package grails.plugin.springsecurity
+import grails.plugin.springsecurity.userdetails.GrailsUser
+
import javax.servlet.http.HttpServletRequest
import org.springframework.security.core.Authentication
import org.springframework.security.core.context.SecurityContextHolder as SCH
import org.springframework.transaction.annotation.Transactional
+import org.springframework.util.Assert
/**
* Utility methods.
@@ -74,8 +77,15 @@ class SpringSecurityService {
}
String className = SpringSecurityUtils.securityConfig.userLookup.userDomainClassName
- String usernamePropName = SpringSecurityUtils.securityConfig.userLookup.usernamePropertyName
- grailsApplication.getClassForName(className).findWhere((usernamePropName): principal.username)
+ def User = grailsApplication.getClassForName(className)
+
+ if (principal instanceof GrailsUser) {
+ User.get principal.id
+ }
+ else {
+ String usernamePropName = SpringSecurityUtils.securityConfig.userLookup.usernamePropertyName
+ User.findWhere((usernamePropName): principal.username)
+ }
}
/**

0 comments on commit b7728c8

Please sign in to comment.
Something went wrong with that request. Please try again.