From 8058ca9e06b4d9b066ba843599ccdb3af3e4d98a Mon Sep 17 00:00:00 2001 From: smallchill Date: Mon, 24 Dec 2018 13:22:49 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/boot/ctrl/BladeController.java | 2 +- .../core/log/event/ApiLogListener.java | 2 +- .../core/log/event/BladeLogListener.java | 2 +- .../core/log/event/ErrorLogListener.java | 2 +- .../core/secure/utils/SecureUtil.java | 35 +++++++++++++++++++ 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/blade-core-boot/src/main/java/org/springblade/core/boot/ctrl/BladeController.java b/blade-core-boot/src/main/java/org/springblade/core/boot/ctrl/BladeController.java index e4db3c0..8d18015 100644 --- a/blade-core-boot/src/main/java/org/springblade/core/boot/ctrl/BladeController.java +++ b/blade-core-boot/src/main/java/org/springblade/core/boot/ctrl/BladeController.java @@ -67,7 +67,7 @@ public class BladeController { * @return */ public BladeUser getUser() { - return SecureUtil.getUser(request); + return SecureUtil.getUser(); } /** ============================ API_RESULT ================================================= */ diff --git a/blade-core-log/src/main/java/org/springblade/core/log/event/ApiLogListener.java b/blade-core-log/src/main/java/org/springblade/core/log/event/ApiLogListener.java index 46bc582..75639a4 100644 --- a/blade-core-log/src/main/java/org/springblade/core/log/event/ApiLogListener.java +++ b/blade-core-log/src/main/java/org/springblade/core/log/event/ApiLogListener.java @@ -65,7 +65,7 @@ public class ApiLogListener { logApi.setRequestUri(URLUtil.getPath(request.getRequestURI())); logApi.setMethod(request.getMethod()); logApi.setParams(WebUtil.getRequestParamString(request)); - logApi.setCreateBy(SecureUtil.getUser(request).getAccount()); + logApi.setCreateBy(SecureUtil.getUserAccount(request).getAccount()); logApi.setCreateTime(LocalDateTime.now()); logService.saveApiLog(logApi); } diff --git a/blade-core-log/src/main/java/org/springblade/core/log/event/BladeLogListener.java b/blade-core-log/src/main/java/org/springblade/core/log/event/BladeLogListener.java index dd565a7..abd648f 100644 --- a/blade-core-log/src/main/java/org/springblade/core/log/event/BladeLogListener.java +++ b/blade-core-log/src/main/java/org/springblade/core/log/event/BladeLogListener.java @@ -62,7 +62,7 @@ public class BladeLogListener { logBlade.setServerHost(serverInfo.getHostName()); logBlade.setServerIp(serverInfo.getIPWithPort()); logBlade.setEnv(bladeProperties.getEnv()); - logBlade.setCreateBy(SecureUtil.getUser(request).getAccount()); + logBlade.setCreateBy(SecureUtil.getUserAccount(request)); logBlade.setCreateTime(LocalDateTime.now()); logService.saveBladeLog(logBlade); } diff --git a/blade-core-log/src/main/java/org/springblade/core/log/event/ErrorLogListener.java b/blade-core-log/src/main/java/org/springblade/core/log/event/ErrorLogListener.java index 9b24aad..c49c436 100644 --- a/blade-core-log/src/main/java/org/springblade/core/log/event/ErrorLogListener.java +++ b/blade-core-log/src/main/java/org/springblade/core/log/event/ErrorLogListener.java @@ -60,7 +60,7 @@ public class ErrorLogListener { logError.setServerHost(serverInfo.getHostName()); logError.setServerIp(serverInfo.getIPWithPort()); logError.setEnv(bladeProperties.getEnv()); - logError.setCreateBy(SecureUtil.getUser(request).getAccount()); + logError.setCreateBy(SecureUtil.getUserAccount(request).getAccount()); logError.setCreateTime(LocalDateTime.now()); logService.saveErrorLog(logError); } diff --git a/blade-core-secure/src/main/java/org/springblade/core/secure/utils/SecureUtil.java b/blade-core-secure/src/main/java/org/springblade/core/secure/utils/SecureUtil.java index aec3e16..c2630ac 100644 --- a/blade-core-secure/src/main/java/org/springblade/core/secure/utils/SecureUtil.java +++ b/blade-core-secure/src/main/java/org/springblade/core/secure/utils/SecureUtil.java @@ -24,6 +24,7 @@ import org.springblade.core.tool.date.DateField; import org.springblade.core.tool.date.DateTime; import org.springblade.core.tool.date.DateUtil; import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.StringPool; import org.springblade.core.tool.utils.WebUtil; import javax.crypto.spec.SecretKeySpec; @@ -89,6 +90,40 @@ public class SecureUtil { return bladeUser; } + + + /** + * 获取用户id + * @return + */ + public static Integer getUserId() { + return (null == getUser()) ? -1 : getUser().getUserId(); + } + + /** + * 获取用户id + * @return + */ + public static Integer getUserId(HttpServletRequest request) { + return (null == getUser(request)) ? -1 : getUser().getUserId(); + } + + /** + * 获取用户账号 + * @return + */ + public static String getUserAccount() { + return (null == getUser()) ? StringPool.EMPTY : getUser().getAccount(); + } + + /** + * 获取用户账号 + * @return + */ + public static String getUserAccount(HttpServletRequest request) { + return (null == getUser(request)) ? StringPool.EMPTY : getUser().getAccount(); + } + /** * 获取Claims *