diff --git a/win-framework/pom.xml b/win-framework/pom.xml index a5f71d92..a16ba8fc 100644 --- a/win-framework/pom.xml +++ b/win-framework/pom.xml @@ -26,8 +26,6 @@ win-spring-boot-starter-biz-operatelog win-spring-boot-starter-biz-dict win-spring-boot-starter-biz-sms - win-spring-boot-starter-biz-weixin - win-spring-boot-starter-biz-social win-spring-boot-starter-biz-tenant win-spring-boot-starter-biz-data-permission win-spring-boot-starter-biz-error-code diff --git a/win-framework/win-spring-boot-starter-biz-social/pom.xml b/win-framework/win-spring-boot-starter-biz-social/pom.xml deleted file mode 100644 index 8d56770f..00000000 --- a/win-framework/win-spring-boot-starter-biz-social/pom.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - com.win - win-framework - ${revision} - - jar - 4.0.0 - - win-spring-boot-starter-biz-social - ${project.artifactId} - - - - com.win - win-common - - - - org.springframework.boot - spring-boot-starter-aop - - - - com.win - win-spring-boot-starter-web - - - - org.springframework.boot - spring-boot-configuration-processor - true - - - - com.xingyuv - spring-boot-starter-justauth - - - cn.hutool - hutool-core - - - - - com.win - win-spring-boot-starter-redis - - - - - - \ No newline at end of file diff --git a/win-framework/win-spring-boot-starter-biz-social/src/main/java/com/win/framework/social/config/WinSocialAutoConfiguration.java b/win-framework/win-spring-boot-starter-biz-social/src/main/java/com/win/framework/social/config/WinSocialAutoConfiguration.java deleted file mode 100644 index cdfe73c6..00000000 --- a/win-framework/win-spring-boot-starter-biz-social/src/main/java/com/win/framework/social/config/WinSocialAutoConfiguration.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.win.framework.social.config; - -import com.win.framework.social.core.WinAuthRequestFactory; -import com.xingyuv.http.HttpUtil; -import com.xingyuv.http.support.hutool.HutoolImpl; -import com.xingyuv.jushauth.cache.AuthStateCache; -import com.xingyuv.justauth.autoconfigure.JustAuthProperties; -import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Primary; - -/** - * 社交自动装配类 - * - * @author timfruit - * @date 2021-10-30 - */ -@Slf4j -@AutoConfiguration -@EnableConfigurationProperties(JustAuthProperties.class) -public class WinSocialAutoConfiguration { - - @Bean - @Primary - @ConditionalOnProperty(prefix = "justauth", value = "enabled", havingValue = "true", matchIfMissing = true) - public WinAuthRequestFactory winAuthRequestFactory(JustAuthProperties properties, AuthStateCache authStateCache) { - // 需要修改 HttpUtil 使用的实现,避免类报错 - HttpUtil.setHttp(new HutoolImpl()); - // 创建 WinAuthRequestFactory - return new WinAuthRequestFactory(properties, authStateCache); - } - -} diff --git a/win-framework/win-spring-boot-starter-biz-social/src/main/java/com/win/framework/social/core/WinAuthRequestFactory.java b/win-framework/win-spring-boot-starter-biz-social/src/main/java/com/win/framework/social/core/WinAuthRequestFactory.java deleted file mode 100644 index af2d1634..00000000 --- a/win-framework/win-spring-boot-starter-biz-social/src/main/java/com/win/framework/social/core/WinAuthRequestFactory.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.win.framework.social.core; - -import cn.hutool.core.util.EnumUtil; -import cn.hutool.core.util.ReflectUtil; -import com.win.framework.social.core.enums.AuthExtendSource; -import com.win.framework.social.core.request.AuthWeChatMiniAppRequest; -import com.win.framework.social.core.request.AuthWeChatMpRequest; -import com.xingyuv.jushauth.cache.AuthStateCache; -import com.xingyuv.jushauth.config.AuthConfig; -import com.xingyuv.jushauth.config.AuthSource; -import com.xingyuv.jushauth.request.AuthRequest; -import com.xingyuv.justauth.AuthRequestFactory; -import com.xingyuv.justauth.autoconfigure.JustAuthProperties; - -import java.lang.reflect.Method; - -import static com.xingyuv.jushauth.config.AuthDefaultSource.WECHAT_MP; - -/** - * 第三方授权拓展 request 工厂类 - * 为使得拓展配置 {@link AuthConfig} 和默认配置齐平,所以自定义本工厂类 - * - * @author timfruit - * @date 2021-10-31 - */ -public class WinAuthRequestFactory extends AuthRequestFactory { - - protected JustAuthProperties properties; - protected AuthStateCache authStateCache; - - /** - * 由于父类 configureHttpConfig 方法是 private 修饰,所以获取后,进行反射调用 - */ - private final Method configureHttpConfigMethod = ReflectUtil.getMethod(AuthRequestFactory.class, - "configureHttpConfig", String.class, AuthConfig.class, JustAuthProperties.JustAuthHttpConfig.class); - - public WinAuthRequestFactory(JustAuthProperties properties, AuthStateCache authStateCache) { - super(properties, authStateCache); - this.properties = properties; - this.authStateCache = authStateCache; - } - - /** - * 返回 AuthRequest 对象 - * - * @param source {@link AuthSource} - * @return {@link AuthRequest} - */ - @Override - public AuthRequest get(String source) { - // 先尝试获取自定义扩展的 - AuthRequest authRequest = getExtendRequest(source); - // 找不到,使用默认拓展 - if (authRequest == null) { - authRequest = super.get(source); - } - return authRequest; - } - - protected AuthRequest getExtendRequest(String source) { - // TODO 芋艿:临时兼容 justauth 迁移的类型不对问题; - if (WECHAT_MP.name().equalsIgnoreCase(source)) { - AuthConfig config = properties.getType().get(WECHAT_MP.name()); - return new AuthWeChatMpRequest(config, authStateCache); - } - - AuthExtendSource authExtendSource; - try { - authExtendSource = EnumUtil.fromString(AuthExtendSource.class, source.toUpperCase()); - } catch (IllegalArgumentException e) { - // 无自定义匹配 - return null; - } - - // 拓展配置和默认配置齐平,properties 放在一起 - AuthConfig config = properties.getType().get(authExtendSource.name()); - // 找不到对应关系,直接返回空 - if (config == null) { - return null; - } - // 反射调用,配置 http config - ReflectUtil.invoke(this, configureHttpConfigMethod, authExtendSource.name(), config, properties.getHttpConfig()); - - // 获得拓展的 Request - // noinspection SwitchStatementWithTooFewBranches - switch (authExtendSource) { - case WECHAT_MINI_APP: - return new AuthWeChatMiniAppRequest(config, authStateCache); - default: - return null; - } - } - -} diff --git a/win-framework/win-spring-boot-starter-biz-social/src/main/java/com/win/framework/social/core/enums/AuthExtendSource.java b/win-framework/win-spring-boot-starter-biz-social/src/main/java/com/win/framework/social/core/enums/AuthExtendSource.java deleted file mode 100644 index b08fa05d..00000000 --- a/win-framework/win-spring-boot-starter-biz-social/src/main/java/com/win/framework/social/core/enums/AuthExtendSource.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.win.framework.social.core.enums; - -import com.xingyuv.jushauth.config.AuthSource; -import com.xingyuv.jushauth.request.AuthDefaultRequest; - -/** - * 拓展 JustAuth 各 api 需要的 url, 用枚举类分平台类型管理 - * - * 默认配置 {@link com.xingyuv.jushauth.config.AuthDefaultSource} - * - * @author timfruit - */ -public enum AuthExtendSource implements AuthSource { - - /** - * 微信小程序授权登录 - */ - WECHAT_MINI_APP { - - @Override - public String authorize() { - // 参见 https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/login.html 文档 - throw new UnsupportedOperationException("不支持获取授权 url,请使用小程序内置函数 wx.login() 登录获取 code"); - } - - @Override - public String accessToken() { - // 参见 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html 文档 - // 获取 openid, unionId , session_key 等字段 - return "https://api.weixin.qq.com/sns/jscode2session"; - } - - @Override - public String userInfo() { - // 参见 https://developers.weixin.qq.com/miniprogram/dev/api/open-api/user-info/wx.getUserProfile.html 文档 - throw new UnsupportedOperationException("不支持获取用户信息 url,请使用小程序内置函数 wx.getUserProfile() 获取用户信息"); - } - - @Override - public Class getTargetClass() { - return null; - } - } - -} diff --git a/win-framework/win-spring-boot-starter-biz-social/src/main/java/com/win/framework/social/core/request/AuthWeChatMiniAppRequest.java b/win-framework/win-spring-boot-starter-biz-social/src/main/java/com/win/framework/social/core/request/AuthWeChatMiniAppRequest.java deleted file mode 100644 index 3e80ad3f..00000000 --- a/win-framework/win-spring-boot-starter-biz-social/src/main/java/com/win/framework/social/core/request/AuthWeChatMiniAppRequest.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.win.framework.social.core.request; - -import com.win.framework.common.util.json.JsonUtils; -import com.win.framework.social.core.enums.AuthExtendSource; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.xingyuv.jushauth.cache.AuthStateCache; -import com.xingyuv.jushauth.config.AuthConfig; -import com.xingyuv.jushauth.exception.AuthException; -import com.xingyuv.jushauth.model.AuthCallback; -import com.xingyuv.jushauth.model.AuthToken; -import com.xingyuv.jushauth.model.AuthUser; -import com.xingyuv.jushauth.request.AuthDefaultRequest; -import com.xingyuv.jushauth.utils.HttpUtils; -import com.xingyuv.jushauth.utils.UrlBuilder; -import lombok.Data; - -/** - * 微信小程序登陆 Request 请求 - * - * 由于 JustAuth 定位是面向 Web 为主的三方登录,所以微信小程序只能自己封装 - * - * @author timfruit - * @date 2021-10-29 - */ -public class AuthWeChatMiniAppRequest extends AuthDefaultRequest { - - public AuthWeChatMiniAppRequest(AuthConfig config, AuthStateCache authStateCache) { - super(config, AuthExtendSource.WECHAT_MINI_APP, authStateCache); - } - - @Override - protected AuthToken getAccessToken(AuthCallback authCallback) { - // 参见 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html 文档 - // 使用 code 获取对应的 openId、unionId 等字段 - String response = new HttpUtils(config.getHttpConfig()).get(accessTokenUrl(authCallback.getCode())).getBody(); - JSCode2SessionResponse accessTokenObject = JsonUtils.parseObject(response, JSCode2SessionResponse.class); - assert accessTokenObject != null; - checkResponse(accessTokenObject); - // 拼装结果 - return AuthToken.builder() - .openId(accessTokenObject.getOpenid()) - .unionId(accessTokenObject.getUnionId()) - .build(); - } - - @Override - protected AuthUser getUserInfo(AuthToken authToken) { - // 参见 https://developers.weixin.qq.com/miniprogram/dev/api/open-api/user-info/wx.getUserProfile.html 文档 - // 如果需要用户信息,需要在小程序调用函数后传给后端 - return AuthUser.builder() - .username("") - .nickname("") - .avatar("") - .uuid(authToken.getOpenId()) - .token(authToken) - .source(source.toString()) - .build(); - } - - /** - * 检查响应内容是否正确 - * - * @param response 请求响应内容 - */ - private void checkResponse(JSCode2SessionResponse response) { - if (response.getErrorCode() != 0) { - throw new AuthException(response.getErrorCode(), response.getErrorMsg()); - } - } - - @Override - protected String accessTokenUrl(String code) { - return UrlBuilder.fromBaseUrl(source.accessToken()) - .queryParam("appid", config.getClientId()) - .queryParam("secret", config.getClientSecret()) - .queryParam("js_code", code) - .queryParam("grant_type", "authorization_code") - .build(); - } - - @Data - @SuppressWarnings("SpellCheckingInspection") - private static class JSCode2SessionResponse { - - @JsonProperty("errcode") - private int errorCode; - @JsonProperty("errmsg") - private String errorMsg; - @JsonProperty("session_key") - private String sessionKey; - private String openid; - @JsonProperty("unionid") - private String unionId; - - } - -} diff --git a/win-framework/win-spring-boot-starter-biz-social/src/main/java/com/win/framework/social/core/request/AuthWeChatMpRequest.java b/win-framework/win-spring-boot-starter-biz-social/src/main/java/com/win/framework/social/core/request/AuthWeChatMpRequest.java deleted file mode 100644 index b0ad9ecb..00000000 --- a/win-framework/win-spring-boot-starter-biz-social/src/main/java/com/win/framework/social/core/request/AuthWeChatMpRequest.java +++ /dev/null @@ -1,178 +0,0 @@ -package com.win.framework.social.core.request; - -import com.alibaba.fastjson.JSONObject; -import com.xingyuv.jushauth.cache.AuthStateCache; -import com.xingyuv.jushauth.config.AuthConfig; -import com.xingyuv.jushauth.config.AuthDefaultSource; -import com.xingyuv.jushauth.enums.AuthResponseStatus; -import com.xingyuv.jushauth.enums.AuthUserGender; -import com.xingyuv.jushauth.enums.scope.AuthWechatMpScope; -import com.xingyuv.jushauth.exception.AuthException; -import com.xingyuv.jushauth.model.AuthCallback; -import com.xingyuv.jushauth.model.AuthResponse; -import com.xingyuv.jushauth.model.AuthToken; -import com.xingyuv.jushauth.model.AuthUser; -import com.xingyuv.jushauth.request.AuthDefaultRequest; -import com.xingyuv.jushauth.utils.AuthScopeUtils; -import com.xingyuv.jushauth.utils.GlobalAuthUtils; -import com.xingyuv.jushauth.utils.HttpUtils; -import com.xingyuv.jushauth.utils.UrlBuilder; - -/** - * 微信公众平台登录 - * - * @author yangkai.shen (https://xkcoding.com) - * @since 1.1.0 - */ -public class AuthWeChatMpRequest extends AuthDefaultRequest { - public AuthWeChatMpRequest(AuthConfig config) { - super(config, AuthDefaultSource.WECHAT_MP); - } - - public AuthWeChatMpRequest(AuthConfig config, AuthStateCache authStateCache) { - super(config, AuthDefaultSource.WECHAT_MP, authStateCache); - } - - /** - * 微信的特殊性,此时返回的信息同时包含 openid 和 access_token - * - * @param authCallback 回调返回的参数 - * @return 所有信息 - */ - @Override - protected AuthToken getAccessToken(AuthCallback authCallback) { - return this.getToken(accessTokenUrl(authCallback.getCode())); - } - - @Override - protected AuthUser getUserInfo(AuthToken authToken) { - String openId = authToken.getOpenId(); - - String response = doGetUserInfo(authToken); - JSONObject object = JSONObject.parseObject(response); - - this.checkResponse(object); - - String location = String.format("%s-%s-%s", object.getString("country"), object.getString("province"), object.getString("city")); - - if (object.containsKey("unionid")) { - authToken.setUnionId(object.getString("unionid")); - } - - return AuthUser.builder() - .rawUserInfo(object) - .username(object.getString("nickname")) - .nickname(object.getString("nickname")) - .avatar(object.getString("headimgurl")) - .location(location) - .uuid(openId) - .gender(AuthUserGender.getWechatRealGender(object.getString("sex"))) - .token(authToken) - .source(source.toString()) - .build(); - } - - @Override - public AuthResponse refresh(AuthToken oldToken) { - return AuthResponse.builder() - .code(AuthResponseStatus.SUCCESS.getCode()) - .data(this.getToken(refreshTokenUrl(oldToken.getRefreshToken()))) - .build(); - } - - /** - * 检查响应内容是否正确 - * - * @param object 请求响应内容 - */ - private void checkResponse(JSONObject object) { - if (object.containsKey("errcode")) { - throw new AuthException(object.getIntValue("errcode"), object.getString("errmsg")); - } - } - - /** - * 获取token,适用于获取access_token和刷新token - * - * @param accessTokenUrl 实际请求token的地址 - * @return token对象 - */ - private AuthToken getToken(String accessTokenUrl) { - String response = new HttpUtils(config.getHttpConfig()).get(accessTokenUrl).getBody(); - JSONObject accessTokenObject = JSONObject.parseObject(response); - - this.checkResponse(accessTokenObject); - - return AuthToken.builder() - .accessToken(accessTokenObject.getString("access_token")) - .refreshToken(accessTokenObject.getString("refresh_token")) - .expireIn(accessTokenObject.getIntValue("expires_in")) - .openId(accessTokenObject.getString("openid")) - .scope(accessTokenObject.getString("scope")) - .build(); - } - - /** - * 返回带{@code state}参数的授权url,授权回调时会带上这个{@code state} - * - * @param state state 验证授权流程的参数,可以防止csrf - * @return 返回授权地址 - * @since 1.9.3 - */ - @Override - public String authorize(String state) { - return UrlBuilder.fromBaseUrl(source.authorize()) - .queryParam("appid", config.getClientId()) - .queryParam("redirect_uri", GlobalAuthUtils.urlEncode(config.getRedirectUri())) - .queryParam("response_type", "code") - .queryParam("scope", this.getScopes(",", false, AuthScopeUtils.getDefaultScopes(AuthWechatMpScope.values()))) - .queryParam("state", getRealState(state).concat("#wechat_redirect")) - .build(); - } - - /** - * 返回获取accessToken的url - * - * @param code 授权码 - * @return 返回获取accessToken的url - */ - @Override - protected String accessTokenUrl(String code) { - return UrlBuilder.fromBaseUrl(source.accessToken()) - .queryParam("appid", config.getClientId()) - .queryParam("secret", config.getClientSecret()) - .queryParam("code", code) - .queryParam("grant_type", "authorization_code") - .build(); - } - - /** - * 返回获取userInfo的url - * - * @param authToken 用户授权后的token - * @return 返回获取userInfo的url - */ - @Override - protected String userInfoUrl(AuthToken authToken) { - return UrlBuilder.fromBaseUrl(source.userInfo()) - .queryParam("access_token", authToken.getAccessToken()) - .queryParam("openid", authToken.getOpenId()) - .queryParam("lang", "zh_CN") - .build(); - } - - /** - * 返回获取userInfo的url - * - * @param refreshToken getAccessToken方法返回的refreshToken - * @return 返回获取userInfo的url - */ - @Override - protected String refreshTokenUrl(String refreshToken) { - return UrlBuilder.fromBaseUrl(source.refresh()) - .queryParam("appid", config.getClientId()) - .queryParam("grant_type", "refresh_token") - .queryParam("refresh_token", refreshToken) - .build(); - } -} diff --git a/win-framework/win-spring-boot-starter-biz-social/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/win-framework/win-spring-boot-starter-biz-social/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted file mode 100644 index 00b932cc..00000000 --- a/win-framework/win-spring-boot-starter-biz-social/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /dev/null @@ -1 +0,0 @@ -com.win.framework.social.config.WinSocialAutoConfiguration \ No newline at end of file diff --git a/win-framework/win-spring-boot-starter-biz-weixin/pom.xml b/win-framework/win-spring-boot-starter-biz-weixin/pom.xml deleted file mode 100644 index b0524106..00000000 --- a/win-framework/win-spring-boot-starter-biz-weixin/pom.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - com.win - win-framework - ${revision} - - 4.0.0 - win-spring-boot-starter-biz-weixin - jar - - ${project.artifactId} - 微信拓展 - 1. 基于 weixin-java-mp 库,对接微信公众号平台。目前主要解决微信公众号的支付场景。 - 2. 基于 weixin-java-miniapp 库,对接微信小程序。目前主要解决微信小程序的一键登录场景。 - - https://github.com/YunaiV/ruoyi-vue-pro - - - - com.win - win-common - - - - - com.win - win-spring-boot-starter-test - test - - - - - com.github.binarywang - wx-java-mp-spring-boot-starter - - - com.github.binarywang - wx-java-miniapp-spring-boot-starter - - - - diff --git a/win-framework/win-spring-boot-starter-biz-weixin/src/main/java/com/win/framework/weixin/package-info.java b/win-framework/win-spring-boot-starter-biz-weixin/src/main/java/com/win/framework/weixin/package-info.java deleted file mode 100644 index 1a22ce66..00000000 --- a/win-framework/win-spring-boot-starter-biz-weixin/src/main/java/com/win/framework/weixin/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -/** - * 微信拓展 - * 1. 基于 weixin-java-mp 库,对接微信公众号平台。目前主要解决微信公众号的支付场景。 - * 2. 基于 weixin-java-miniapp 库,对接微信小程序。目前主要解决微信小程序的一键登录场景。 - */ -package com.win.framework.weixin; - diff --git a/win-framework/win-spring-boot-starter-protection/src/main/java/com/win/framework/resilience4j/《芋道 Spring Boot 服务容错 Resilience4j 入门》.md b/win-framework/win-spring-boot-starter-protection/src/main/java/com/win/framework/resilience4j/《芋道 Spring Boot 服务容错 Resilience4j 入门》.md deleted file mode 100644 index e8534ef9..00000000 --- a/win-framework/win-spring-boot-starter-protection/src/main/java/com/win/framework/resilience4j/《芋道 Spring Boot 服务容错 Resilience4j 入门》.md +++ /dev/null @@ -1 +0,0 @@ - diff --git a/win-module-bpm/win-module-bpm-biz/src/main/java/com/win/module/bpm/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md b/win-module-bpm/win-module-bpm-biz/src/main/java/com/win/module/bpm/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md deleted file mode 100644 index 2f05ebd1..00000000 --- a/win-module-bpm/win-module-bpm-biz/src/main/java/com/win/module/bpm/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md +++ /dev/null @@ -1 +0,0 @@ - diff --git a/win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md b/win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md deleted file mode 100644 index 2f05ebd1..00000000 --- a/win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md +++ /dev/null @@ -1 +0,0 @@ - diff --git a/win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/framework/monitor/《芋道 Spring Boot 监控工具 Admin 入门》.md b/win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/framework/monitor/《芋道 Spring Boot 监控工具 Admin 入门》.md deleted file mode 100644 index 5641db1a..00000000 --- a/win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/framework/monitor/《芋道 Spring Boot 监控工具 Admin 入门》.md +++ /dev/null @@ -1 +0,0 @@ - diff --git a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/admin/auth/AuthController.java b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/admin/auth/AuthController.java index b9eccf63..de14099c 100644 --- a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/admin/auth/AuthController.java +++ b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/admin/auth/AuthController.java @@ -1,12 +1,13 @@ package com.win.module.system.controller.admin.auth; -import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import com.win.framework.common.enums.CommonStatusEnum; import com.win.framework.common.pojo.CommonResult; import com.win.framework.operatelog.core.annotations.OperateLog; import com.win.framework.security.config.SecurityProperties; -import com.win.module.system.controller.admin.auth.vo.*; +import com.win.module.system.controller.admin.auth.vo.AuthLoginReqVO; +import com.win.module.system.controller.admin.auth.vo.AuthLoginRespVO; +import com.win.module.system.controller.admin.auth.vo.AuthPermissionInfoRespVO; import com.win.module.system.convert.auth.AuthConvert; import com.win.module.system.dal.dataobject.permission.MenuDO; import com.win.module.system.dal.dataobject.permission.RoleDO; @@ -18,10 +19,9 @@ import com.win.module.system.service.permission.PermissionService; import com.win.module.system.service.permission.RoleService; import com.win.module.system.service.social.SocialUserService; import com.win.module.system.service.user.AdminUserService; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -113,45 +113,4 @@ public class AuthController { return success(AuthConvert.INSTANCE.convert(user, roles, menuList)); } - // ========== 短信登录相关 ========== - - @PostMapping("/sms-login") - @PermitAll - @Operation(summary = "使用短信验证码登录") - @OperateLog(enable = false) // 避免 Post 请求被记录操作日志 - public CommonResult smsLogin(@RequestBody @Valid AuthSmsLoginReqVO reqVO) { - return success(authService.smsLogin(reqVO)); - } - - @PostMapping("/send-sms-code") - @PermitAll - @Operation(summary = "发送手机验证码") - @OperateLog(enable = false) // 避免 Post 请求被记录操作日志 - public CommonResult sendLoginSmsCode(@RequestBody @Valid AuthSmsSendReqVO reqVO) { - authService.sendSmsCode(reqVO); - return success(true); - } - - // ========== 社交登录相关 ========== - - @GetMapping("/social-auth-redirect") - @PermitAll - @Operation(summary = "社交授权的跳转") - @Parameters({ - @Parameter(name = "type", description = "社交类型", required = true), - @Parameter(name = "redirectUri", description = "回调路径") - }) - public CommonResult socialLogin(@RequestParam("type") Integer type, - @RequestParam("redirectUri") String redirectUri) { - return CommonResult.success(socialUserService.getAuthorizeUrl(type, redirectUri)); - } - - @PostMapping("/social-login") - @PermitAll - @Operation(summary = "社交快捷登录,使用 code 授权码", description = "适合未登录的用户,但是社交账号已绑定用户") - @OperateLog(enable = false) // 避免 Post 请求被记录操作日志 - public CommonResult socialQuickLogin(@RequestBody @Valid AuthSocialLoginReqVO reqVO) { - return success(authService.socialLogin(reqVO)); - } - } \ No newline at end of file diff --git a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/admin/auth/vo/AuthLoginReqVO.java b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/admin/auth/vo/AuthLoginReqVO.java index f4ad9267..48ad9233 100644 --- a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/admin/auth/vo/AuthLoginReqVO.java +++ b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/admin/auth/vo/AuthLoginReqVO.java @@ -1,8 +1,5 @@ package com.win.module.system.controller.admin.auth.vo; -import cn.hutool.core.util.StrUtil; -import com.win.framework.common.validation.InEnum; -import com.win.module.system.enums.social.SocialTypeEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; @@ -10,7 +7,6 @@ import lombok.Data; import lombok.NoArgsConstructor; import org.hibernate.validator.constraints.Length; -import javax.validation.constraints.AssertTrue; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.Pattern; @@ -39,31 +35,9 @@ public class AuthLoginReqVO { @NotEmpty(message = "验证码不能为空", groups = CodeEnableGroup.class) private String captchaVerification; - // ========== 绑定社交登录时,需要传递如下参数 ========== - - @Schema(description = "社交平台的类型,参见 SocialTypeEnum 枚举值", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") - @InEnum(SocialTypeEnum.class) - private Integer socialType; - - @Schema(description = "授权码", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private String socialCode; - - @Schema(description = "state", requiredMode = Schema.RequiredMode.REQUIRED, example = "9b2ffbc1-7425-4155-9894-9d5c08541d62") - private String socialState; - /** * 开启验证码的 Group */ public interface CodeEnableGroup {} - @AssertTrue(message = "授权码不能为空") - public boolean isSocialCodeValid() { - return socialType == null || StrUtil.isNotEmpty(socialCode); - } - - @AssertTrue(message = "授权 state 不能为空") - public boolean isSocialState() { - return socialType == null || StrUtil.isNotEmpty(socialState); - } - } \ No newline at end of file diff --git a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/admin/auth/vo/AuthSocialLoginReqVO.java b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/admin/auth/vo/AuthSocialLoginReqVO.java deleted file mode 100644 index 66361d35..00000000 --- a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/admin/auth/vo/AuthSocialLoginReqVO.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.win.module.system.controller.admin.auth.vo; - -import com.win.framework.common.validation.InEnum; -import com.win.module.system.enums.social.SocialTypeEnum; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 社交绑定登录 Request VO,使用 code 授权码 + 账号密码") -@Data -@NoArgsConstructor -@AllArgsConstructor -@Builder -public class AuthSocialLoginReqVO { - - @Schema(description = "社交平台的类型,参见 UserSocialTypeEnum 枚举值", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") - @InEnum(SocialTypeEnum.class) - @NotNull(message = "社交平台的类型不能为空") - private Integer type; - - @Schema(description = "授权码", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotEmpty(message = "授权码不能为空") - private String code; - - @Schema(description = "state", requiredMode = Schema.RequiredMode.REQUIRED, example = "9b2ffbc1-7425-4155-9894-9d5c08541d62") - @NotEmpty(message = "state 不能为空") - private String state; - -} diff --git a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/convert/auth/AuthConvert.java b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/convert/auth/AuthConvert.java index e535b849..f21dfe61 100644 --- a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/convert/auth/AuthConvert.java +++ b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/convert/auth/AuthConvert.java @@ -1,9 +1,7 @@ package com.win.module.system.convert.auth; -import com.win.module.system.api.sms.dto.code.SmsCodeSendReqDTO; -import com.win.module.system.api.sms.dto.code.SmsCodeUseReqDTO; -import com.win.module.system.api.social.dto.SocialUserBindReqDTO; -import com.win.module.system.controller.admin.auth.vo.*; +import com.win.module.system.controller.admin.auth.vo.AuthLoginRespVO; +import com.win.module.system.controller.admin.auth.vo.AuthPermissionInfoRespVO; import com.win.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO; import com.win.module.system.dal.dataobject.permission.MenuDO; import com.win.module.system.dal.dataobject.permission.RoleDO; @@ -74,10 +72,4 @@ public interface AuthConvert { return filterList(treeNodeMap.values(), node -> ID_ROOT.equals(node.getParentId())); } - SocialUserBindReqDTO convert(Long userId, Integer userType, AuthSocialLoginReqVO reqVO); - - SmsCodeSendReqDTO convert(AuthSmsSendReqVO reqVO); - - SmsCodeUseReqDTO convert(AuthSmsLoginReqVO reqVO, Integer scene, String usedIp); - } diff --git a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/auth/AdminAuthService.java b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/auth/AdminAuthService.java index c2b97468..0c19370b 100644 --- a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/auth/AdminAuthService.java +++ b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/auth/AdminAuthService.java @@ -39,29 +39,6 @@ public interface AdminAuthService { */ void logout(String token, Integer logType); - /** - * 短信验证码发送 - * - * @param reqVO 发送请求 - */ - void sendSmsCode(AuthSmsSendReqVO reqVO); - - /** - * 短信登录 - * - * @param reqVO 登录信息 - * @return 登录结果 - */ - AuthLoginRespVO smsLogin(AuthSmsLoginReqVO reqVO) ; - - /** - * 社交快捷登录,使用 code 授权码 - * - * @param reqVO 登录信息 - * @return 登录结果 - */ - AuthLoginRespVO socialLogin(@Valid AuthSocialLoginReqVO reqVO); - /** * 刷新访问令牌 * diff --git a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/auth/AdminAuthServiceImpl.java b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/auth/AdminAuthServiceImpl.java index c07e6016..999bda19 100644 --- a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/auth/AdminAuthServiceImpl.java +++ b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/auth/AdminAuthServiceImpl.java @@ -1,6 +1,7 @@ package com.win.module.system.service.auth; import cn.hutool.core.util.ObjectUtil; +import com.google.common.annotations.VisibleForTesting; import com.win.framework.common.enums.CommonStatusEnum; import com.win.framework.common.enums.UserTypeEnum; import com.win.framework.common.util.monitor.TracerUtils; @@ -8,16 +9,14 @@ import com.win.framework.common.util.servlet.ServletUtils; import com.win.framework.common.util.validation.ValidationUtils; import com.win.module.system.api.logger.dto.LoginLogCreateReqDTO; import com.win.module.system.api.sms.SmsCodeApi; -import com.win.module.system.api.social.dto.SocialUserBindReqDTO; -import com.win.module.system.api.social.dto.SocialUserRespDTO; -import com.win.module.system.controller.admin.auth.vo.*; +import com.win.module.system.controller.admin.auth.vo.AuthLoginReqVO; +import com.win.module.system.controller.admin.auth.vo.AuthLoginRespVO; import com.win.module.system.convert.auth.AuthConvert; import com.win.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO; import com.win.module.system.dal.dataobject.user.AdminUserDO; import com.win.module.system.enums.logger.LoginLogTypeEnum; import com.win.module.system.enums.logger.LoginResultEnum; import com.win.module.system.enums.oauth2.OAuth2ClientConstants; -import com.win.module.system.enums.sms.SmsSceneEnum; import com.win.module.system.service.logger.LoginLogService; import com.win.module.system.service.member.MemberService; import com.win.module.system.service.oauth2.OAuth2TokenService; @@ -26,7 +25,6 @@ import com.win.module.system.service.user.AdminUserService; import com.xingyuv.captcha.model.common.ResponseModel; import com.xingyuv.captcha.model.vo.CaptchaVO; import com.xingyuv.captcha.service.CaptchaService; -import com.google.common.annotations.VisibleForTesting; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -36,7 +34,6 @@ import javax.validation.Validator; import java.util.Objects; import static com.win.framework.common.exception.util.ServiceExceptionUtil.exception; -import static com.win.framework.common.util.servlet.ServletUtils.getClientIP; import static com.win.module.system.enums.ErrorCodeConstants.*; /** @@ -96,44 +93,12 @@ public class AdminAuthServiceImpl implements AdminAuthService { public AuthLoginRespVO login(AuthLoginReqVO reqVO) { // 校验验证码 validateCaptcha(reqVO); - // 使用账号密码,进行登录 AdminUserDO user = authenticate(reqVO.getUsername(), reqVO.getPassword()); - - // 如果 socialType 非空,说明需要绑定社交用户 - if (reqVO.getSocialType() != null) { - socialUserService.bindSocialUser(new SocialUserBindReqDTO(user.getId(), getUserType().getValue(), - reqVO.getSocialType(), reqVO.getSocialCode(), reqVO.getSocialState())); - } // 创建 Token 令牌,记录登录日志 return createTokenAfterLoginSuccess(user.getId(), reqVO.getUsername(), LoginLogTypeEnum.LOGIN_USERNAME); } - @Override - public void sendSmsCode(AuthSmsSendReqVO reqVO) { - // 登录场景,验证是否存在 - if (userService.getUserByMobile(reqVO.getMobile()) == null) { - throw exception(AUTH_MOBILE_NOT_EXISTS); - } - // 发送验证码 - smsCodeApi.sendSmsCode(AuthConvert.INSTANCE.convert(reqVO).setCreateIp(getClientIP())); - } - - @Override - public AuthLoginRespVO smsLogin(AuthSmsLoginReqVO reqVO) { - // 校验验证码 - smsCodeApi.useSmsCode(AuthConvert.INSTANCE.convert(reqVO, SmsSceneEnum.ADMIN_MEMBER_LOGIN.getScene(), getClientIP())); - - // 获得用户信息 - AdminUserDO user = userService.getUserByMobile(reqVO.getMobile()); - if (user == null) { - throw exception(USER_NOT_EXISTS); - } - - // 创建 Token 令牌,记录登录日志 - return createTokenAfterLoginSuccess(user.getId(), reqVO.getMobile(), LoginLogTypeEnum.LOGIN_MOBILE); - } - private void createLoginLog(Long userId, String username, LoginLogTypeEnum logTypeEnum, LoginResultEnum loginResult) { // 插入登录日志 @@ -153,25 +118,6 @@ public class AdminAuthServiceImpl implements AdminAuthService { } } - @Override - public AuthLoginRespVO socialLogin(AuthSocialLoginReqVO reqVO) { - // 使用 code 授权码,进行登录。然后,获得到绑定的用户编号 - SocialUserRespDTO socialUser = socialUserService.getSocialUser(UserTypeEnum.ADMIN.getValue(), reqVO.getType(), - reqVO.getCode(), reqVO.getState()); - if (socialUser == null) { - throw exception(AUTH_THIRD_LOGIN_NOT_BIND); - } - - // 获得用户 - AdminUserDO user = userService.getUser(socialUser.getUserId()); - if (user == null) { - throw exception(USER_NOT_EXISTS); - } - - // 创建 Token 令牌,记录登录日志 - return createTokenAfterLoginSuccess(user.getId(), user.getUsername(), LoginLogTypeEnum.LOGIN_SOCIAL); - } - @VisibleForTesting void validateCaptcha(AuthLoginReqVO reqVO) { // 如果验证码关闭,则不进行校验 diff --git a/win-server/src/main/resources/application.yaml b/win-server/src/main/resources/application.yaml index 629b9543..ba03eb84 100644 --- a/win-server/src/main/resources/application.yaml +++ b/win-server/src/main/resources/application.yaml @@ -136,7 +136,7 @@ win: license: MIT license-url: https://gitee.com/zhijiantianya/ruoyi-vue-pro/blob/master/LICENSE captcha: - enable: false # 验证码的开关,默认为 true + enable: true # 验证码的开关,默认为 true codegen: base-package: ${win.info.base-package} db-schemas: ${spring.datasource.dynamic.datasource.master.name} @@ -206,6 +206,8 @@ win: - rep_demo_jianpiao - tmp_report_data_1 - tmp_report_data_income + - tmp_report_data_income + - system_serial_number sms-code: # 短信验证码相关的配置项 expire-times: 10m send-frequency: 1m