D
D
DeNissss44442021-05-06 13:24:23
Java
DeNissss4444, 2021-05-06 13:24:23

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

2 answer(s)
O
Orkhan, 2021-05-06
@DeNissss4444

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>

I
Ivan Demianov, 2021-05-06
@Vanushka1102

Make a validation and then innerhtml

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question