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
1) MY CUSTOM USER CLASS with extra field mobile:
public class SiteUser extends User {
public SiteUser(String username, String password, Collection extends GrantedAuthority> authorities,
String mobile) {
super(username, password, true, true, true, true, authorities);
this.mobile = mobile;
}
private String mobile;
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
}
2) IN MY UserDetailsServiceImpl.java I POPULATED THIS CUSTOM SiteUser object.
public SiteUser loadUserByUsername(String username) {
UserInfoVO userInfoVO = userDAO.getUserInfo(username);
GrantedAuthority authority = new SimpleGrantedAuthority(userInfoVO.getRole());
SiteUser siteUser = new SiteUser(userInfoVO.getUsername(), userInfoVO.getPassword(),
Arrays.asList(authority), userInfoVO.getMobile());
return siteUser;
}
3) AND IN VIEW I AM ACCESSING IT AS:
< a href="#" th:text="${#httpServletRequest.userPrincipal.principal.mobile}">