package com.sunyard.chsm.auth;

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

import static com.sunyard.chsm.constant.SecurityConstant.ATTRIBUTE_APP_USER;

/**
 * @author liulu
 * @since 2024/12/6
 */
public class UserContext {


    public static AppUser getCurrentUser() {
        RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
        return (AppUser) requestAttributes.getAttribute(ATTRIBUTE_APP_USER, RequestAttributes.SCOPE_REQUEST);
    }

    public static Long getCurrentAppId() {
        return getCurrentUser().getAppId();
    }


}
