From 2b4aeea915e1ef9b7dcec6fd66c45b95c72165fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Thu, 2 Nov 2023 12:34:48 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20=E9=87=8D?= =?UTF-8?q?=E6=9E=84=E7=99=BB=E5=BD=95=E7=AD=96=E7=95=A5=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=89=A9=E5=B1=95=E6=80=A7=E9=99=8D=E4=BD=8E=E5=A4=8D=E6=9D=82?= =?UTF-8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/controller/TokenController.java | 24 +++--- .../org/dromara/auth/form/EmailLoginBody.java | 14 ++-- .../dromara/auth/form/PasswordLoginBody.java | 34 ++++++++ .../org/dromara/auth/form/RegisterBody.java | 18 +++++ .../org/dromara/auth/form/SmsLoginBody.java | 13 ++- .../dromara/auth/form/SocialLoginBody.java | 36 +++++++++ .../org/dromara/auth/form/XcxLoginBody.java | 29 +++++++ .../dromara/auth/service/IAuthStrategy.java | 16 +--- .../auth/service/impl/EmailAuthStrategy.java | 13 ++- .../service/impl/PasswordAuthStrategy.java | 13 ++- .../auth/service/impl/SmsAuthStrategy.java | 13 ++- .../auth/service/impl/SocialAuthStrategy.java | 23 +++--- .../auth/service/impl/XcxAuthStrategy.java | 16 ++-- .../common/core/domain/model/LoginBody.java | 80 +------------------ .../common/core/validate/auth/EmailGroup.java | 7 -- .../core/validate/auth/PasswordGroup.java | 7 -- .../common/core/validate/auth/SmsGroup.java | 7 -- .../core/validate/auth/SocialGroup.java | 4 - .../core/validate/auth/WechatGroup.java | 7 -- .../common/social/utils/SocialUtils.java | 9 +-- 20 files changed, 185 insertions(+), 198 deletions(-) create mode 100644 ruoyi-auth/src/main/java/org/dromara/auth/form/PasswordLoginBody.java create mode 100644 ruoyi-auth/src/main/java/org/dromara/auth/form/SocialLoginBody.java create mode 100644 ruoyi-auth/src/main/java/org/dromara/auth/form/XcxLoginBody.java delete mode 100644 ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/EmailGroup.java delete mode 100644 ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/PasswordGroup.java delete mode 100644 ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/SmsGroup.java delete mode 100644 ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/SocialGroup.java delete mode 100644 ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/WechatGroup.java diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/controller/TokenController.java b/ruoyi-auth/src/main/java/org/dromara/auth/controller/TokenController.java index e2b54a4d..8a3e896b 100644 --- a/ruoyi-auth/src/main/java/org/dromara/auth/controller/TokenController.java +++ b/ruoyi-auth/src/main/java/org/dromara/auth/controller/TokenController.java @@ -14,15 +14,14 @@ import org.dromara.auth.domain.vo.LoginTenantVo; import org.dromara.auth.domain.vo.LoginVo; import org.dromara.auth.domain.vo.TenantListVo; import org.dromara.auth.form.RegisterBody; +import org.dromara.auth.form.SocialLoginBody; import org.dromara.auth.service.IAuthStrategy; import org.dromara.auth.service.SysLoginService; import org.dromara.common.core.constant.UserConstants; import org.dromara.common.core.domain.R; import org.dromara.common.core.domain.model.LoginBody; -import org.dromara.common.core.utils.MapstructUtils; -import org.dromara.common.core.utils.MessageUtils; -import org.dromara.common.core.utils.StreamUtils; -import org.dromara.common.core.utils.StringUtils; +import org.dromara.common.core.utils.*; +import org.dromara.common.json.utils.JsonUtils; import org.dromara.common.social.config.properties.SocialLoginConfigProperties; import org.dromara.common.social.config.properties.SocialProperties; import org.dromara.common.social.utils.SocialUtils; @@ -64,9 +63,14 @@ public class TokenController { /** * 登录方法 + * + * @param body 登录信息 + * @return 结果 */ - @PostMapping("login") - public R login(@Validated @RequestBody LoginBody loginBody) { + @PostMapping("/login") + public R login(@Validated @RequestBody String body) { + LoginBody loginBody = JsonUtils.parseObject(body, LoginBody.class); + ValidatorUtils.validate(loginBody); // 授权类型和客户端id String clientId = loginBody.getClientId(); String grantType = loginBody.getGrantType(); @@ -82,7 +86,7 @@ public class TokenController { // 校验租户 sysLoginService.checkTenant(loginBody.getTenantId()); // 登录 - return R.ok(IAuthStrategy.login(loginBody, clientVo)); + return R.ok(IAuthStrategy.login(body, clientVo, grantType)); } /** @@ -109,9 +113,11 @@ public class TokenController { * @return 结果 */ @PostMapping("/social/callback") - public R socialCallback(@RequestBody LoginBody loginBody) { + public R socialCallback(@RequestBody SocialLoginBody loginBody) { // 获取第三方登录信息 - AuthResponse response = SocialUtils.loginAuth(loginBody, socialProperties); + AuthResponse response = SocialUtils.loginAuth( + loginBody.getSource(), loginBody.getSocialCode(), + loginBody.getSocialState(), socialProperties); AuthUser authUserData = response.getData(); // 判断授权响应是否成功 if (!response.ok()) { diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/form/EmailLoginBody.java b/ruoyi-auth/src/main/java/org/dromara/auth/form/EmailLoginBody.java index b0bcd85a..931e2364 100644 --- a/ruoyi-auth/src/main/java/org/dromara/auth/form/EmailLoginBody.java +++ b/ruoyi-auth/src/main/java/org/dromara/auth/form/EmailLoginBody.java @@ -1,9 +1,10 @@ package org.dromara.auth.form; -import lombok.Data; - import jakarta.validation.constraints.Email; import jakarta.validation.constraints.NotBlank; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.dromara.common.core.domain.model.LoginBody; /** * 邮件登录对象 @@ -12,13 +13,8 @@ import jakarta.validation.constraints.NotBlank; */ @Data -public class EmailLoginBody { - - /** - * 租户ID - */ - @NotBlank(message = "{tenant.number.not.blank}") - private String tenantId; +@EqualsAndHashCode(callSuper = true) +public class EmailLoginBody extends LoginBody { /** * 邮箱 diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/form/PasswordLoginBody.java b/ruoyi-auth/src/main/java/org/dromara/auth/form/PasswordLoginBody.java new file mode 100644 index 00000000..edb7ab23 --- /dev/null +++ b/ruoyi-auth/src/main/java/org/dromara/auth/form/PasswordLoginBody.java @@ -0,0 +1,34 @@ +package org.dromara.auth.form; + +import jakarta.validation.constraints.NotBlank; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.dromara.common.core.domain.model.LoginBody; +import org.hibernate.validator.constraints.Length; + +import static org.dromara.common.core.constant.UserConstants.*; + +/** + * 密码登录对象 + * + * @author Lion Li + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class PasswordLoginBody extends LoginBody { + + /** + * 用户名 + */ + @NotBlank(message = "{user.username.not.blank}") + @Length(min = USERNAME_MIN_LENGTH, max = USERNAME_MAX_LENGTH, message = "{user.username.length.valid}") + private String username; + + /** + * 用户密码 + */ + @NotBlank(message = "{user.password.not.blank}") + @Length(min = PASSWORD_MIN_LENGTH, max = PASSWORD_MAX_LENGTH, message = "{user.password.length.valid}") + private String password; + +} diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/form/RegisterBody.java b/ruoyi-auth/src/main/java/org/dromara/auth/form/RegisterBody.java index 0971dc1d..386c0fc7 100644 --- a/ruoyi-auth/src/main/java/org/dromara/auth/form/RegisterBody.java +++ b/ruoyi-auth/src/main/java/org/dromara/auth/form/RegisterBody.java @@ -1,8 +1,12 @@ package org.dromara.auth.form; +import jakarta.validation.constraints.NotBlank; import lombok.Data; import lombok.EqualsAndHashCode; import org.dromara.common.core.domain.model.LoginBody; +import org.hibernate.validator.constraints.Length; + +import static org.dromara.common.core.constant.UserConstants.*; /** * 用户注册对象 @@ -13,6 +17,20 @@ import org.dromara.common.core.domain.model.LoginBody; @EqualsAndHashCode(callSuper = true) public class RegisterBody extends LoginBody { + /** + * 用户名 + */ + @NotBlank(message = "{user.username.not.blank}") + @Length(min = USERNAME_MIN_LENGTH, max = USERNAME_MAX_LENGTH, message = "{user.username.length.valid}") + private String username; + + /** + * 用户密码 + */ + @NotBlank(message = "{user.password.not.blank}") + @Length(min = PASSWORD_MIN_LENGTH, max = PASSWORD_MAX_LENGTH, message = "{user.password.length.valid}") + private String password; + private String userType; } diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/form/SmsLoginBody.java b/ruoyi-auth/src/main/java/org/dromara/auth/form/SmsLoginBody.java index fe829941..48e262f3 100644 --- a/ruoyi-auth/src/main/java/org/dromara/auth/form/SmsLoginBody.java +++ b/ruoyi-auth/src/main/java/org/dromara/auth/form/SmsLoginBody.java @@ -1,8 +1,9 @@ package org.dromara.auth.form; -import lombok.Data; - import jakarta.validation.constraints.NotBlank; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.dromara.common.core.domain.model.LoginBody; /** * 短信登录对象 @@ -11,12 +12,8 @@ import jakarta.validation.constraints.NotBlank; */ @Data -public class SmsLoginBody { - - /** - * 租户ID - */ - private String tenantId; +@EqualsAndHashCode(callSuper = true) +public class SmsLoginBody extends LoginBody { /** * 手机号 diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/form/SocialLoginBody.java b/ruoyi-auth/src/main/java/org/dromara/auth/form/SocialLoginBody.java new file mode 100644 index 00000000..cbd61c93 --- /dev/null +++ b/ruoyi-auth/src/main/java/org/dromara/auth/form/SocialLoginBody.java @@ -0,0 +1,36 @@ +package org.dromara.auth.form; + +import jakarta.validation.constraints.NotBlank; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.dromara.common.core.domain.model.LoginBody; + +/** + * 三方登录对象 + * + * @author Lion Li + */ + +@Data +@EqualsAndHashCode(callSuper = true) +public class SocialLoginBody extends LoginBody { + + /** + * 第三方登录平台 + */ + @NotBlank(message = "{social.source.not.blank}") + private String source; + + /** + * 第三方登录code + */ + @NotBlank(message = "{social.code.not.blank}") + private String socialCode; + + /** + * 第三方登录socialState + */ + @NotBlank(message = "{social.state.not.blank}") + private String socialState; + +} diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/form/XcxLoginBody.java b/ruoyi-auth/src/main/java/org/dromara/auth/form/XcxLoginBody.java new file mode 100644 index 00000000..c68306c1 --- /dev/null +++ b/ruoyi-auth/src/main/java/org/dromara/auth/form/XcxLoginBody.java @@ -0,0 +1,29 @@ +package org.dromara.auth.form; + +import jakarta.validation.constraints.NotBlank; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.dromara.common.core.domain.model.LoginBody; + +/** + * 三方登录对象 + * + * @author Lion Li + */ + +@Data +@EqualsAndHashCode(callSuper = true) +public class XcxLoginBody extends LoginBody { + + /** + * 小程序id(多个小程序时使用) + */ + private String appid; + + /** + * 小程序code + */ + @NotBlank(message = "{xcx.code.not.blank}") + private String xcxCode; + +} diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/service/IAuthStrategy.java b/ruoyi-auth/src/main/java/org/dromara/auth/service/IAuthStrategy.java index 470acf1b..9d2816ee 100644 --- a/ruoyi-auth/src/main/java/org/dromara/auth/service/IAuthStrategy.java +++ b/ruoyi-auth/src/main/java/org/dromara/auth/service/IAuthStrategy.java @@ -1,7 +1,6 @@ package org.dromara.auth.service; import org.dromara.auth.domain.vo.LoginVo; -import org.dromara.common.core.domain.model.LoginBody; import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.utils.SpringUtils; import org.dromara.system.api.domain.vo.RemoteClientVo; @@ -18,27 +17,20 @@ public interface IAuthStrategy { /** * 登录 */ - static LoginVo login(LoginBody loginBody, RemoteClientVo client) { + static LoginVo login(String body, RemoteClientVo client, String grantType) { // 授权类型和客户端id - String clientId = loginBody.getClientId(); - String grantType = loginBody.getGrantType(); + String clientId = client.getClientId(); String beanName = grantType + BASE_NAME; if (!SpringUtils.containsBean(beanName)) { throw new ServiceException("授权类型不正确!"); } IAuthStrategy instance = SpringUtils.getBean(beanName); - instance.validate(loginBody); - return instance.login(clientId, loginBody, client); + return instance.login(clientId, body, client); } - /** - * 参数校验 - */ - void validate(LoginBody loginBody); - /** * 登录 */ - LoginVo login(String clientId, LoginBody loginBody, RemoteClientVo client); + LoginVo login(String clientId, String body, RemoteClientVo client); } diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/EmailAuthStrategy.java b/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/EmailAuthStrategy.java index 200d0d4e..3a4c8fd1 100644 --- a/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/EmailAuthStrategy.java +++ b/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/EmailAuthStrategy.java @@ -6,7 +6,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.auth.domain.vo.LoginVo; -import org.dromara.common.core.domain.model.LoginBody; +import org.dromara.auth.form.EmailLoginBody; import org.dromara.auth.service.IAuthStrategy; import org.dromara.auth.service.SysLoginService; import org.dromara.common.core.constant.Constants; @@ -17,7 +17,7 @@ import org.dromara.common.core.utils.MessageUtils; import org.dromara.common.core.utils.ServletUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.core.utils.ValidatorUtils; -import org.dromara.common.core.validate.auth.EmailGroup; +import org.dromara.common.json.utils.JsonUtils; import org.dromara.common.redis.utils.RedisUtils; import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.system.api.RemoteUserService; @@ -41,12 +41,9 @@ public class EmailAuthStrategy implements IAuthStrategy { private RemoteUserService remoteUserService; @Override - public void validate(LoginBody loginBody) { - ValidatorUtils.validate(loginBody, EmailGroup.class); - } - - @Override - public LoginVo login(String clientId, LoginBody loginBody, RemoteClientVo client) { + public LoginVo login(String clientId, String body, RemoteClientVo client) { + EmailLoginBody loginBody = JsonUtils.parseObject(body, EmailLoginBody.class); + ValidatorUtils.validate(loginBody); String tenantId = loginBody.getTenantId(); String email = loginBody.getEmail(); String emailCode = loginBody.getEmailCode(); diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/PasswordAuthStrategy.java b/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/PasswordAuthStrategy.java index c083d015..14dd4347 100644 --- a/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/PasswordAuthStrategy.java +++ b/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/PasswordAuthStrategy.java @@ -7,12 +7,12 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.auth.domain.vo.LoginVo; +import org.dromara.auth.form.PasswordLoginBody; import org.dromara.auth.properties.CaptchaProperties; import org.dromara.auth.service.IAuthStrategy; import org.dromara.auth.service.SysLoginService; import org.dromara.common.core.constant.Constants; import org.dromara.common.core.constant.GlobalConstants; -import org.dromara.common.core.domain.model.LoginBody; import org.dromara.common.core.enums.LoginType; import org.dromara.common.core.exception.CaptchaException; import org.dromara.common.core.exception.user.CaptchaExpireException; @@ -20,7 +20,7 @@ import org.dromara.common.core.utils.MessageUtils; import org.dromara.common.core.utils.ServletUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.core.utils.ValidatorUtils; -import org.dromara.common.core.validate.auth.PasswordGroup; +import org.dromara.common.json.utils.JsonUtils; import org.dromara.common.redis.utils.RedisUtils; import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.system.api.RemoteUserService; @@ -46,12 +46,9 @@ public class PasswordAuthStrategy implements IAuthStrategy { private RemoteUserService remoteUserService; @Override - public void validate(LoginBody loginBody) { - ValidatorUtils.validate(loginBody, PasswordGroup.class); - } - - @Override - public LoginVo login(String clientId, LoginBody loginBody, RemoteClientVo client) { + public LoginVo login(String clientId, String body, RemoteClientVo client) { + PasswordLoginBody loginBody = JsonUtils.parseObject(body, PasswordLoginBody.class); + ValidatorUtils.validate(loginBody); String tenantId = loginBody.getTenantId(); String username = loginBody.getUsername(); String password = loginBody.getPassword(); diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/SmsAuthStrategy.java b/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/SmsAuthStrategy.java index 0d6a385d..f1830ba0 100644 --- a/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/SmsAuthStrategy.java +++ b/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/SmsAuthStrategy.java @@ -6,7 +6,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.auth.domain.vo.LoginVo; -import org.dromara.common.core.domain.model.LoginBody; +import org.dromara.auth.form.SmsLoginBody; import org.dromara.auth.service.IAuthStrategy; import org.dromara.auth.service.SysLoginService; import org.dromara.common.core.constant.Constants; @@ -17,7 +17,7 @@ import org.dromara.common.core.utils.MessageUtils; import org.dromara.common.core.utils.ServletUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.core.utils.ValidatorUtils; -import org.dromara.common.core.validate.auth.SmsGroup; +import org.dromara.common.json.utils.JsonUtils; import org.dromara.common.redis.utils.RedisUtils; import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.system.api.RemoteUserService; @@ -41,12 +41,9 @@ public class SmsAuthStrategy implements IAuthStrategy { private RemoteUserService remoteUserService; @Override - public void validate(LoginBody loginBody) { - ValidatorUtils.validate(loginBody, SmsGroup.class); - } - - @Override - public LoginVo login(String clientId, LoginBody loginBody, RemoteClientVo client) { + public LoginVo login(String clientId, String body, RemoteClientVo client) { + SmsLoginBody loginBody = JsonUtils.parseObject(body, SmsLoginBody.class); + ValidatorUtils.validate(loginBody); String tenantId = loginBody.getTenantId(); String phonenumber = loginBody.getPhonenumber(); String smsCode = loginBody.getSmsCode(); diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/SocialAuthStrategy.java b/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/SocialAuthStrategy.java index 031cccd8..61999757 100644 --- a/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/SocialAuthStrategy.java +++ b/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/SocialAuthStrategy.java @@ -13,15 +13,15 @@ import me.zhyd.oauth.model.AuthResponse; import me.zhyd.oauth.model.AuthUser; import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.auth.domain.vo.LoginVo; +import org.dromara.auth.form.SocialLoginBody; import org.dromara.auth.service.IAuthStrategy; import org.dromara.auth.service.SysLoginService; import org.dromara.common.core.constant.Constants; -import org.dromara.common.core.domain.model.LoginBody; import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.utils.MessageUtils; import org.dromara.common.core.utils.ServletUtils; import org.dromara.common.core.utils.ValidatorUtils; -import org.dromara.common.core.validate.auth.SocialGroup; +import org.dromara.common.json.utils.JsonUtils; import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.common.social.config.properties.SocialProperties; import org.dromara.common.social.utils.SocialUtils; @@ -50,21 +50,20 @@ public class SocialAuthStrategy implements IAuthStrategy { @DubboReference private RemoteUserService remoteUserService; - @Override - public void validate(LoginBody loginBody) { - ValidatorUtils.validate(loginBody, SocialGroup.class); - } - /** * 登录-第三方授权登录 * - * @param clientId 客户端id - * @param loginBody 登录信息 - * @param client 客户端信息 + * @param clientId 客户端id + * @param body 登录信息 + * @param client 客户端信息 */ @Override - public LoginVo login(String clientId, LoginBody loginBody, RemoteClientVo client) { - AuthResponse response = SocialUtils.loginAuth(loginBody, socialProperties); + public LoginVo login(String clientId, String body, RemoteClientVo client) { + SocialLoginBody loginBody = JsonUtils.parseObject(body, SocialLoginBody.class); + ValidatorUtils.validate(loginBody); + AuthResponse response = SocialUtils.loginAuth( + loginBody.getSource(), loginBody.getSocialCode(), + loginBody.getSocialState(), socialProperties); if (!response.ok()) { throw new ServiceException(response.getMsg()); } diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/XcxAuthStrategy.java b/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/XcxAuthStrategy.java index 30f5f585..ce698c97 100644 --- a/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/XcxAuthStrategy.java +++ b/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/XcxAuthStrategy.java @@ -6,14 +6,14 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.auth.domain.vo.LoginVo; -import org.dromara.common.core.domain.model.LoginBody; +import org.dromara.auth.form.XcxLoginBody; import org.dromara.auth.service.IAuthStrategy; import org.dromara.auth.service.SysLoginService; import org.dromara.common.core.constant.Constants; import org.dromara.common.core.utils.MessageUtils; import org.dromara.common.core.utils.ServletUtils; import org.dromara.common.core.utils.ValidatorUtils; -import org.dromara.common.core.validate.auth.WechatGroup; +import org.dromara.common.json.utils.JsonUtils; import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.system.api.RemoteUserService; import org.dromara.system.api.domain.vo.RemoteClientVo; @@ -36,14 +36,14 @@ public class XcxAuthStrategy implements IAuthStrategy { private RemoteUserService remoteUserService; @Override - public void validate(LoginBody loginBody) { - ValidatorUtils.validate(loginBody, WechatGroup.class); - } - - @Override - public LoginVo login(String clientId, LoginBody loginBody, RemoteClientVo client) { + public LoginVo login(String clientId, String body, RemoteClientVo client) { + XcxLoginBody loginBody = JsonUtils.parseObject(body, XcxLoginBody.class); + ValidatorUtils.validate(loginBody); // xcxCode 为 小程序调用 wx.login 授权后获取 String xcxCode = loginBody.getXcxCode(); + // 多个小程序识别使用 + String appid = loginBody.getAppid(); + // todo 以下自行实现 // 校验 appid + appsrcret + xcxCode 调用登录凭证校验接口 获取 session_key 与 openid String openid = ""; diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/domain/model/LoginBody.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/domain/model/LoginBody.java index 4f0283b7..ee612fdb 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/domain/model/LoginBody.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/domain/model/LoginBody.java @@ -1,13 +1,8 @@ package org.dromara.common.core.domain.model; -import jakarta.validation.constraints.Email; -import org.dromara.common.core.constant.UserConstants; +import jakarta.validation.constraints.NotBlank; import lombok.Data; import lombok.NoArgsConstructor; -import org.dromara.common.core.validate.auth.*; -import org.hibernate.validator.constraints.Length; - -import jakarta.validation.constraints.NotBlank; /** * 用户登录对象 @@ -24,16 +19,6 @@ public class LoginBody { @NotBlank(message = "{auth.clientid.not.blank}") private String clientId; - /** - * 客户端key - */ - private String clientKey; - - /** - * 客户端秘钥 - */ - private String clientSecret; - /** * 授权类型 */ @@ -45,20 +30,6 @@ public class LoginBody { */ private String tenantId; - /** - * 用户名 - */ - @NotBlank(message = "{user.username.not.blank}", groups = {PasswordGroup.class}) - @Length(min = UserConstants.USERNAME_MIN_LENGTH, max = UserConstants.USERNAME_MAX_LENGTH, message = "{user.username.length.valid}", groups = {PasswordGroup.class}) - private String username; - - /** - * 用户密码 - */ - @NotBlank(message = "{user.password.not.blank}", groups = {PasswordGroup.class}) - @Length(min = UserConstants.PASSWORD_MIN_LENGTH, max = UserConstants.PASSWORD_MAX_LENGTH, message = "{user.password.length.valid}", groups = {PasswordGroup.class}) - private String password; - /** * 验证码 */ @@ -69,53 +40,4 @@ public class LoginBody { */ private String uuid; - /** - * 手机号 - */ - @NotBlank(message = "{user.phonenumber.not.blank}", groups = {SmsGroup.class}) - private String phonenumber; - - /** - * 短信code - */ - @NotBlank(message = "{sms.code.not.blank}", groups = {SmsGroup.class}) - private String smsCode; - - /** - * 邮箱 - */ - @NotBlank(message = "{user.email.not.blank}", groups = {EmailGroup.class}) - @Email(message = "{user.email.not.valid}") - private String email; - - /** - * 邮箱code - */ - @NotBlank(message = "{email.code.not.blank}", groups = {EmailGroup.class}) - private String emailCode; - - /** - * 小程序code - */ - @NotBlank(message = "{xcx.code.not.blank}", groups = {WechatGroup.class}) - private String xcxCode; - - /** - * 第三方登录平台 - */ - @NotBlank(message = "{social.source.not.blank}" , groups = {SocialGroup.class}) - private String source; - - /** - * 第三方登录code - */ - @NotBlank(message = "{social.code.not.blank}" , groups = {SocialGroup.class}) - private String socialCode; - - /** - * 第三方登录socialState - */ - @NotBlank(message = "{social.state.not.blank}" , groups = {SocialGroup.class}) - private String socialState; - } diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/EmailGroup.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/EmailGroup.java deleted file mode 100644 index 345a8e7c..00000000 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/EmailGroup.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.dromara.common.core.validate.auth; - -/** - * @author Michelle.Chung - */ -public interface EmailGroup { -} diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/PasswordGroup.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/PasswordGroup.java deleted file mode 100644 index b2c06b80..00000000 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/PasswordGroup.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.dromara.common.core.validate.auth; - -/** - * @author Michelle.Chung - */ -public interface PasswordGroup { -} diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/SmsGroup.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/SmsGroup.java deleted file mode 100644 index e6fc6576..00000000 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/SmsGroup.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.dromara.common.core.validate.auth; - -/** - * @author Michelle.Chung - */ -public interface SmsGroup { -} diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/SocialGroup.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/SocialGroup.java deleted file mode 100644 index 2b19ffe3..00000000 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/SocialGroup.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.dromara.common.core.validate.auth; - -public interface SocialGroup { -} diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/WechatGroup.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/WechatGroup.java deleted file mode 100644 index 1955de21..00000000 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/validate/auth/WechatGroup.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.dromara.common.core.validate.auth; - -/** - * @author Michelle.Chung - */ -public interface WechatGroup { -} diff --git a/ruoyi-common/ruoyi-common-social/src/main/java/org/dromara/common/social/utils/SocialUtils.java b/ruoyi-common/ruoyi-common-social/src/main/java/org/dromara/common/social/utils/SocialUtils.java index 0c636c25..572a5d09 100644 --- a/ruoyi-common/ruoyi-common-social/src/main/java/org/dromara/common/social/utils/SocialUtils.java +++ b/ruoyi-common/ruoyi-common-social/src/main/java/org/dromara/common/social/utils/SocialUtils.java @@ -7,7 +7,6 @@ import me.zhyd.oauth.model.AuthCallback; import me.zhyd.oauth.model.AuthResponse; import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.request.*; -import org.dromara.common.core.domain.model.LoginBody; import org.dromara.common.core.utils.SpringUtils; import org.dromara.common.social.config.properties.SocialLoginConfigProperties; import org.dromara.common.social.config.properties.SocialProperties; @@ -23,11 +22,11 @@ public class SocialUtils { private static final AuthRedisStateCache STATE_CACHE = SpringUtils.getBean(AuthRedisStateCache.class); @SuppressWarnings("unchecked") - public static AuthResponse loginAuth(LoginBody loginBody, SocialProperties socialProperties) throws AuthException { - AuthRequest authRequest = getAuthRequest(loginBody.getSource(), socialProperties); + public static AuthResponse loginAuth(String source, String code, String state, SocialProperties socialProperties) throws AuthException { + AuthRequest authRequest = getAuthRequest(source, socialProperties); AuthCallback callback = new AuthCallback(); - callback.setCode(loginBody.getSocialCode()); - callback.setState(loginBody.getSocialState()); + callback.setCode(code); + callback.setState(state); return authRequest.login(callback); }