From 4749090fc09849ee7a71cea850e23e28349613ac Mon Sep 17 00:00:00 2001 From: niudehua <657563945@qq.com> Date: Tue, 9 Mar 2021 20:08:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E5=8C=BF=E5=90=8D?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=BC=9A=E8=A2=AB=E9=89=B4=E5=AE=9A=E4=B8=BA?= =?UTF-8?q?anonymousUser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security/core/util/SecurityFrameworkUtils.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/cn/iocoder/dashboard/framework/security/core/util/SecurityFrameworkUtils.java b/src/main/java/cn/iocoder/dashboard/framework/security/core/util/SecurityFrameworkUtils.java index b6c509b93..82405fff5 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/security/core/util/SecurityFrameworkUtils.java +++ b/src/main/java/cn/iocoder/dashboard/framework/security/core/util/SecurityFrameworkUtils.java @@ -20,13 +20,14 @@ import java.util.Set; */ public class SecurityFrameworkUtils { - private SecurityFrameworkUtils() {} + private SecurityFrameworkUtils() { + } /** * 从请求中,获得认证 Token * * @param request 请求 - * @param header 认证 Token 对应的 Header 名字 + * @param header 认证 Token 对应的 Header 名字 * @return 认证 Token */ public static String obtainAuthorization(HttpServletRequest request, String header) { @@ -56,7 +57,7 @@ public class SecurityFrameworkUtils { if (authentication == null) { return null; } - return (LoginUser) authentication.getPrincipal(); + return authentication.getPrincipal() instanceof LoginUser ? (LoginUser) authentication.getPrincipal() : null; } /** @@ -85,12 +86,12 @@ public class SecurityFrameworkUtils { * 设置当前用户 * * @param loginUser 登陆用户 - * @param request 请求 + * @param request 请求 */ public static void setLoginUser(LoginUser loginUser, HttpServletRequest request) { // 创建 UsernamePasswordAuthenticationToken 对象 UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken( - loginUser, null, null); + loginUser, null, null); authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); // 设置到上下文 SecurityContextHolder.getContext().setAuthentication(authenticationToken);