package com.amms.security;

import com.amms.domain.SysUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * SpringSecurity工具类
 */
public class SecurityUtils {

    /**
     * 获取当前登录用户
     * @return
     */
    public static SysUser getCurrentUser() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        SysUser sysUser = null;
        if (!authentication.getPrincipal().equals("anonymousUser")) {
            sysUser = (SysUser) authentication.getPrincipal();
        }

        return sysUser;
    }

}
