mirror of
https://gitee.com/xiaonuobase/snowy.git
synced 2026-03-22 02:37:16 +08:00
【更新】基座三方登录完善,增加三方登录是否开启配置,完善字典颜色支持
This commit is contained in:
@@ -30,14 +30,54 @@ public enum AuthThirdPlatformEnum {
|
||||
IAM("IAM"),
|
||||
|
||||
/**
|
||||
* GITEE
|
||||
* 钉钉
|
||||
*/
|
||||
GITEE("GITEE"),
|
||||
DINGTALK("DINGTALK"),
|
||||
|
||||
/**
|
||||
* WECHAT
|
||||
* 企业微信
|
||||
*/
|
||||
WECHAT("WECHAT");
|
||||
WORKWECHAT("WORKWECHAT"),
|
||||
|
||||
/**
|
||||
* 飞书
|
||||
*/
|
||||
FEISHU("FEISHU"),
|
||||
|
||||
/**
|
||||
* WeLink
|
||||
*/
|
||||
WELINK("WELINK"),
|
||||
|
||||
/**
|
||||
* 云之家
|
||||
*/
|
||||
YUNZHIJIA("YUNZHIJIA"),
|
||||
|
||||
/**
|
||||
* QQ
|
||||
*/
|
||||
QQ("QQ"),
|
||||
|
||||
/**
|
||||
* 微信
|
||||
*/
|
||||
WECHAT("WECHAT"),
|
||||
|
||||
/**
|
||||
* 微博
|
||||
*/
|
||||
WEIBO("WEIBO"),
|
||||
|
||||
/**
|
||||
* 抖音
|
||||
*/
|
||||
DOUYIN("DOUYIN"),
|
||||
|
||||
/**
|
||||
* 支付宝
|
||||
*/
|
||||
ALIPAY("ALIPAY");
|
||||
|
||||
private final String value;
|
||||
|
||||
@@ -46,7 +86,17 @@ public enum AuthThirdPlatformEnum {
|
||||
}
|
||||
|
||||
public static void validate(String value) {
|
||||
boolean flag = IAM.getValue().equals(value) || GITEE.getValue().equals(value) || WECHAT.getValue().equals(value);
|
||||
boolean flag = IAM.getValue().equals(value) ||
|
||||
DINGTALK.getValue().equals(value) ||
|
||||
WORKWECHAT.getValue().equals(value) ||
|
||||
FEISHU.getValue().equals(value) ||
|
||||
WELINK.getValue().equals(value) ||
|
||||
YUNZHIJIA.getValue().equals(value) ||
|
||||
QQ.getValue().equals(value) ||
|
||||
WECHAT.getValue().equals(value) ||
|
||||
WEIBO.getValue().equals(value) ||
|
||||
DOUYIN.getValue().equals(value) ||
|
||||
ALIPAY.getValue().equals(value);
|
||||
if(!flag) {
|
||||
throw new CommonException("不支持的第三方平台:{}", value);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
* 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
|
||||
* 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
|
||||
*/
|
||||
package vip.xiaonuo.auth.modular.third.request;
|
||||
package vip.xiaonuo.auth.modular.third.request.iam;
|
||||
|
||||
import me.zhyd.oauth.config.AuthSource;
|
||||
import me.zhyd.oauth.request.AuthDefaultRequest;
|
||||
@@ -10,7 +10,7 @@
|
||||
* 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
|
||||
* 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
|
||||
*/
|
||||
package vip.xiaonuo.auth.modular.third.request;
|
||||
package vip.xiaonuo.auth.modular.third.request.iam;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Getter;
|
||||
@@ -38,8 +38,6 @@ import java.util.Map;
|
||||
@Getter
|
||||
public class AuthThirdIamRequest extends AuthDefaultRequest {
|
||||
|
||||
private final Map<String, String> authSourceOidcBaseJson;
|
||||
|
||||
static {
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
}
|
||||
@@ -48,7 +46,6 @@ public class AuthThirdIamRequest extends AuthDefaultRequest {
|
||||
super(config, new AuthThirdIamCommonSource(authSourceOidcBaseJson.get("authorizeUrl"),
|
||||
authSourceOidcBaseJson.get("accessTokenUrl"),
|
||||
authSourceOidcBaseJson.get("userInfoUrl")));
|
||||
this.authSourceOidcBaseJson = authSourceOidcBaseJson;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -28,9 +28,7 @@ import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.model.AuthCallback;
|
||||
import me.zhyd.oauth.model.AuthResponse;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.request.AuthGiteeRequest;
|
||||
import me.zhyd.oauth.request.AuthRequest;
|
||||
import me.zhyd.oauth.request.AuthWeChatOpenRequest;
|
||||
import me.zhyd.oauth.request.*;
|
||||
import me.zhyd.oauth.utils.AuthStateUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -46,7 +44,7 @@ import vip.xiaonuo.auth.modular.third.param.AuthThirdBindAccountParam;
|
||||
import vip.xiaonuo.auth.modular.third.param.AuthThirdCallbackParam;
|
||||
import vip.xiaonuo.auth.modular.third.param.AuthThirdRenderParam;
|
||||
import vip.xiaonuo.auth.modular.third.param.AuthThirdUserPageParam;
|
||||
import vip.xiaonuo.auth.modular.third.request.AuthThirdIamRequest;
|
||||
import vip.xiaonuo.auth.modular.third.request.iam.AuthThirdIamRequest;
|
||||
import vip.xiaonuo.auth.modular.third.result.AuthThirdRenderResult;
|
||||
import vip.xiaonuo.auth.modular.third.service.AuthThirdService;
|
||||
import vip.xiaonuo.common.cache.CommonCacheOperator;
|
||||
@@ -69,6 +67,7 @@ public class AuthThirdServiceImpl extends ServiceImpl<AuthThirdMapper, AuthThird
|
||||
/** 缓存前缀 */
|
||||
private static final String CONFIG_CACHE_KEY = "auth-third-state:";
|
||||
|
||||
private static final String SNOWY_THIRD_IAM_ALLOW_LOGIN_FLAG_KEY = "SNOWY_THIRD_IAM_ALLOW_LOGIN_FLAG";
|
||||
private static final String SNOWY_THIRD_IAM_AUTHORIZE_URL_KEY = "SNOWY_THIRD_IAM_AUTHORIZE_URL";
|
||||
private static final String SNOWY_THIRD_IAM_ACCESS_TOKEN_URL_KEY = "SNOWY_THIRD_IAM_ACCESS_TOKEN_URL";
|
||||
private static final String SNOWY_THIRD_IAM_USER_INFO_URL_KEY = "SNOWY_THIRD_IAM_USER_INFO_URL";
|
||||
@@ -76,10 +75,8 @@ public class AuthThirdServiceImpl extends ServiceImpl<AuthThirdMapper, AuthThird
|
||||
private static final String SNOWY_THIRD_IAM_CLIENT_SECRET_KEY = "SNOWY_THIRD_IAM_CLIENT_SECRET";
|
||||
private static final String SNOWY_THIRD_IAM_REDIRECT_URL_KEY = "SNOWY_THIRD_IAM_REDIRECT_URL";
|
||||
|
||||
private static final String SNOWY_THIRD_GITEE_CLIENT_ID_KEY = "SNOWY_THIRD_GITEE_CLIENT_ID";
|
||||
private static final String SNOWY_THIRD_GITEE_CLIENT_SECRET_KEY = "SNOWY_THIRD_GITEE_CLIENT_SECRET";
|
||||
private static final String SNOWY_THIRD_GITEE_REDIRECT_URL_KEY = "SNOWY_THIRD_GITEE_REDIRECT_URL";
|
||||
|
||||
// 微信
|
||||
private static final String SNOWY_THIRD_WECHAT_ALLOW_LOGIN_FLAG_KEY = "SNOWY_THIRD_WECHAT_ALLOW_LOGIN_FLAG";
|
||||
private static final String SNOWY_THIRD_WECHAT_CLIENT_ID_KEY = "SNOWY_THIRD_WECHAT_CLIENT_ID";
|
||||
private static final String SNOWY_THIRD_WECHAT_CLIENT_SECRET_KEY = "SNOWY_THIRD_WECHAT_CLIENT_SECRET";
|
||||
private static final String SNOWY_THIRD_WECHAT_REDIRECT_URL_KEY = "SNOWY_THIRD_WECHAT_REDIRECT_URL";
|
||||
@@ -258,8 +255,15 @@ public class AuthThirdServiceImpl extends ServiceImpl<AuthThirdMapper, AuthThird
|
||||
source = source.toUpperCase();
|
||||
HttpUtil.setHttp(new HutoolImpl());
|
||||
AuthThirdPlatformEnum.validate(source);
|
||||
if (source.equals(AuthThirdPlatformEnum.IAM.getValue())) {
|
||||
// 山信通登录
|
||||
if(source.equals(AuthThirdPlatformEnum.IAM.getValue())) {
|
||||
// 检查是否允许登录
|
||||
if(!Boolean.parseBoolean(devConfigApi.getValueByKey(SNOWY_THIRD_IAM_ALLOW_LOGIN_FLAG_KEY))) {
|
||||
throw new CommonException("IAM登录已禁用");
|
||||
}
|
||||
if(!devConfigApi.getValueByKey(SNOWY_THIRD_IAM_REDIRECT_URL_KEY).startsWith("http")) {
|
||||
throw new CommonException("重定向地址配置错误");
|
||||
}
|
||||
// IAM登录
|
||||
authRequest = new AuthThirdIamRequest(AuthConfig.builder()
|
||||
.clientId(devConfigApi.getValueByKey(SNOWY_THIRD_IAM_CLIENT_ID_KEY))
|
||||
.clientSecret(devConfigApi.getValueByKey(SNOWY_THIRD_IAM_CLIENT_SECRET_KEY))
|
||||
@@ -271,16 +275,14 @@ public class AuthThirdServiceImpl extends ServiceImpl<AuthThirdMapper, AuthThird
|
||||
"accessTokenUrl", devConfigApi.getValueByKey(SNOWY_THIRD_IAM_ACCESS_TOKEN_URL_KEY),
|
||||
"userInfoUrl", devConfigApi.getValueByKey(SNOWY_THIRD_IAM_USER_INFO_URL_KEY)));
|
||||
}
|
||||
if (source.equals(AuthThirdPlatformEnum.GITEE.getValue())) {
|
||||
// GITEE登录
|
||||
authRequest = new AuthGiteeRequest(AuthConfig.builder()
|
||||
.clientId(devConfigApi.getValueByKey(SNOWY_THIRD_GITEE_CLIENT_ID_KEY))
|
||||
.clientSecret(devConfigApi.getValueByKey(SNOWY_THIRD_GITEE_CLIENT_SECRET_KEY))
|
||||
.redirectUri(devConfigApi.getValueByKey(SNOWY_THIRD_GITEE_REDIRECT_URL_KEY))
|
||||
.ignoreCheckState(true)
|
||||
.build());
|
||||
}
|
||||
if(source.equals(AuthThirdPlatformEnum.WECHAT.getValue())){
|
||||
// 检查是否允许登录
|
||||
if(!Boolean.parseBoolean(devConfigApi.getValueByKey(SNOWY_THIRD_WECHAT_ALLOW_LOGIN_FLAG_KEY))) {
|
||||
throw new CommonException("微信登录已禁用");
|
||||
}
|
||||
if(!devConfigApi.getValueByKey(SNOWY_THIRD_WECHAT_REDIRECT_URL_KEY).startsWith("http")) {
|
||||
throw new CommonException("重定向地址配置错误");
|
||||
}
|
||||
// 微信登录
|
||||
authRequest = new AuthWeChatOpenRequest(AuthConfig.builder()
|
||||
.clientId(devConfigApi.getValueByKey(SNOWY_THIRD_WECHAT_CLIENT_ID_KEY))
|
||||
|
||||
@@ -88,6 +88,19 @@ public class DevConfigController {
|
||||
return CommonResult.data(devConfigService.sysBaseList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统三方登录开关配置
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:00
|
||||
*/
|
||||
@ApiOperationSupport(order = 2)
|
||||
@Operation(summary = "获取系统三方登录开关配置")
|
||||
@GetMapping("/dev/config/sysThirdAllowFlagList")
|
||||
public CommonResult<List<DevConfig>> sysThirdAllowFlagList() {
|
||||
return CommonResult.data(devConfigService.sysThirdAllowFlagList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置列表
|
||||
*
|
||||
|
||||
@@ -51,6 +51,14 @@ public interface DevConfigService extends IService<DevConfig> {
|
||||
*/
|
||||
List<DevConfig> sysBaseList();
|
||||
|
||||
/**
|
||||
* 获取系统三方登录开关配置
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:08
|
||||
*/
|
||||
List<DevConfig> sysThirdAllowFlagList();
|
||||
|
||||
/**
|
||||
* 获取配置列表
|
||||
*
|
||||
|
||||
@@ -135,6 +135,19 @@ public class DevConfigServiceImpl extends ServiceImpl<DevConfigMapper, DevConfig
|
||||
return this.list(lambdaQueryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DevConfig> sysThirdAllowFlagList() {
|
||||
LambdaQueryWrapper<DevConfig> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
// 查询部分字段
|
||||
lambdaQueryWrapper.select(DevConfig::getId, DevConfig::getConfigKey, DevConfig::getConfigValue,
|
||||
DevConfig::getCategory, DevConfig::getSortCode, DevConfig::getRemark);
|
||||
// key以SNOWY_THIRD开头
|
||||
lambdaQueryWrapper.like(DevConfig::getConfigKey, "SNOWY_THIRD");
|
||||
// key以ALLOW_LOGIN_FLAG结尾
|
||||
lambdaQueryWrapper.like(DevConfig::getConfigKey, "ALLOW_LOGIN_FLAG");
|
||||
return this.list(lambdaQueryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DevConfig> list(DevConfigListParam devConfigListParam) {
|
||||
LambdaQueryWrapper<DevConfig> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
@@ -65,7 +65,7 @@ public class DevDictServiceImpl extends ServiceImpl<DevDictMapper, DevDict> impl
|
||||
QueryWrapper<DevDict> queryWrapper = new QueryWrapper<DevDict>().checkSqlInjection();
|
||||
// 查询部分字段
|
||||
queryWrapper.lambda().select(DevDict::getId, DevDict::getParentId, DevDict::getCategory, DevDict::getDictLabel,
|
||||
DevDict::getDictValue, DevDict::getSortCode);
|
||||
DevDict::getDictValue, DevDict::getDictColor, DevDict::getSortCode);
|
||||
if (ObjectUtil.isNotEmpty(devDictPageParam.getParentId())) {
|
||||
queryWrapper.lambda().and(q -> q.eq(DevDict::getParentId, devDictPageParam.getParentId())
|
||||
.or().eq(DevDict::getId, devDictPageParam.getParentId()));
|
||||
@@ -103,7 +103,7 @@ public class DevDictServiceImpl extends ServiceImpl<DevDictMapper, DevDict> impl
|
||||
LambdaQueryWrapper<DevDict> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
// 查询部分字段
|
||||
lambdaQueryWrapper.select(DevDict::getId, DevDict::getParentId, DevDict::getCategory, DevDict::getDictLabel,
|
||||
DevDict::getDictValue, DevDict::getSortCode);
|
||||
DevDict::getDictValue, DevDict::getDictColor, DevDict::getSortCode);
|
||||
lambdaQueryWrapper.orderByAsc(DevDict::getSortCode);
|
||||
if (ObjectUtil.isNotEmpty(devDictTreeParam.getCategory())) {
|
||||
lambdaQueryWrapper.eq(DevDict::getCategory, devDictTreeParam.getCategory());
|
||||
|
||||
Reference in New Issue
Block a user