diff --git a/sa-token-bom/pom.xml b/sa-token-bom/pom.xml index 10dd50dc..6eb680d5 100644 --- a/sa-token-bom/pom.xml +++ b/sa-token-bom/pom.xml @@ -136,12 +136,12 @@ cn.dev33 - sa-token-redisson + sa-token-redisson-spring-boot-starter ${revision} cn.dev33 - sa-token-redisson-jackson2 + sa-token-redisson ${revision} diff --git a/sa-token-demo/sa-token-demo-springboot-redisson/pom.xml b/sa-token-demo/sa-token-demo-springboot-redisson/pom.xml index 7717fd1e..3710cd06 100644 --- a/sa-token-demo/sa-token-demo-springboot-redisson/pom.xml +++ b/sa-token-demo/sa-token-demo-springboot-redisson/pom.xml @@ -42,7 +42,7 @@ cn.dev33 - sa-token-redisson + sa-token-redisson-spring-boot-starter ${sa-token.version} diff --git a/sa-token-dependencies/pom.xml b/sa-token-dependencies/pom.xml index 8f749496..edead77c 100644 --- a/sa-token-dependencies/pom.xml +++ b/sa-token-dependencies/pom.xml @@ -36,7 +36,7 @@ 0.9.1 1.2.83 2.0.15 - 3.19.0 + 3.45.0 5.8.36 diff --git a/sa-token-plugin/pom.xml b/sa-token-plugin/pom.xml index 5f584e92..340a72a3 100644 --- a/sa-token-plugin/pom.xml +++ b/sa-token-plugin/pom.xml @@ -31,6 +31,7 @@ sa-token-jwt sa-token-sso sa-token-oauth2 + sa-token-redisson sa-token-redis-template @@ -41,12 +42,11 @@ sa-token-spring-el sa-token-grpc sa-token-quick-login - sa-token-redisson + sa-token-redisson-spring-boot-starter sa-token-redisx - sa-token-redisson-jackson2 diff --git a/sa-token-plugin/sa-token-redisson-jackson2/pom.xml b/sa-token-plugin/sa-token-redisson-jackson2/pom.xml deleted file mode 100644 index fae05d9d..00000000 --- a/sa-token-plugin/sa-token-redisson-jackson2/pom.xml +++ /dev/null @@ -1,61 +0,0 @@ - - - 4.0.0 - - - cn.dev33 - sa-token-plugin - ${revision} - ../pom.xml - - jar - - sa-token-redisson-jackson2 - sa-token-redisson-jackson2 - sa-token integrate redisson (to jackson) - - - - 3.27.2 - 2.17.0 - - - - - - cn.dev33 - sa-token-core - provided - - - - - org.redisson - redisson - ${redisson.version} - - - org.yaml - snakeyaml - - - - - - - com.fasterxml.jackson.core - jackson-databind - ${jackson.version} - - - - - com.fasterxml.jackson.datatype - jackson-datatype-jsr310 - ${jackson.version} - - - - diff --git a/sa-token-plugin/sa-token-redisson-jackson2/src/main/java/cn/dev33/satoken/dao/SaTokenDaoRedissonJackson.java b/sa-token-plugin/sa-token-redisson-jackson2/src/main/java/cn/dev33/satoken/dao/SaTokenDaoRedissonJackson.java deleted file mode 100644 index fa98f61c..00000000 --- a/sa-token-plugin/sa-token-redisson-jackson2/src/main/java/cn/dev33/satoken/dao/SaTokenDaoRedissonJackson.java +++ /dev/null @@ -1,292 +0,0 @@ -/* - * Copyright 2020-2099 sa-token.cc - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package cn.dev33.satoken.dao; - -import java.time.Duration; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.format.DateTimeFormatter; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import com.fasterxml.jackson.annotation.JsonTypeInfo; -import org.redisson.api.RBatch; -import org.redisson.api.RBucket; -import org.redisson.api.RBucketAsync; -import org.redisson.api.RedissonClient; -import org.redisson.client.codec.Codec; -import org.redisson.codec.JsonJacksonCodec; - -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer; -import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; -import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer; -import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer; -import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; -import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer; - -import cn.dev33.satoken.strategy.SaStrategy; -import cn.dev33.satoken.util.SaFoxUtil; - -/** - * Sa-Token 持久层实现 [ Redisson客户端、Redis存储、Jackson序列化 ] - * - * @author 疯狂的狮子Li - * @author noear - * @since 1.34.0 - */ -public class SaTokenDaoRedissonJackson implements SaTokenDao { - - public static final String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss"; - public static final String DATE_PATTERN = "yyyy-MM-dd"; - public static final String TIME_PATTERN = "HH:mm:ss"; - public static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern(DATE_TIME_PATTERN); - public static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern(DATE_PATTERN); - public static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern(TIME_PATTERN); - - /** - * ObjectMapper 对象 (以 public 作用域暴露出此对象,方便开发者二次更改配置) - * - *

例如: - *

-	 *      SaTokenDaoRedisJackson redisJackson = (SaTokenDaoRedisJackson) SaManager.getSaTokenDao();
-	 *      redisJackson.objectMapper.xxx = xxx;
-	 * 	
- *

- */ - public final ObjectMapper objectMapper; - - /** - * 序列化方式 - */ - public final Codec codec; - - /** - * redisson 客户端 - */ - public final RedissonClient redissonClient; - - public SaTokenDaoRedissonJackson(RedissonClient redissonClient) { - this.objectMapper = new ObjectMapper(); - - this.objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY); - - // 配置[忽略未知字段] - this.objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - - // 配置[时间类型转换] - JavaTimeModule timeModule = new JavaTimeModule(); - // LocalDateTime序列化与反序列化 - timeModule.addSerializer(new LocalDateTimeSerializer(DATE_TIME_FORMATTER)); - timeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DATE_TIME_FORMATTER)); - // LocalDate序列化与反序列化 - timeModule.addSerializer(new LocalDateSerializer(DATE_FORMATTER)); - timeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(DATE_FORMATTER)); - // LocalTime序列化与反序列化 - timeModule.addSerializer(new LocalTimeSerializer(TIME_FORMATTER)); - timeModule.addDeserializer(LocalTime.class, new LocalTimeDeserializer(TIME_FORMATTER)); - this.objectMapper.registerModule(timeModule); - - // 重写 SaSession 生成策略 - SaStrategy.instance.createSession = (sessionId) -> new SaSessionForJacksonCustomized(sessionId); - - - // 开始初始化相关组件 - this.codec = new JsonJacksonCodec(objectMapper); - this.redissonClient = redissonClient; - } - - - /** - * 获取Value,如无返空 - */ - @Override - public String get(String key) { - RBucket rBucket = redissonClient.getBucket(key, codec); - return rBucket.get(); - } - - /** - * 写入Value,并设定存活时间 (单位: 秒) - */ - @Override - public void set(String key, String value, long timeout) { - if(timeout == 0 || timeout <= SaTokenDao.NOT_VALUE_EXPIRE) { - return; - } - // 判断是否为永不过期 - if(timeout == SaTokenDao.NEVER_EXPIRE) { - RBucket bucket = redissonClient.getBucket(key, codec); - bucket.set(value); - } else { - RBatch batch = redissonClient.createBatch(); - RBucketAsync bucket = batch.getBucket(key, codec); - bucket.setAsync(value); - bucket.expireAsync(Duration.ofSeconds(timeout)); - batch.execute(); - } - } - - /** - * 修修改指定key-value键值对 (过期时间不变) - */ - @Override - public void update(String key, String value) { - long expire = getTimeout(key); - // -2 = 无此键 - if(expire == SaTokenDao.NOT_VALUE_EXPIRE) { - return; - } - this.set(key, value, expire); - } - - /** - * 删除Value - */ - @Override - public void delete(String key) { - redissonClient.getBucket(key, codec).delete(); - } - - /** - * 获取Value的剩余存活时间 (单位: 秒) - */ - @Override - public long getTimeout(String key) { - RBucket rBucket = redissonClient.getBucket(key, codec); - long timeout = rBucket.remainTimeToLive(); - return timeout < 0 ? timeout : timeout / 1000; - } - - /** - * 修改Value的剩余存活时间 (单位: 秒) - */ - @Override - public void updateTimeout(String key, long timeout) { - // 判断是否想要设置为永久 - if(timeout == SaTokenDao.NEVER_EXPIRE) { - long expire = getTimeout(key); - if(expire == SaTokenDao.NEVER_EXPIRE) { - // 如果其已经被设置为永久,则不作任何处理 - } else { - // 如果尚未被设置为永久,那么再次set一次 - this.set(key, this.get(key), timeout); - } - return; - } - RBucket rBucket = redissonClient.getBucket(key, codec); - rBucket.expire(Duration.ofSeconds(timeout)); - } - - - - /** - * 获取Object,如无返空 - */ - @Override - public Object getObject(String key) { - RBucket rBucket = redissonClient.getBucket(key, codec); - return rBucket.get(); - } - - /** - * 写入Object,并设定存活时间 (单位: 秒) - */ - @Override - public void setObject(String key, Object object, long timeout) { - if(timeout == 0 || timeout <= SaTokenDao.NOT_VALUE_EXPIRE) { - return; - } - // 判断是否为永不过期 - if(timeout == SaTokenDao.NEVER_EXPIRE) { - RBucket bucket = redissonClient.getBucket(key, codec); - bucket.set(object); - } else { - RBatch batch = redissonClient.createBatch(); - RBucketAsync bucket = batch.getBucket(key, codec); - bucket.setAsync(object); - bucket.expireAsync(Duration.ofSeconds(timeout)); - batch.execute(); - } - - } - - /** - * 更新Object (过期时间不变) - */ - @Override - public void updateObject(String key, Object object) { - long expire = getObjectTimeout(key); - // -2 = 无此键 - if(expire == SaTokenDao.NOT_VALUE_EXPIRE) { - return; - } - this.setObject(key, object, expire); - } - - /** - * 删除Object - */ - @Override - public void deleteObject(String key) { - redissonClient.getBucket(key, codec).delete(); - } - - /** - * 获取Object的剩余存活时间 (单位: 秒) - */ - @Override - public long getObjectTimeout(String key) { - RBucket rBucket = redissonClient.getBucket(key, codec); - long timeout = rBucket.remainTimeToLive(); - return timeout < 0 ? timeout : timeout / 1000; - } - - /** - * 修改Object的剩余存活时间 (单位: 秒) - */ - @Override - public void updateObjectTimeout(String key, long timeout) { - // 判断是否想要设置为永久 - if(timeout == SaTokenDao.NEVER_EXPIRE) { - long expire = getObjectTimeout(key); - if(expire == SaTokenDao.NEVER_EXPIRE) { - // 如果其已经被设置为永久,则不作任何处理 - } else { - // 如果尚未被设置为永久,那么再次set一次 - this.setObject(key, this.getObject(key), timeout); - } - return; - } - RBucket rBucket = redissonClient.getBucket(key, codec); - rBucket.expire(Duration.ofSeconds(timeout)); - } - - - /** - * 搜索数据 - */ - @Override - public List searchData(String prefix, String keyword, int start, int size, boolean sortType) { - Stream stream = redissonClient.getKeys().getKeysStreamByPattern(prefix + "*" + keyword + "*"); - List list = stream.collect(Collectors.toList()); - return SaFoxUtil.searchList(list, start, size, sortType); - } -} diff --git a/sa-token-plugin/sa-token-redisson/.gitignore b/sa-token-plugin/sa-token-redisson-spring-boot-starter/.gitignore similarity index 100% rename from sa-token-plugin/sa-token-redisson/.gitignore rename to sa-token-plugin/sa-token-redisson-spring-boot-starter/.gitignore diff --git a/sa-token-plugin/sa-token-redisson-spring-boot-starter/pom.xml b/sa-token-plugin/sa-token-redisson-spring-boot-starter/pom.xml new file mode 100644 index 00000000..8ffaf12f --- /dev/null +++ b/sa-token-plugin/sa-token-redisson-spring-boot-starter/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + + + cn.dev33 + sa-token-plugin + ${revision} + ../pom.xml + + jar + + sa-token-redisson-jackson + sa-token-redisson-spring-boot-starter + sa-token integrate redisson (to jackson) + + + + + cn.dev33 + sa-token-core + + + + + cn.dev33 + sa-token-redisson + + + + + org.redisson + redisson-spring-boot-starter + + + + + + + diff --git a/sa-token-plugin/sa-token-redisson-jackson2/src/main/java/cn/dev33/satoken/dao/SaSessionForJacksonCustomized.java b/sa-token-plugin/sa-token-redisson-spring-boot-starter/src/main/java/cn/dev33/satoken/spring/SaTokenDaoForRedissonBeanRegister.java similarity index 52% rename from sa-token-plugin/sa-token-redisson-jackson2/src/main/java/cn/dev33/satoken/dao/SaSessionForJacksonCustomized.java rename to sa-token-plugin/sa-token-redisson-spring-boot-starter/src/main/java/cn/dev33/satoken/spring/SaTokenDaoForRedissonBeanRegister.java index fe56ca4f..a9fb34c1 100644 --- a/sa-token-plugin/sa-token-redisson-jackson2/src/main/java/cn/dev33/satoken/dao/SaSessionForJacksonCustomized.java +++ b/sa-token-plugin/sa-token-redisson-spring-boot-starter/src/main/java/cn/dev33/satoken/spring/SaTokenDaoForRedissonBeanRegister.java @@ -13,35 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package cn.dev33.satoken.dao; +package cn.dev33.satoken.spring; -import cn.dev33.satoken.session.SaSession; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import cn.dev33.satoken.dao.SaTokenDao; +import cn.dev33.satoken.dao.SaTokenDaoForRedisson; +import org.redisson.api.RedissonClient; +import org.springframework.context.annotation.Bean; /** - * Jackson定制版SaSession,忽略 timeout 等属性的序列化 - * + * 注册 SaTokenDaoForRedisson Bean + * * @author click33 * @since 1.34.0 */ -@JsonIgnoreProperties({"timeout"}) -public class SaSessionForJacksonCustomized extends SaSession { +public class SaTokenDaoForRedissonBeanRegister { - /** - * - */ - private static final long serialVersionUID = -7600983549653130681L; - - public SaSessionForJacksonCustomized() { - super(); - } - - /** - * 构建一个Session对象 - * @param id Session的id - */ - public SaSessionForJacksonCustomized(String id) { - super(id); + @Bean + public SaTokenDao getSaTokenDaoForRedisson(RedissonClient redissonClient) { + return new SaTokenDaoForRedisson(redissonClient); } } diff --git a/sa-token-plugin/sa-token-redisson/src/main/resources/META-INF/spring.factories b/sa-token-plugin/sa-token-redisson-spring-boot-starter/src/main/resources/META-INF/spring.factories similarity index 53% rename from sa-token-plugin/sa-token-redisson/src/main/resources/META-INF/spring.factories rename to sa-token-plugin/sa-token-redisson-spring-boot-starter/src/main/resources/META-INF/spring.factories index 79e474b2..5bfefa9a 100644 --- a/sa-token-plugin/sa-token-redisson/src/main/resources/META-INF/spring.factories +++ b/sa-token-plugin/sa-token-redisson-spring-boot-starter/src/main/resources/META-INF/spring.factories @@ -1 +1 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.dev33.satoken.dao.SaTokenDaoForRedisson \ No newline at end of file +org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.dev33.satoken.spring.SaTokenDaoForRedissonBeanRegister \ No newline at end of file diff --git a/sa-token-plugin/sa-token-redisson-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/sa-token-plugin/sa-token-redisson-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 00000000..b003810e --- /dev/null +++ b/sa-token-plugin/sa-token-redisson-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +cn.dev33.satoken.spring.SaTokenDaoForRedissonBeanRegister \ No newline at end of file diff --git a/sa-token-plugin/sa-token-redisson-jackson2/README.md b/sa-token-plugin/sa-token-redisson/README.md similarity index 100% rename from sa-token-plugin/sa-token-redisson-jackson2/README.md rename to sa-token-plugin/sa-token-redisson/README.md diff --git a/sa-token-plugin/sa-token-redisson/pom.xml b/sa-token-plugin/sa-token-redisson/pom.xml index ddf26330..8dd39a9d 100644 --- a/sa-token-plugin/sa-token-redisson/pom.xml +++ b/sa-token-plugin/sa-token-redisson/pom.xml @@ -12,24 +12,33 @@ jar - sa-token-redisson-jackson + sa-token-redisson-jackson2 sa-token-redisson sa-token integrate redisson (to jackson) + + + - + cn.dev33 sa-token-core + org.redisson - redisson-spring-boot-starter + redisson + - - - diff --git a/sa-token-plugin/sa-token-redisson/src/main/java/cn/dev33/satoken/dao/SaTokenDaoForRedisson.java b/sa-token-plugin/sa-token-redisson/src/main/java/cn/dev33/satoken/dao/SaTokenDaoForRedisson.java index dd97a77a..ff984324 100644 --- a/sa-token-plugin/sa-token-redisson/src/main/java/cn/dev33/satoken/dao/SaTokenDaoForRedisson.java +++ b/sa-token-plugin/sa-token-redisson/src/main/java/cn/dev33/satoken/dao/SaTokenDaoForRedisson.java @@ -21,8 +21,6 @@ import org.redisson.api.RBatch; import org.redisson.api.RBucket; import org.redisson.api.RBucketAsync; import org.redisson.api.RedissonClient; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; import java.time.Duration; import java.util.List; @@ -33,31 +31,18 @@ import java.util.stream.Stream; * Sa-Token 持久层实现 [ Redisson客户端、Redis存储、Jackson序列化 ] * * @author 疯狂的狮子Li + * @author noear * @since 1.34.0 */ -@Component public class SaTokenDaoForRedisson implements SaTokenDaoByObjectFollowStringUseJsonSerializer { /** * redisson 客户端 */ - public RedissonClient redissonClient; - - /** - * 标记:是否已初始化成功 - */ - public boolean isInit; - - @Autowired - public void init(RedissonClient redissonClient) { - // 不重复初始化 - if(this.isInit) { - return; - } + public final RedissonClient redissonClient; - // 开始初始化相关组件 + public SaTokenDaoForRedisson(RedissonClient redissonClient) { this.redissonClient = redissonClient; - this.isInit = true; } @@ -152,5 +137,4 @@ public class SaTokenDaoForRedisson implements SaTokenDaoByObjectFollowStringUseJ List list = stream.collect(Collectors.toList()); return SaFoxUtil.searchList(list, start, size, sortType); } - } diff --git a/sa-token-plugin/sa-token-redisson/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/sa-token-plugin/sa-token-redisson/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted file mode 100644 index 36aa50fe..00000000 --- a/sa-token-plugin/sa-token-redisson/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /dev/null @@ -1 +0,0 @@ -cn.dev33.satoken.dao.SaTokenDaoForRedisson \ No newline at end of file diff --git a/sa-token-starter/sa-token-solon-plugin/src/main/java/cn/dev33/satoken/solon/dao/SaTokenDaoOfRedisBase64.java b/sa-token-starter/sa-token-solon-plugin/src/main/java/cn/dev33/satoken/solon/dao/SaTokenDaoOfRedisBase64.java index 40df43f3..3523be14 100644 --- a/sa-token-starter/sa-token-solon-plugin/src/main/java/cn/dev33/satoken/solon/dao/SaTokenDaoOfRedisBase64.java +++ b/sa-token-starter/sa-token-solon-plugin/src/main/java/cn/dev33/satoken/solon/dao/SaTokenDaoOfRedisBase64.java @@ -16,6 +16,7 @@ package cn.dev33.satoken.solon.dao; import cn.dev33.satoken.dao.SaTokenDao; +import cn.dev33.satoken.dao.auto.SaTokenDaoBySessionFollowObject; import cn.dev33.satoken.util.SaFoxUtil; import org.noear.redisx.RedisClient; import org.noear.redisx.plus.RedisBucket; @@ -31,7 +32,7 @@ import java.util.Set; * @author noear * @since 1.6 */ -public class SaTokenDaoOfRedisBase64 implements SaTokenDao { +public class SaTokenDaoOfRedisBase64 implements SaTokenDaoBySessionFollowObject { private final RedisBucket redisBucket; public SaTokenDaoOfRedisBase64(Properties props) {