package com.zhitan.common.config.keycloak;
|
|
import com.zhitan.common.core.redis.RedisCache;
|
import lombok.AllArgsConstructor;
|
import me.zhyd.oauth.cache.AuthStateCache;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import java.time.Duration;
|
import java.util.concurrent.TimeUnit;
|
|
/**
|
* 授权状态缓存
|
*/
|
@AllArgsConstructor
|
@Component
|
public class AuthRedisStateCache implements AuthStateCache {
|
|
@Autowired
|
private final RedisCache redisCache;
|
|
/**
|
* 存入缓存
|
*
|
* @param key 缓存key
|
* @param value 缓存内容
|
*/
|
@Override
|
public void cache(String key, String value) {
|
// 授权超时时间 默认三分钟
|
redisCache.setCacheObject("social_auth_codes:" + key, value, 3, TimeUnit.MINUTES);
|
}
|
|
@Override
|
public void cache(String s, String s1, long l) {
|
|
}
|
|
|
|
/**
|
* 获取缓存内容
|
*
|
* @param key 缓存key
|
* @return 缓存内容
|
*/
|
@Override
|
public String get(String key) {
|
return redisCache.getCacheObject("social_auth_codes:" + key);
|
}
|
|
/**
|
* 是否存在key,如果对应key的value值已过期,也返回false
|
*
|
* @param key 缓存key
|
* @return true:存在key,并且value没过期;false:key不存在或者已过期
|
*/
|
@Override
|
public boolean containsKey(String key) {
|
return redisCache.hasKey("social_auth_codes:" + key);
|
}
|
}
|