package com.changhu.support.satoken;

import cn.dev33.satoken.dao.SaTokenDaoRedis;
import cn.dev33.satoken.jwt.StpLogicJwtForSimple;
import cn.dev33.satoken.stp.StpLogic;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @author 20252
 * @createTime 2024/7/23 下午4:21
 * @desc SaTokenConfig...
 */
@Component
public class SaTokenConfig {

    @Autowired
    private SaTokenDaoRedis saTokenDaoRedis;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @PostConstruct
    public void setConfig() {
        this.saTokenDaoRedis.stringRedisTemplate = this.stringRedisTemplate;
        this.saTokenDaoRedis.objectRedisTemplate = this.redisTemplate;
    }

    /**
     * Sa-Token 整合 jwt (Simple 简单模式)
     */
    @Bean
    public StpLogic getStpLogicJwt() {
        return new StpLogicJwtForSimple();
    }
}
