先生们,专家,告诉我,pliz:Spring Boot / Security 项目,当添加到 html/Thymeleaf sec:authentication=”principal.authorities”浏览器发出 500 和
Error retrieving value for property "”principal.authorities”" of authentication object of class org.springframework.security.authentication.UsernamePasswordAuthenticationToken
Invalid property '”principal' of bean class [org.springframework.security.authentication.UsernamePasswordAuthenticationToken]: Bean property '”principal' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
同时,authentication.getAuthorities() 在控制台中显示值,一切都在调试中到位,如果您注释掉有问题的行,则访问限制适用于该按钮:
<div sec:authorize="hasAuthority('ADMIN')">
<form th:action="@{/bankdemo/accounts/show/{phone}(phone=${account.phone})}"
th:method="delete">
<input type="hidden" th:name="id" th:value="${bill.id}"/>
<button class="btn btn-danger"
onclick="if (!(confirm('Are you sure you want to delete this bill?')))
return false">
Erase</button>
</form>
</div>
场地:
@ElementCollection(targetClass = Role.class)
@CollectionTable(name="roles", joinColumns = @JoinColumn(name="account_id"))
@Enumerated(EnumType.STRING)
private Set<Role> roles;
吸气剂:
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return roles;
}
埃南:
public enum Role implements GrantedAuthority{
ADMIN, CLIENT;
@Override
public String getAuthority() {
return name();
}
}
怎么了?
复制粘贴错误!无法识别带有错误字体“principal.authorities”的引号!!!