package com.jeeww.utils;

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

import com.jeeww.security.CustomerUserDetails;

public class UserDetailUtils {
    public static CustomerUserDetails getUserDetail() throws Exception {
        Object user = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (user.equals("anonymousUser")) {
            throw new Exception("请登录!");
        }
        CustomerUserDetails userDetail = (CustomerUserDetails) user;
        return userDetail;
    }

    public static void checkUserIsLogin() throws Exception {
        Object user = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (user.equals("anonymousUser")) {
            throw new Exception("请登录!");
        }
    }
}
