Accessing my custom user object in jsp page, using spring 3 security

 

Questions


I have implemented UserDetailsService, it returns an instance of MyUser (which implements UserDetails)

public MyUser loadUserByUsername(String arg0)

Now I want to access my custom getters/fields on MyUser in my JSP pages, so far I got this:

${pageContext.request.userPrincipal.name}

But that only allows access to a Principal object. How can I access MyUser object?

 

 

————————————————-

Answer

its easy in the jsp page I added this :

<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
...
<sec:authentication property="principal.firstname" /> 

Where principal is actually an instance of MyUser, so “firstname” can be any of my custom getters and setters

java,spring,spring-mvc,spring-security

Facebook Comments

Post a comment