Konstantin Shaposhnikov wrote:
I would recommend you to write simple bean with getter method that
returns current logged in user from SecurityContext:

class CurrentUser {
  Object getPrincipal() {
    SecurityContext ctx = SecurityContextHolder.getContext();
    if (ctx == null)
      return null;
    return ctx.getAuthentication().getPrincipal();
  }
}
SecurityContextHolder.getContext() is guaranteed to never return null, so you can skip that check. Also consider if the getPrincipal() returns a UserDetails object, as in that case you'll probably want to cast the getPrincipal() Object to UserDetails and use one of its getters instead (eg getUsername()).

Cheers
Ben


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Home: http://acegisecurity.org
Acegisecurity-developer mailing list
Acegisecurity-developer@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/acegisecurity-developer

Reply via email to