As previous user has answer, spring security support the getUserPrincipal and isUserInRole. Here is how spring security does it.
When you configure spring, it can load the following filters:
http://static.springframework.org/spring-security/site/reference/html/ns-config.html#filter-stack
As part of the standard filter configuration the SecurityContextHolderAwareRequestFilter
filter is loaded.
Examining the filter @ https://fisheye.springsource.org/browse/spring-security/tags/spring-security-parent-2.0.4/core/src/main/java/org/springframework/security/wrapper/SecurityContextHolderAwareRequestFilter.java?r=2514
You can see it wraps and changes the HttpServletRequest
object to the SecurityContextHolderAwareRequestWrapper
class which extends HttpServletRequestWrapper
which implements HttpServletRequest
and feed it back to the standard Servlet Filter doFilter chain. Since spring security filter should be configured as the first filter, all subsequent classes will see the SecurityContextHolderAwareRequestWrapper
instead. This includes JSP pages or Servlets behind this filter.
When you make a call to isUserInRole
or getUserPrincipal
from the JSP page, Servlet or any framework behind this filter, it is calling the HttpServletRequest
implementation from Spring Security.