package com.jiayue.ssi.util;

import com.jiayue.ssi.entity.SysUser;
import org.springframework.security.core.context.SecurityContextHolder;

/**
* SecurityContext获取
*
* @author xsl
* @since 2023/03/14
*/
public class SecurityContextUtil {
    /**
     * 获取当前系统用户
     * @return
     */
    public static SysUser getSysUser(){
        if (SecurityContextHolder.getContext().getAuthentication()==null){
            SysUser sysUser = new SysUser();
            sysUser.setUsername("system");
            return sysUser;
        }
        return (SysUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    }
}
