package com.simuwang.shiro.core.adapter;

import cn.hutool.core.collection.ListUtil;
import com.simuwang.shiro.core.ShiroUser;
import org.apache.shiro.crypto.hash.SimpleHash;

import java.util.List;

/**
 * @author wangzaijun
 * @date 2024/9/6 17:44
 * @description 认证与授权的用户信息适配器（访问数据库和缓存）
 */
public class SimpleLoginAuthAdapter implements LoginAuthAdapter {
    @Override
    public ShiroUser findUserByUsername(String username) {
        ShiroUser sysUser = new ShiroUser();
        sysUser.setUserId(0);
        sysUser.setUsername("admin");
        sysUser.setPassword(new SimpleHash("SHA-256", "123456", "1234567890abcdef", 1000).toHex());
        sysUser.setStatus(1);
        return sysUser;
    }

    @Override
    public List<String> findRoleByUserId(Integer userId) {
        return ListUtil.toList("ADMIN");
    }

    @Override
    public List<String> findPermissionsByUserId(Integer userId) {
        return ListUtil.toList("RS:ALL");
    }
}
