Springブート1.5.2とThymeleaf 2.1を使用して、HTMLページにコードを追加して、ユーザーの役割を特定しようとしています。ThymeleafのSpringセキュリティ式
しかし、これらのステートメントのすべてが間違っているtrueと評価:
<div sec:authorize="hasAuthority('ADMIN')" > Has Authority ADMIN </div>
<div sec:authorize="hasAuthority('USER')" > Has Authority USER </div>
<div sec:authorize="hasRole('ROLE_ADMIN')">Has Role ROLE_ADMIN</div>
<div sec:authorize="hasRole('ROLE_USER')">Has Role ROLE_USER</div>
<div sec:authorize="hasRole('ADMIN')">Has Role ADMIN</div>
<div sec:authorize="hasRole('USER')">Has Role USER</div>
User.java
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
private Set<Role> roles;
Role.java
@Entity
@Table(name = "role")
public class Role {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private int id;
@Column(name = "role")
private String role;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
}