mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2025-01-19 11:40:05 +08:00
修复 匿名用户会被鉴定为anonymousUser
This commit is contained in:
parent
4749090fc0
commit
be250ca56d
@ -20,14 +20,13 @@ import java.util.Set;
|
|||||||
*/
|
*/
|
||||||
public class SecurityFrameworkUtils {
|
public class SecurityFrameworkUtils {
|
||||||
|
|
||||||
private SecurityFrameworkUtils() {
|
private SecurityFrameworkUtils() {}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从请求中,获得认证 Token
|
* 从请求中,获得认证 Token
|
||||||
*
|
*
|
||||||
* @param request 请求
|
* @param request 请求
|
||||||
* @param header 认证 Token 对应的 Header 名字
|
* @param header 认证 Token 对应的 Header 名字
|
||||||
* @return 认证 Token
|
* @return 认证 Token
|
||||||
*/
|
*/
|
||||||
public static String obtainAuthorization(HttpServletRequest request, String header) {
|
public static String obtainAuthorization(HttpServletRequest request, String header) {
|
||||||
@ -86,12 +85,12 @@ public class SecurityFrameworkUtils {
|
|||||||
* 设置当前用户
|
* 设置当前用户
|
||||||
*
|
*
|
||||||
* @param loginUser 登陆用户
|
* @param loginUser 登陆用户
|
||||||
* @param request 请求
|
* @param request 请求
|
||||||
*/
|
*/
|
||||||
public static void setLoginUser(LoginUser loginUser, HttpServletRequest request) {
|
public static void setLoginUser(LoginUser loginUser, HttpServletRequest request) {
|
||||||
// 创建 UsernamePasswordAuthenticationToken 对象
|
// 创建 UsernamePasswordAuthenticationToken 对象
|
||||||
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(
|
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(
|
||||||
loginUser, null, null);
|
loginUser, null, null);
|
||||||
authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
|
authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
|
||||||
// 设置到上下文
|
// 设置到上下文
|
||||||
SecurityContextHolder.getContext().setAuthentication(authenticationToken);
|
SecurityContextHolder.getContext().setAuthentication(authenticationToken);
|
||||||
|
Loading…
Reference in New Issue
Block a user