From 9a82d627a6cf5439ec9018239ace1cdc7fbf72f5 Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Mon, 08 Jun 2020 15:50:12 +0800
Subject: [PATCH] modfiy
---
src/main/java/com/xcong/excoin/common/LoginUserUtils.java | 22 ++++++++++++++++++++++
1 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/common/LoginUserUtils.java b/src/main/java/com/xcong/excoin/common/LoginUserUtils.java
index dbdd9d2..0c24019 100644
--- a/src/main/java/com/xcong/excoin/common/LoginUserUtils.java
+++ b/src/main/java/com/xcong/excoin/common/LoginUserUtils.java
@@ -1,5 +1,6 @@
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;
@@ -17,6 +18,27 @@
public static MemberEntity getAppLoginUser() {
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() == null) {
+ return null;
+ }
+
+ if (SecurityContextHolder.getContext().getAuthentication().getPrincipal().equals(ANON)) {
return null;
} else {
return (MemberEntity) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
--
Gitblit v1.9.1