【发布时间】:2021-10-11 13:35:00
【问题描述】:
我在显示未显示经过身份验证的用户全名时遇到问题。
我看不到sec:authentication 中定义的任何值。
即使我定义了 sprng 安全性并将其嵌入到支持 thymeleaf 的 html 代码中,该代码也无法正常工作。
我该如何解决?
这是我的 CustomerUserDetails 类
public class CustomerUserDetails implements UserDetails{
public String getFullName() {
LOGGER.info("CustomerUserDetails | getFullName: " + customer.getFirstName() + " " + customer.getLastName());
return customer.getFirstName() + " " + customer.getLastName();
}
}
这是下面显示的依赖项。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
下面是我的代码。
我只显示下面显示的这段代码来显示经过身份验证的用户全名
<a class="nav-link" th:href="@{/account_details}" ><b>[[${#request.userPrincipal.principal.fullName}]]</b></a>
为什么 sec:authentication 不起作用?
我该如何解决这个问题?
【问题讨论】:
标签: spring-boot spring-security thymeleaf