refactor: 适配 ContiNew Starter 认证模块-JustAuth
This commit is contained in:
parent
86ca8f094f
commit
7ad8d1773a
@ -17,6 +17,12 @@
|
|||||||
<description>公共模块(存放公共工具类,公共配置等)</description>
|
<description>公共模块(存放公共工具类,公共配置等)</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<!-- ContiNew Starter 认证模块 - JustAuth -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>top.charles7c.continew</groupId>
|
||||||
|
<artifactId>continew-starter-auth-justauth</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- ContiNew Starter 认证模块 - SaToken -->
|
<!-- ContiNew Starter 认证模块 - SaToken -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>top.charles7c.continew</groupId>
|
<groupId>top.charles7c.continew</groupId>
|
||||||
@ -84,16 +90,6 @@
|
|||||||
<artifactId>sms4j-spring-boot-starter</artifactId>
|
<artifactId>sms4j-spring-boot-starter</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Just Auth(开箱即用的整合第三方登录的开源组件,脱离繁琐的第三方登录 SDK,让登录变得 So easy!) -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.xkcoding.justauth</groupId>
|
|
||||||
<artifactId>justauth-spring-boot-starter</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>me.zhyd.oauth</groupId>
|
|
||||||
<artifactId>JustAuth</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Easy Excel(一个基于 Java 的、快速、简洁、解决大文件内存溢出的 Excel 处理工具) -->
|
<!-- Easy Excel(一个基于 Java 的、快速、简洁、解决大文件内存溢出的 Excel 处理工具) -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
|
@ -1,88 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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 top.charles7c.cnadmin.common.config.justauth;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
|
|
||||||
import top.charles7c.cnadmin.common.constant.CacheConstants;
|
|
||||||
import top.charles7c.continew.starter.cache.redisson.util.RedisUtils;
|
|
||||||
|
|
||||||
import me.zhyd.oauth.cache.AuthStateCache;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Just Auth 自定义 State 缓存实现(Redis)
|
|
||||||
*
|
|
||||||
* @author Charles7c
|
|
||||||
* @since 2023/10/8 22:17
|
|
||||||
*/
|
|
||||||
public class JustAuthRedisStateCache implements AuthStateCache {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 存入缓存
|
|
||||||
*
|
|
||||||
* @param key
|
|
||||||
* 缓存 key
|
|
||||||
* @param value
|
|
||||||
* 缓存内容
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void cache(String key, String value) {
|
|
||||||
// 参考:在 JustAuth 中,内置了一个基于 map 的 state 缓存器,默认缓存有效期为 3 分钟
|
|
||||||
RedisUtils.set(RedisUtils.formatKey(CacheConstants.SOCIAL_AUTH_STATE_KEY_PREFIX, key), value,
|
|
||||||
Duration.ofMinutes(3));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 存入缓存
|
|
||||||
*
|
|
||||||
* @param key
|
|
||||||
* 缓存 key
|
|
||||||
* @param value
|
|
||||||
* 缓存内容
|
|
||||||
* @param timeout
|
|
||||||
* 指定缓存过期时间(毫秒)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void cache(String key, String value, long timeout) {
|
|
||||||
RedisUtils.set(RedisUtils.formatKey(CacheConstants.SOCIAL_AUTH_STATE_KEY_PREFIX, key), value,
|
|
||||||
Duration.ofMillis(timeout));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取缓存内容
|
|
||||||
*
|
|
||||||
* @param key
|
|
||||||
* 缓存 key
|
|
||||||
* @return 缓存内容
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String get(String key) {
|
|
||||||
return RedisUtils.get(RedisUtils.formatKey(CacheConstants.SOCIAL_AUTH_STATE_KEY_PREFIX, key));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否存在 key,如果对应 key 的 value 值已过期,也返回 false
|
|
||||||
*
|
|
||||||
* @param key
|
|
||||||
* 缓存 key
|
|
||||||
* @return true:存在 key,并且 value 没过期;false:key 不存在或者已过期
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean containsKey(String key) {
|
|
||||||
return RedisUtils.hasKey(RedisUtils.formatKey(CacheConstants.SOCIAL_AUTH_STATE_KEY_PREFIX, key));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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 top.charles7c.cnadmin.common.config.justauth;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
import me.zhyd.oauth.cache.AuthStateCache;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Just Auth State 缓存配置
|
|
||||||
*
|
|
||||||
* @author Charles7c
|
|
||||||
* @since 2023/10/8 22:17
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class JustAuthStateConfiguration {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Just Auth State 缓存 Redis 适配
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public AuthStateCache authStateCache() {
|
|
||||||
return new JustAuthRedisStateCache();
|
|
||||||
}
|
|
||||||
}
|
|
@ -67,9 +67,4 @@ public class CacheConstants {
|
|||||||
* 仪表盘缓存键前缀
|
* 仪表盘缓存键前缀
|
||||||
*/
|
*/
|
||||||
public static final String DASHBOARD_KEY_PREFIX = "DASHBOARD";
|
public static final String DASHBOARD_KEY_PREFIX = "DASHBOARD";
|
||||||
|
|
||||||
/**
|
|
||||||
* 三方账号认证状态键前缀
|
|
||||||
*/
|
|
||||||
public static final String SOCIAL_AUTH_STATE_KEY_PREFIX = "SOCIAL_AUTH_STATE";
|
|
||||||
}
|
}
|
||||||
|
@ -1 +0,0 @@
|
|||||||
com.xkcoding.justauth.autoconfigure.JustAuthAutoConfiguration
|
|
@ -83,21 +83,6 @@ spring.cache:
|
|||||||
# 是否允许缓存空值(默认 true,表示允许,可以解决缓存穿透问题)
|
# 是否允许缓存空值(默认 true,表示允许,可以解决缓存穿透问题)
|
||||||
cache-null-values: true
|
cache-null-values: true
|
||||||
|
|
||||||
--- ### Just Auth 配置
|
|
||||||
justauth:
|
|
||||||
enabled: true
|
|
||||||
type:
|
|
||||||
GITEE:
|
|
||||||
client-id: 5d271b7f638941812aaf8bfc2e2f08f06d6235ef934e0e39537e2364eb8452c4
|
|
||||||
client-secret: 1f7d08**********5b7**********29e
|
|
||||||
redirect-uri: ${project.url}/social/callback?source=gitee
|
|
||||||
GITHUB:
|
|
||||||
client-id: 38080dad08cfbdfacca9
|
|
||||||
client-secret: 1f7d08**********5b7**********29e
|
|
||||||
redirect-uri: ${project.url}/social/callback?source=github
|
|
||||||
cache:
|
|
||||||
type: custom
|
|
||||||
|
|
||||||
--- ### 短信配置
|
--- ### 短信配置
|
||||||
sms:
|
sms:
|
||||||
# 从 YAML 读取配置
|
# 从 YAML 读取配置
|
||||||
@ -177,6 +162,21 @@ springdoc:
|
|||||||
swagger-ui:
|
swagger-ui:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
||||||
|
--- ### Just Auth 配置
|
||||||
|
justauth:
|
||||||
|
enabled: true
|
||||||
|
type:
|
||||||
|
GITEE:
|
||||||
|
client-id: 5d271b7f638941812aaf8bfc2e2f08f06d6235ef934e0e39537e2364eb8452c4
|
||||||
|
client-secret: 1f7d08**********5b7**********29e
|
||||||
|
redirect-uri: ${project.url}/social/callback?source=gitee
|
||||||
|
GITHUB:
|
||||||
|
client-id: 38080dad08cfbdfacca9
|
||||||
|
client-secret: 1f7d08**********5b7**********29e
|
||||||
|
redirect-uri: ${project.url}/social/callback?source=github
|
||||||
|
cache:
|
||||||
|
type: custom
|
||||||
|
|
||||||
--- ### Sa-Token 扩展配置
|
--- ### Sa-Token 扩展配置
|
||||||
sa-token.extension:
|
sa-token.extension:
|
||||||
# 安全配置:排除(放行)路径配置
|
# 安全配置:排除(放行)路径配置
|
||||||
|
@ -85,21 +85,6 @@ spring.cache:
|
|||||||
# 是否允许缓存空值(默认 true,表示允许,可以解决缓存穿透问题)
|
# 是否允许缓存空值(默认 true,表示允许,可以解决缓存穿透问题)
|
||||||
cache-null-values: true
|
cache-null-values: true
|
||||||
|
|
||||||
--- ### Just Auth 配置
|
|
||||||
justauth:
|
|
||||||
enabled: true
|
|
||||||
type:
|
|
||||||
GITEE:
|
|
||||||
client-id: 5d271b7f638941812aaf8bfc2e2f08f06d6235ef934e0e39537e2364eb8452c4
|
|
||||||
client-secret: 1f7d08**********5b7**********29e
|
|
||||||
redirect-uri: ${project.url}/social/callback?source=gitee
|
|
||||||
GITHUB:
|
|
||||||
client-id: 38080dad08cfbdfacca9
|
|
||||||
client-secret: 1f7d08**********5b7**********29e
|
|
||||||
redirect-uri: ${project.url}/social/callback?source=github
|
|
||||||
cache:
|
|
||||||
type: custom
|
|
||||||
|
|
||||||
--- ### 短信配置
|
--- ### 短信配置
|
||||||
sms:
|
sms:
|
||||||
# 从 YAML 读取配置
|
# 从 YAML 读取配置
|
||||||
@ -183,6 +168,21 @@ knife4j:
|
|||||||
# 开启生产环境屏蔽
|
# 开启生产环境屏蔽
|
||||||
production: true
|
production: true
|
||||||
|
|
||||||
|
--- ### Just Auth 配置
|
||||||
|
justauth:
|
||||||
|
enabled: true
|
||||||
|
type:
|
||||||
|
GITEE:
|
||||||
|
client-id: 5d271b7f638941812aaf8bfc2e2f08f06d6235ef934e0e39537e2364eb8452c4
|
||||||
|
client-secret: 1f7d08**********5b7**********29e
|
||||||
|
redirect-uri: ${project.url}/social/callback?source=gitee
|
||||||
|
GITHUB:
|
||||||
|
client-id: 38080dad08cfbdfacca9
|
||||||
|
client-secret: 1f7d08**********5b7**********29e
|
||||||
|
redirect-uri: ${project.url}/social/callback?source=github
|
||||||
|
cache:
|
||||||
|
type: custom
|
||||||
|
|
||||||
--- ### Sa-Token 扩展配置
|
--- ### Sa-Token 扩展配置
|
||||||
sa-token.extension:
|
sa-token.extension:
|
||||||
# 安全配置:排除(放行)路径配置
|
# 安全配置:排除(放行)路径配置
|
||||||
|
23
pom.xml
23
pom.xml
@ -37,7 +37,6 @@
|
|||||||
|
|
||||||
<!-- ### 工具库相关 ### -->
|
<!-- ### 工具库相关 ### -->
|
||||||
<sms4j.version>3.0.4</sms4j.version>
|
<sms4j.version>3.0.4</sms4j.version>
|
||||||
<justauth.version>1.16.5</justauth.version>
|
|
||||||
<easyexcel.version>3.3.2</easyexcel.version>
|
<easyexcel.version>3.3.2</easyexcel.version>
|
||||||
<ip2region.version>3.1.5.1</ip2region.version>
|
<ip2region.version>3.1.5.1</ip2region.version>
|
||||||
|
|
||||||
@ -56,28 +55,6 @@
|
|||||||
<version>${sms4j.version}</version>
|
<version>${sms4j.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Just Auth(开箱即用的整合第三方登录的开源组件,脱离繁琐的第三方登录 SDK,让登录变得 So easy!) -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.xkcoding.justauth</groupId>
|
|
||||||
<artifactId>justauth-spring-boot-starter</artifactId>
|
|
||||||
<version>1.4.0</version>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>cn.hutool</groupId>
|
|
||||||
<artifactId>hutool-core</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>me.zhyd.oauth</groupId>
|
|
||||||
<artifactId>JustAuth</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>me.zhyd.oauth</groupId>
|
|
||||||
<artifactId>JustAuth</artifactId>
|
|
||||||
<version>${justauth.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Easy Excel(一个基于 Java 的、快速、简洁、解决大文件内存溢出的 Excel 处理工具) -->
|
<!-- Easy Excel(一个基于 Java 的、快速、简洁、解决大文件内存溢出的 Excel 处理工具) -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
|
Loading…
Reference in New Issue
Block a user