Get authenticated user entity Spring MVC

2019-07-31 15:18发布

I use Spring MVC + Spring Security in my project. And I need get user entity after user authenticates and across his session. For example, in order to print his name on my welcome page like: Welcome, ${user.firstName}! or get his list of companies on another page:

<c:forEach items="${user.userCompanies}" var="company">
    ${company.name}
</c:forEach>

etc. Could you help me to solve this issue?

1条回答
Lonely孤独者°
2楼-- · 2019-07-31 15:52

Check the taglib provided by Spring Security.
To get the username, use:

<sec:authentication property="principal.username" />
查看更多
登录 后发表回答