♻️ Refactoring code. close #I7PVTQ 登录日志的创建人不对

This commit is contained in:
lbw committed 2023-08-02 12:54:51 +08:00
1 parent 812ed9d57a
commit c37b60e9dd
1 file changed
+7 -4
@@ -3,8 +3,10 @@ package com.pig4cloud.pigx.common.data.mybatis;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
import com.pig4cloud.pigx.common.security.util.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.util.ClassUtils;
@@ -77,11 +79,12 @@ public class MybatisPlusMetaObjectHandler implements MetaObjectHandler {
* @return 当前用户名
*/
private String getUserName() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (Optional.ofNullable(authentication).isPresent()) {
return authentication.getName();
Authentication authentication = SecurityUtils.getAuthentication();
// 匿名接口直接返回
if (authentication instanceof AnonymousAuthenticationToken) {
return null;
}
return null;
return authentication.getName();
}
}