package com.zsc.bill.framework.security;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.Objects;

/**
 * @author Yao
 */
public class SecurityUtil {

    public static UserDetailsImpl getUserInfo() {
        return getPrincipal();
    }

    private static UserDetailsImpl getPrincipal() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return Objects.nonNull(authentication) ? (UserDetailsImpl) authentication.getPrincipal() : null;
    }
}
