| | |
| | | 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; |
| | |
| | | |
| | | 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(); |