From 97019000616ca8a64852a117c1ce008b419256e7 Mon Sep 17 00:00:00 2001 From: "Yangkai.Shen" <237497819@qq.com> Date: Thu, 5 Sep 2019 15:21:32 +0800 Subject: [PATCH] =?UTF-8?q?:arrow=5Fup:=20=E5=8D=87=E7=BA=A7=20justauth-sp?= =?UTF-8?q?ring-boot-starter=20=E7=89=88=E6=9C=AC=E4=B8=BA=201.1.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spring-boot-demo-social/pom.xml | 2 +- .../config/justauth/JustAuthConfig.java | 39 ----------- .../justauth/JustAuthRedisStateCache.java | 70 ------------------- 3 files changed, 1 insertion(+), 110 deletions(-) delete mode 100644 spring-boot-demo-social/src/main/java/com/xkcoding/social/config/justauth/JustAuthConfig.java delete mode 100644 spring-boot-demo-social/src/main/java/com/xkcoding/social/config/justauth/JustAuthRedisStateCache.java diff --git a/spring-boot-demo-social/pom.xml b/spring-boot-demo-social/pom.xml index 4960ecf..241acce 100644 --- a/spring-boot-demo-social/pom.xml +++ b/spring-boot-demo-social/pom.xml @@ -20,7 +20,7 @@ UTF-8 UTF-8 1.8 - 1.0.0 + 1.1.0 diff --git a/spring-boot-demo-social/src/main/java/com/xkcoding/social/config/justauth/JustAuthConfig.java b/spring-boot-demo-social/src/main/java/com/xkcoding/social/config/justauth/JustAuthConfig.java deleted file mode 100644 index eb346da..0000000 --- a/spring-boot-demo-social/src/main/java/com/xkcoding/social/config/justauth/JustAuthConfig.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.xkcoding.social.config.justauth; - -import me.zhyd.oauth.cache.AuthStateCache; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; -import org.springframework.data.redis.serializer.StringRedisSerializer; - -import java.io.Serializable; - -/** - *

- * JustAuth自动装配 - *

- * - * @author yangkai.shen - * @date Created in 2019-08-09 14:21 - */ -@Configuration -public class JustAuthConfig { - /** - * 默认情况下的模板只能支持RedisTemplate,也就是只能存入字符串,因此支持序列化 - */ - @Bean - public RedisTemplate redisCacheTemplate(LettuceConnectionFactory redisConnectionFactory) { - RedisTemplate template = new RedisTemplate<>(); - template.setKeySerializer(new StringRedisSerializer()); - template.setValueSerializer(new GenericJackson2JsonRedisSerializer()); - template.setConnectionFactory(redisConnectionFactory); - return template; - } - - @Bean - public AuthStateCache authStateCache(RedisTemplate redisCacheTemplate) { - return new JustAuthRedisStateCache(redisCacheTemplate); - } -} \ No newline at end of file diff --git a/spring-boot-demo-social/src/main/java/com/xkcoding/social/config/justauth/JustAuthRedisStateCache.java b/spring-boot-demo-social/src/main/java/com/xkcoding/social/config/justauth/JustAuthRedisStateCache.java deleted file mode 100644 index cec2fb7..0000000 --- a/spring-boot-demo-social/src/main/java/com/xkcoding/social/config/justauth/JustAuthRedisStateCache.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.xkcoding.social.config.justauth; - -import lombok.RequiredArgsConstructor; -import me.zhyd.oauth.cache.AuthStateCache; -import org.springframework.data.redis.core.RedisTemplate; - -import java.util.concurrent.TimeUnit; - -/** - *

- * Redis作为JustAuth的State的缓存 - *

- * - * @author yangkai.shen - * @date Created in 2019-08-09 14:22 - */ -@RequiredArgsConstructor -public class JustAuthRedisStateCache implements AuthStateCache { - private final RedisTemplate redisTemplate; - private static final long DEF_TIMEOUT = 3 * 60 * 1000; - - /** - * 存入缓存 - * - * @param key 缓存key - * @param value 缓存内容 - */ - @Override - public void cache(String key, String value) { - this.cache(key, value, DEF_TIMEOUT); - } - - /** - * 存入缓存 - * - * @param key 缓存key - * @param value 缓存内容 - * @param timeout 指定缓存过期时间(毫秒) - */ - @Override - public void cache(String key, String value, long timeout) { - redisTemplate.opsForValue().set(key, value, timeout, TimeUnit.MILLISECONDS); - } - - /** - * 获取缓存内容 - * - * @param key 缓存key - * @return 缓存内容 - */ - @Override - public String get(String key) { - return redisTemplate.opsForValue().get(key); - } - - /** - * 是否存在key,如果对应key的value值已过期,也返回false - * - * @param key 缓存key - * @return true:存在key,并且value没过期;false:key不存在或者已过期 - */ - @Override - public boolean containsKey(String key) { - Long expire = redisTemplate.getExpire(key, TimeUnit.MILLISECONDS); - if (expire == null) { - expire = 0L; - } - return expire > 0; - } -}