package com.izouma.jiashanxia.utils;

import com.izouma.jiashanxia.domain.User;
import com.izouma.jiashanxia.security.JwtUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class SecurityUtils {
    public static User getAuthenticatedUser() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        User user = null;
        if (authentication != null && authentication.getPrincipal() instanceof JwtUser) {
            user = ((JwtUser) authentication.getPrincipal()).getUser();
        }
        return user;
    }
}
