How to generate content based on spring-security user rights
-
27-09-2019 - |
Question
I want to generate some html content based on the user rights of a user who logged in with spring-security. I can't find much about this subject on the internet so far and i'm wondering what would be a good way to implement this.
So far i was thinking about making a custom tag, attach it to a controller who links to a class that can generate, for example, the menu. I'm just not sure how get the user roles/rights of the user from spring-security.
Solution
How about something like this:
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %> ... <body> Shared content for all roles. <sec:authorize access="hasRole('roleName1')"> content for roleName1 </sec:authorize> <sec:authorize access="hasRole('roleName2')"> content for roleName2 </sec:authorize> More shared content for all roles. </body>
OTHER TIPS
Check the spring security tags to create dynamic content based on user roles. Spring Security Taglibs reference.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow