- Добавил возможность назначения ролей пользователям.

- Добавил контроллер для управления пользователями и запрет доступа к нему пользователям без роли ADMIN.

https://www.youtube.com/watch?v=6dteOGWy4uk&list=PLU2ftbIeotGpAYRP9Iv2KLIwK36-o_qYk&index=9

Использовал аннотацию @EnableMethodSecurity вместо deprecated  @EnableGlobalMethodSecurity
This commit is contained in:
Leonid
2025-02-10 12:17:59 +03:00
parent 8d7cbcc165
commit 8d4c5e1b3a
6 changed files with 104 additions and 6 deletions

View File

@@ -1,5 +1,7 @@
<#import "parts/common.ftl" as com>
<@com.page>
<div>Hello there</div>
<a href="/main">Main page</a>
<div>Hello there</div>
<a href="/main">Main page</a>
<br>
<a href="/users">Users page</a>
</@com.page>

View File

@@ -3,6 +3,7 @@
<@com.page>
<div>
<@l.logout />
<span> <a href="/users">Users page</a> </span>
</div>
<div>
@@ -33,4 +34,5 @@
<#else>
No messages found
</#list>
<br>
</@com.page>

View File

@@ -0,0 +1,14 @@
<#import "parts/common.ftl" as com>
<@com.page>
<form action="/users" method="post">
<input type="text" name="username" value="${user.username}">
<#list roles as role>
<div>
<label><input type="checkbox" name="${role}" ${user.roles?seq_contains(role)?string("checked", "")}>${role}</label>
</div>
</#list>
<input type="hidden" value="${user.id}" name="userId">
<input type="hidden" value="${_csrf.token}" name="_csrf">
<button type="submit">Save</button>
</form>
</@com.page>

View File

@@ -0,0 +1,23 @@
<#import "parts/common.ftl" as com>
<@com.page>
<div>Users</div>
<table>
<thead>
<tr>
<th>Name</th>
<th>Role</th>
<th></th>
</tr>
</thead>
<tbody>
<#list users as user>
<tr>
<td>${user.username}</td>
<td><#list user.roles as role>${role}<#sep>, </#list></td>
<td><a href="/users/${user.id}">edit</a></td>
</tr>
</#list>
</tbody>
</table>
<a href="/main">Main page</a>
</@com.page>