Файл Thyemelaf:
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
crossorigin="anonymous"></script>
<link rel="stylesheet" th:href="@{/css/home.css}">
</head>
<body>
<h1 class="text-center text-info">Home</h1>
<div sec:authorize="isAuthenticated()">
This content is only shown to authenticated users.
</div>
<div sec:authorize="hasRole('ADMIN')">
This content is only shown to users.
</div>
<div class="container">
<div class="row justify-content-center">
<span class=" text-danger mx-2">Logged user:</span>
<span sec:authentication="name" class=" text-primary"></span>
<span class=" text-danger mx-2"> Roles:</span>
<span sec:authentication="principal.authorities" class=" text-primary"></span>
</div>
<div class="row justify-content-center">
<div class="col-lg-12">
<table class="table table-border ">
<thead class="bg-dark text-light">
<tr>
<th>Username</th>
<th>Role</th>
<div sec:authorize="hasRole('ADMIN')">
<th>Delete Users</th>
</div>
</tr>
</thead>
<tbody>
<tr th:each="user: ${userList}" class="bg-light">
<td th:text="${user.username}"></td>
<td th:text="${user.role}"></td>
<div sec:authorize="hasRole('ADMIN')">
<td><button class="btn btn-outline-danger">Delete</button></td>
</div>
</tr>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="col align-self-end">
<form th:action="@{/logout}" class="form-group" method="POST">
<button type="submit" class="btn btn-primary">Logout</button>
</form>
</div>
</div>
</div>
</body>
</html>
Фрагмент из конфигурации безопасности:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/css/**", "/js/**", "/images/**").permitAll()
.antMatchers("/register").permitAll()
.anyRequest()
.authenticated()
.and()
.authorizeRequests()
.and()
.formLogin().loginPage("/login").defaultSuccessUrl("/", true).permitAll()
.and()
.logout()
.logoutSuccessUrl("/login").permitAll();
}
Это не работает:
<div sec:authorize="hasRole('ADMIN')">
<th>Delete Users</th>
</div>
Каждые другая вещь, например, se c: аутентификация и другие работают нормально, и только se c: authorize не работает Я думаю, что это связано с кодом SecurityConfig, но я не могу понять, какие изменения мне нужно внести работайте помогите пожалуйста.