Files
longdianningxing/nladmin-common/src/main/java/org/nl/utils/SecurityUtils.java
2022-09-21 10:15:52 +08:00

60 lines
1.4 KiB
Java

package org.nl.utils;
import cn.dev33.satoken.stp.StpUtil;
import lombok.extern.slf4j.Slf4j;
import org.nl.utils.dto.CurrentUser;
/**
* @author: lyd
* @description: 获取当前用户的信息 - 前提下在登录之后将数据存储到session
* @Date:
*/
@Slf4j
public class SecurityUtils {
/**
* 获取系统用户 - CurrentUser
*
* @return 系统用户
*/
public static Object getCurrentUser() {
CurrentUser user = null;
try {
user = (CurrentUser) StpUtil.getTokenSession().get("userInfo");
if (user.getUser() != null) {
return user.getUser();
}
}
catch (Exception e) {
return null;
}
return null;
}
/**
* 获取系统用户名称
*
* @return 系统用户名称
*/
public static String getCurrentUsername() {
CurrentUser currentUser = (CurrentUser) StpUtil.getTokenSession().get("userInfo");
if (currentUser.getUsername() != null) {
return currentUser.getUsername();
}
return "";
}
/**
* 获取系统用户Id
*
* @return 系统用户Id
*/
public static Long getCurrentUserId() {
CurrentUser currentUser = (CurrentUser) StpUtil.getTokenSession().get("userInfo");
if (currentUser.getId() != null) {
return currentUser.getId();
}
return 0L;
}
}