From 86dba4c9631c1c7d2f11a2fdd30427eeb5524105 Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Wed, 27 May 2020 18:04:53 +0800
Subject: [PATCH] 20200527 代码提交
---
src/main/java/com/xcong/excoin/common/LoginUserUtils.java | 28 +++++++++++++++++++++++++++-
1 files changed, 27 insertions(+), 1 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/common/LoginUserUtils.java b/src/main/java/com/xcong/excoin/common/LoginUserUtils.java
index 7840a12..64c0aa2 100644
--- a/src/main/java/com/xcong/excoin/common/LoginUserUtils.java
+++ b/src/main/java/com/xcong/excoin/common/LoginUserUtils.java
@@ -1,6 +1,8 @@
package com.xcong.excoin.common;
+import com.xcong.excoin.common.exception.GlobalException;
import com.xcong.excoin.modules.member.entity.MemberEntity;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.context.SecurityContextHolder;
/**
@@ -9,9 +11,33 @@
* @author wzy
* @date 2020-05-14
**/
+@Slf4j
public class LoginUserUtils {
+ private static final String ANON = "anonymousUser";
+
public static MemberEntity getAppLoginUser() {
- return (MemberEntity) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
+ if (SecurityContextHolder.getContext().getAuthentication().getPrincipal().equals(ANON)) {
+ throw new GlobalException("无法获取登陆信息");
+ } else {
+ return (MemberEntity) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
+ }
+ }
+
+ public static String getAppLoginUserToken() {
+ return (String) SecurityContextHolder.getContext().getAuthentication().getCredentials();
+ }
+
+ /**
+ * mybatis 拦截器专用
+ *
+ * @return MemberEntity
+ */
+ public static MemberEntity getUser() {
+ if (SecurityContextHolder.getContext().getAuthentication().getPrincipal().equals(ANON)) {
+ return null;
+ } else {
+ return (MemberEntity) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
+ }
}
}
--
Gitblit v1.9.1