package com.codvision.auth.core.token;

import com.codvision.authcore.bean.SysUserBean;
import com.codvision.commoncore.common.ExpiryMap;

/**
 * 内存管理token
 *
 * @author lingee
 * @date 2023/11/22
 */
public class MemoryTokenManager implements ITokenManager {

    private static final ExpiryMap<String, SysUserBean> TOKEN_MAP = new ExpiryMap<>(true);

    @Override
    public void setTokenUser(String token, SysUserBean sysUser) {
        sysUser.setToken(token);
        sysUser.setPassword(null);
        TOKEN_MAP.put(token, sysUser, 86400000);
    }

    @Override
    public SysUserBean getTokenUser(String token) {
        return TOKEN_MAP.get(token);
    }

    @Override
    public void removeTokenUser(String token) {
        TOKEN_MAP.remove(token);
    }
}
