I am using Spring MVC and Spring Security version 3.0.6.RELEASE. What is the easiest way to get the user name in my JSP? Or even just whether or not the user is logged in? I
I think
will not always work because type returned by Authentication.getPrincipal() is Object, ie: it could be a UserDetail (for which the above will work), a String or anything else.
For purpose of displaying username in JSP page what I find more reliable is using ${pageContext.request.userPrincipal.name}
.
This uses java.security.Principal.getName() which returns String.