package com.dji.sample.common.util;

import com.dji.sample.common.model.CustomClaim;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

import static com.dji.sample.component.AuthInterceptor.TOKEN_CLAIM;
/**
 * @author hqjiang
 * @version 1.0
 * @date 2024/6/26
 */
public class UserRequest {
    public static CustomClaim getCurrentUser() {
        if(RequestContextHolder.getRequestAttributes() == null) {
            return null;
        }
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        if(request == null) {
            return null;
        }
        CustomClaim customClaim = (CustomClaim)request.getAttribute(TOKEN_CLAIM);
        return customClaim;
    }
}
