My app only allows access if the current user is a specific type, this also means the role they have can log into other applications and then access certain parts of my app with specific roles, for example, my web app is configured that
<security-role>
<role-name>teamb</role-name>
</security-role>
Now what I need is to be able access the details regarding this role in my app, ie.e user name
how can I do this in my Spring MVC app?
First of all, include the corresponding tag library in your pages (I’ll make an example using JSP)
Then you just have to use those tags to query for permissions and of course, the data.
To see if an user has enough privileges for something:
If the user has enough privileges, the link to
page.htmwill be rendered.To get the username use
${SPRING_SECURITY_LAST_USERNAME}. Here’s a logout link as an example:Edit
To query the currently authenticated user you can try different approaches:
or
Just remember to check if
authenticationis not null before invoking thegetNameorgetPrincipalmethods.