Answer the question
In order to leave comments, you need to log in
How to hide the Admin field from the eyes of a regular user?
I have a site on Spring. On the main page there is a link to the page for the admin. This page, respectively, can only be viewed by the admin from an ordinary user will knock out an error, but I understand that this should not be so. For good, only the admin should see the link to this page, the average user should not know about it. Tell me how to implement this in Spring, Java?
Answer the question
In order to leave comments, you need to log in
Good afternoon!
I will assume that you have connected Spring Security to your application and you have roles already defined. For example, user & admin.
Now, in order to check the role or privilege of the user in the template engine (thymeleaf), you need to connect either "thymeleaf extras spring security"
https://github.com/thymeleaf/thymeleaf-extras-spri...
Well, further on the link above there is documentation, we read it.
For example,
<div sec:authorize="hasRole('ROLE_ADMIN')">
This will only be displayed if authenticated user has role ROLE_ADMIN.
</div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question