package cn.reghao.autodop.dmaster.rbac;


import cn.reghao.autodop.dmaster.rbac.model.po.User;

/**
 * 获取当前请求的用户
 *
 * @author reghao
 * @date 2020-06-23 19:20:56
 */
public class UserContext implements AutoCloseable {
    static final ThreadLocal<User> CURRENT = new ThreadLocal<>();

    public UserContext(User user) {
        CURRENT.set(user);
    }

    public static User currentUser() {
        return CURRENT.get();
    }

    @Override
    public void close() {
        CURRENT.remove();
    }
}
