!124 发布 2.1.1 大量代码优化与bug修复 建议升级

Merge pull request !124 from 疯狂的狮子Li/dev
dev
疯狂的狮子Li 2 years ago committed by Gitee
commit 8b6a61a6bf
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

@ -2,7 +2,7 @@
<configuration default="false" name="ruoyi-auth" type="docker-deploy" factoryName="dockerfile" server-name="Docker"> <configuration default="false" name="ruoyi-auth" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile"> <deployment type="dockerfile">
<settings> <settings>
<option name="imageTag" value="ruoyi/ruoyi-auth:2.1.0" /> <option name="imageTag" value="ruoyi/ruoyi-auth:2.1.1" />
<option name="buildOnly" value="true" /> <option name="buildOnly" value="true" />
<option name="sourceFilePath" value="ruoyi-auth/Dockerfile" /> <option name="sourceFilePath" value="ruoyi-auth/Dockerfile" />
</settings> </settings>

@ -2,7 +2,7 @@
<configuration default="false" name="ruoyi-gateway" type="docker-deploy" factoryName="dockerfile" server-name="Docker"> <configuration default="false" name="ruoyi-gateway" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile"> <deployment type="dockerfile">
<settings> <settings>
<option name="imageTag" value="ruoyi/ruoyi-gateway:2.1.0" /> <option name="imageTag" value="ruoyi/ruoyi-gateway:2.1.1" />
<option name="buildOnly" value="true" /> <option name="buildOnly" value="true" />
<option name="sourceFilePath" value="ruoyi-gateway/Dockerfile" /> <option name="sourceFilePath" value="ruoyi-gateway/Dockerfile" />
</settings> </settings>

@ -2,7 +2,7 @@
<configuration default="false" name="ruoyi-gen" type="docker-deploy" factoryName="dockerfile" server-name="Docker"> <configuration default="false" name="ruoyi-gen" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile"> <deployment type="dockerfile">
<settings> <settings>
<option name="imageTag" value="ruoyi/ruoyi-gen:2.1.0" /> <option name="imageTag" value="ruoyi/ruoyi-gen:2.1.1" />
<option name="buildOnly" value="true" /> <option name="buildOnly" value="true" />
<option name="sourceFilePath" value="ruoyi-modules/ruoyi-gen/Dockerfile" /> <option name="sourceFilePath" value="ruoyi-modules/ruoyi-gen/Dockerfile" />
</settings> </settings>

@ -2,7 +2,7 @@
<configuration default="false" name="ruoyi-job" type="docker-deploy" factoryName="dockerfile" server-name="Docker"> <configuration default="false" name="ruoyi-job" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile"> <deployment type="dockerfile">
<settings> <settings>
<option name="imageTag" value="ruoyi/ruoyi-job:2.1.0" /> <option name="imageTag" value="ruoyi/ruoyi-job:2.1.1" />
<option name="buildOnly" value="true" /> <option name="buildOnly" value="true" />
<option name="sourceFilePath" value="ruoyi-modules/ruoyi-job/Dockerfile" /> <option name="sourceFilePath" value="ruoyi-modules/ruoyi-job/Dockerfile" />
</settings> </settings>

@ -2,7 +2,7 @@
<configuration default="false" name="ruoyi-monitor" type="docker-deploy" factoryName="dockerfile" server-name="Docker"> <configuration default="false" name="ruoyi-monitor" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile"> <deployment type="dockerfile">
<settings> <settings>
<option name="imageTag" value="ruoyi/ruoyi-monitor:2.1.0" /> <option name="imageTag" value="ruoyi/ruoyi-monitor:2.1.1" />
<option name="buildOnly" value="true" /> <option name="buildOnly" value="true" />
<option name="sourceFilePath" value="ruoyi-visual/ruoyi-monitor/Dockerfile" /> <option name="sourceFilePath" value="ruoyi-visual/ruoyi-monitor/Dockerfile" />
</settings> </settings>

@ -2,7 +2,7 @@
<configuration default="false" name="ruoyi-nacos" type="docker-deploy" factoryName="dockerfile" server-name="Docker"> <configuration default="false" name="ruoyi-nacos" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile"> <deployment type="dockerfile">
<settings> <settings>
<option name="imageTag" value="ruoyi/ruoyi-nacos:2.1.0" /> <option name="imageTag" value="ruoyi/ruoyi-nacos:2.1.1" />
<option name="buildOnly" value="true" /> <option name="buildOnly" value="true" />
<option name="sourceFilePath" value="ruoyi-visual/ruoyi-nacos/Dockerfile" /> <option name="sourceFilePath" value="ruoyi-visual/ruoyi-nacos/Dockerfile" />
</settings> </settings>

@ -2,11 +2,11 @@
<configuration default="false" name="ruoyi-powerjob-server" type="docker-deploy" factoryName="dockerfile" server-name="Docker"> <configuration default="false" name="ruoyi-powerjob-server" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile"> <deployment type="dockerfile">
<settings> <settings>
<option name="imageTag" value="ruoyi/ruoyi-powerjob-server:2.1.0" /> <option name="imageTag" value="ruoyi/ruoyi-powerjob-server:2.1.1" />
<option name="buildOnly" value="true" /> <option name="buildOnly" value="true" />
<option name="sourceFilePath" value="ruoyi-visual/ruoyi-powerjob-server/Dockerfile" /> <option name="sourceFilePath" value="ruoyi-visual/ruoyi-powerjob-server/Dockerfile" />
</settings> </settings>
</deployment> </deployment>
<method v="2" /> <method v="2" />
</configuration> </configuration>
</component> </component>

@ -2,7 +2,7 @@
<configuration default="false" name="ruoyi-resource" type="docker-deploy" factoryName="dockerfile" server-name="Docker"> <configuration default="false" name="ruoyi-resource" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile"> <deployment type="dockerfile">
<settings> <settings>
<option name="imageTag" value="ruoyi/ruoyi-resource:2.1.0" /> <option name="imageTag" value="ruoyi/ruoyi-resource:2.1.1" />
<option name="buildOnly" value="true" /> <option name="buildOnly" value="true" />
<option name="sourceFilePath" value="ruoyi-modules/ruoyi-resource/Dockerfile" /> <option name="sourceFilePath" value="ruoyi-modules/ruoyi-resource/Dockerfile" />
</settings> </settings>

@ -2,7 +2,7 @@
<configuration default="false" name="ruoyi-seata-server" type="docker-deploy" factoryName="dockerfile" server-name="Docker"> <configuration default="false" name="ruoyi-seata-server" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile"> <deployment type="dockerfile">
<settings> <settings>
<option name="imageTag" value="ruoyi/ruoyi-seata-server:2.1.0" /> <option name="imageTag" value="ruoyi/ruoyi-seata-server:2.1.1" />
<option name="buildOnly" value="true" /> <option name="buildOnly" value="true" />
<option name="sourceFilePath" value="ruoyi-visual/ruoyi-seata-server/Dockerfile" /> <option name="sourceFilePath" value="ruoyi-visual/ruoyi-seata-server/Dockerfile" />
</settings> </settings>

@ -2,7 +2,7 @@
<configuration default="false" name="ruoyi-sentinel-dashboard" type="docker-deploy" factoryName="dockerfile" server-name="Docker"> <configuration default="false" name="ruoyi-sentinel-dashboard" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile"> <deployment type="dockerfile">
<settings> <settings>
<option name="imageTag" value="ruoyi/ruoyi-sentinel-dashboard:2.1.0" /> <option name="imageTag" value="ruoyi/ruoyi-sentinel-dashboard:2.1.1" />
<option name="buildOnly" value="true" /> <option name="buildOnly" value="true" />
<option name="sourceFilePath" value="ruoyi-visual/ruoyi-sentinel-dashboard/Dockerfile" /> <option name="sourceFilePath" value="ruoyi-visual/ruoyi-sentinel-dashboard/Dockerfile" />
</settings> </settings>

@ -2,7 +2,7 @@
<configuration default="false" name="ruoyi-system" type="docker-deploy" factoryName="dockerfile" server-name="Docker"> <configuration default="false" name="ruoyi-system" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile"> <deployment type="dockerfile">
<settings> <settings>
<option name="imageTag" value="ruoyi/ruoyi-system:2.1.0" /> <option name="imageTag" value="ruoyi/ruoyi-system:2.1.1" />
<option name="buildOnly" value="true" /> <option name="buildOnly" value="true" />
<option name="sourceFilePath" value="ruoyi-modules/ruoyi-system/Dockerfile" /> <option name="sourceFilePath" value="ruoyi-modules/ruoyi-system/Dockerfile" />
</settings> </settings>

@ -9,10 +9,10 @@
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://gitee.com/dromara/RuoYi-Cloud-Plus/blob/master/LICENSE) [![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://gitee.com/dromara/RuoYi-Cloud-Plus/blob/master/LICENSE)
[![使用IntelliJ IDEA开发维护](https://img.shields.io/badge/IntelliJ%20IDEA-提供支持-blue.svg)](https://www.jetbrains.com/?from=RuoYi-Cloud-Plus) [![使用IntelliJ IDEA开发维护](https://img.shields.io/badge/IntelliJ%20IDEA-提供支持-blue.svg)](https://www.jetbrains.com/?from=RuoYi-Cloud-Plus)
<br> <br>
[![RuoYi-Cloud-Plus](https://img.shields.io/badge/RuoYi_Cloud_Plus-2.0.0-success.svg)](https://gitee.com/dromara/RuoYi-Cloud-Plus) [![RuoYi-Cloud-Plus](https://img.shields.io/badge/RuoYi_Cloud_Plus-2.1.1-success.svg)](https://gitee.com/dromara/RuoYi-Cloud-Plus)
[![Spring Boot](https://img.shields.io/badge/Spring%20Boot-3.0-blue.svg)]() [![Spring Boot](https://img.shields.io/badge/Spring%20Boot-3.1-blue.svg)]()
[![JDK-17](https://img.shields.io/badge/JDK-17-green.svg)]() [![JDK-17](https://img.shields.io/badge/JDK-17-green.svg)]()
[![JDK-19](https://img.shields.io/badge/JDK-19-green.svg)]() [![JDK-19](https://img.shields.io/badge/JDK-21-green.svg)]()
> RuoYi-Cloud-Plus `微服务通用权限管理系统` 重写 RuoYi-Cloud 全方位升级(不兼容原框架) > RuoYi-Cloud-Plus `微服务通用权限管理系统` 重写 RuoYi-Cloud 全方位升级(不兼容原框架)

@ -148,11 +148,6 @@ logging:
sa-token: sa-token:
# token名称 (同时也是cookie名称) # token名称 (同时也是cookie名称)
token-name: Authorization token-name: Authorization
# token固定超时 设为七天 (必定过期) 单位: 秒
timeout: 604800
# 多端不同 token 有效期 可查看 LoginHelper.loginByDevice 方法自定义
# token最低活跃时间 (指定时间无操作就过期) 单位: 秒
active-timeout: 1800
# 开启内网服务调用鉴权(不允许越过gateway访问内网服务 保障服务安全) # 开启内网服务调用鉴权(不允许越过gateway访问内网服务 保障服务安全)
check-same-token: true check-same-token: true
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录) # 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)

@ -27,6 +27,7 @@ spring:
# password: ${datasource.system-postgres.password} # password: ${datasource.system-postgres.password}
websocket: websocket:
# 如果关闭 需要和前端开关一起关闭
enabled: true enabled: true
# 路径 # 路径
path: /websocket path: /websocket

@ -29,7 +29,7 @@ services:
network_mode: "host" network_mode: "host"
nacos: nacos:
image: ruoyi/ruoyi-nacos:2.1.0 image: ruoyi/ruoyi-nacos:2.1.1
container_name: nacos container_name: nacos
ports: ports:
- "8848:8848" - "8848:8848"
@ -96,7 +96,7 @@ services:
network_mode: "host" network_mode: "host"
seata-server: seata-server:
image: ruoyi/ruoyi-seata-server:2.1.0 image: ruoyi/ruoyi-seata-server:2.1.1
container_name: seata-server container_name: seata-server
ports: ports:
- "7091:7091" - "7091:7091"
@ -135,7 +135,7 @@ services:
network_mode: "host" network_mode: "host"
sentinel: sentinel:
image: ruoyi/ruoyi-sentinel-dashboard:2.1.0 image: ruoyi/ruoyi-sentinel-dashboard:2.1.1
container_name: sentinel container_name: sentinel
environment: environment:
TZ: Asia/Shanghai TZ: Asia/Shanghai
@ -150,7 +150,7 @@ services:
network_mode: "host" network_mode: "host"
ruoyi-monitor: ruoyi-monitor:
image: ruoyi/ruoyi-monitor:2.1.0 image: ruoyi/ruoyi-monitor:2.1.1
container_name: ruoyi-monitor container_name: ruoyi-monitor
environment: environment:
# 时区上海 # 时区上海
@ -166,7 +166,7 @@ services:
network_mode: "host" network_mode: "host"
ruoyi-powerjob-server: ruoyi-powerjob-server:
image: ruoyi/ruoyi-powerjob-server:2.1.0 image: ruoyi/ruoyi-powerjob-server:2.1.1
container_name: ruoyi-powerjob-server container_name: ruoyi-powerjob-server
environment: environment:
# 时区上海 # 时区上海
@ -181,7 +181,7 @@ services:
network_mode: "host" network_mode: "host"
ruoyi-gateway: ruoyi-gateway:
image: ruoyi/ruoyi-gateway:2.1.0 image: ruoyi/ruoyi-gateway:2.1.1
container_name: ruoyi-gateway container_name: ruoyi-gateway
environment: environment:
# 时区上海 # 时区上海
@ -197,7 +197,7 @@ services:
network_mode: "host" network_mode: "host"
ruoyi-auth: ruoyi-auth:
image: ruoyi/ruoyi-auth:2.1.0 image: ruoyi/ruoyi-auth:2.1.1
container_name: ruoyi-auth container_name: ruoyi-auth
environment: environment:
# 时区上海 # 时区上海
@ -213,7 +213,7 @@ services:
network_mode: "host" network_mode: "host"
ruoyi-system: ruoyi-system:
image: ruoyi/ruoyi-system:2.1.0 image: ruoyi/ruoyi-system:2.1.1
container_name: ruoyi-system container_name: ruoyi-system
environment: environment:
# 时区上海 # 时区上海
@ -229,7 +229,7 @@ services:
network_mode: "host" network_mode: "host"
ruoyi-gen: ruoyi-gen:
image: ruoyi/ruoyi-gen:2.1.0 image: ruoyi/ruoyi-gen:2.1.1
container_name: ruoyi-gen container_name: ruoyi-gen
environment: environment:
# 时区上海 # 时区上海
@ -245,7 +245,7 @@ services:
network_mode: "host" network_mode: "host"
ruoyi-job: ruoyi-job:
image: ruoyi/ruoyi-job:2.1.0 image: ruoyi/ruoyi-job:2.1.1
container_name: ruoyi-job container_name: ruoyi-job
environment: environment:
# 时区上海 # 时区上海
@ -261,7 +261,7 @@ services:
network_mode: "host" network_mode: "host"
ruoyi-resource: ruoyi-resource:
image: ruoyi/ruoyi-resource:2.1.0 image: ruoyi/ruoyi-resource:2.1.1
container_name: ruoyi-resource container_name: ruoyi-resource
environment: environment:
# 时区上海 # 时区上海

@ -71,6 +71,10 @@ http {
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# websocket参数
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://server/; proxy_pass http://server/;
} }

@ -13,7 +13,7 @@
<description>RuoYi-Cloud-Plus微服务系统</description> <description>RuoYi-Cloud-Plus微服务系统</description>
<properties> <properties>
<revision>2.1.0</revision> <revision>2.1.1</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>17</java.version> <java.version>17</java.version>

@ -15,7 +15,7 @@
</description> </description>
<properties> <properties>
<revision>2.1.0</revision> <revision>2.1.1</revision>
</properties> </properties>
<dependencyManagement> <dependencyManagement>

@ -0,0 +1,19 @@
package org.dromara.resource.api;
/**
*
*
* @author Lion Li
*/
public interface RemoteMessageService {
/**
*
*
* @param sessionKey session id
* @param message
*/
void sendMessage(Long sessionKey, String message);
void publishAll(String message);
}

@ -89,6 +89,10 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>org.dromara</groupId>
<artifactId>ruoyi-api-resource</artifactId>
</dependency>
<!-- 自定义负载均衡(多团队开发使用) --> <!-- 自定义负载均衡(多团队开发使用) -->
<!-- <dependency>--> <!-- <dependency>-->

@ -14,19 +14,20 @@ import org.dromara.auth.domain.vo.LoginTenantVo;
import org.dromara.auth.domain.vo.LoginVo; import org.dromara.auth.domain.vo.LoginVo;
import org.dromara.auth.domain.vo.TenantListVo; import org.dromara.auth.domain.vo.TenantListVo;
import org.dromara.auth.form.RegisterBody; import org.dromara.auth.form.RegisterBody;
import org.dromara.auth.form.SocialLoginBody;
import org.dromara.auth.service.IAuthStrategy; import org.dromara.auth.service.IAuthStrategy;
import org.dromara.auth.service.SysLoginService; import org.dromara.auth.service.SysLoginService;
import org.dromara.common.core.constant.UserConstants; import org.dromara.common.core.constant.UserConstants;
import org.dromara.common.core.domain.R; import org.dromara.common.core.domain.R;
import org.dromara.common.core.domain.model.LoginBody; import org.dromara.common.core.domain.model.LoginBody;
import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.*;
import org.dromara.common.core.utils.MessageUtils; import org.dromara.common.json.utils.JsonUtils;
import org.dromara.common.core.utils.StreamUtils; import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.social.config.properties.SocialLoginConfigProperties; import org.dromara.common.social.config.properties.SocialLoginConfigProperties;
import org.dromara.common.social.config.properties.SocialProperties; import org.dromara.common.social.config.properties.SocialProperties;
import org.dromara.common.social.utils.SocialUtils; import org.dromara.common.social.utils.SocialUtils;
import org.dromara.common.tenant.helper.TenantHelper; import org.dromara.common.tenant.helper.TenantHelper;
import org.dromara.resource.api.RemoteMessageService;
import org.dromara.system.api.RemoteClientService; import org.dromara.system.api.RemoteClientService;
import org.dromara.system.api.RemoteConfigService; import org.dromara.system.api.RemoteConfigService;
import org.dromara.system.api.RemoteSocialService; import org.dromara.system.api.RemoteSocialService;
@ -38,6 +39,8 @@ import org.springframework.web.bind.annotation.*;
import java.net.URL; import java.net.URL;
import java.util.List; import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/** /**
* token * token
@ -52,6 +55,7 @@ public class TokenController {
private final SocialProperties socialProperties; private final SocialProperties socialProperties;
private final SysLoginService sysLoginService; private final SysLoginService sysLoginService;
private final ScheduledExecutorService scheduledExecutorService;
@DubboReference @DubboReference
private final RemoteConfigService remoteConfigService; private final RemoteConfigService remoteConfigService;
@ -61,12 +65,19 @@ public class TokenController {
private final RemoteClientService remoteClientService; private final RemoteClientService remoteClientService;
@DubboReference @DubboReference
private final RemoteSocialService remoteSocialService; private final RemoteSocialService remoteSocialService;
@DubboReference
private final RemoteMessageService remoteMessageService;
/** /**
* *
*
* @param body
* @return
*/ */
@PostMapping("login") @PostMapping("/login")
public R<LoginVo> login(@Validated @RequestBody LoginBody loginBody) { public R<LoginVo> login(@Validated @RequestBody String body) {
LoginBody loginBody = JsonUtils.parseObject(body, LoginBody.class);
ValidatorUtils.validate(loginBody);
// 授权类型和客户端id // 授权类型和客户端id
String clientId = loginBody.getClientId(); String clientId = loginBody.getClientId();
String grantType = loginBody.getGrantType(); String grantType = loginBody.getGrantType();
@ -82,7 +93,13 @@ public class TokenController {
// 校验租户 // 校验租户
sysLoginService.checkTenant(loginBody.getTenantId()); sysLoginService.checkTenant(loginBody.getTenantId());
// 登录 // 登录
return R.ok(IAuthStrategy.login(loginBody, clientVo)); LoginVo loginVo = IAuthStrategy.login(body, clientVo, grantType);
Long userId = LoginHelper.getUserId();
scheduledExecutorService.schedule(() -> {
remoteMessageService.sendMessage(userId, "欢迎登录RuoYi-Cloud-Plus微服务管理系统");
}, 3, TimeUnit.SECONDS);
return R.ok(loginVo);
} }
/** /**
@ -109,9 +126,11 @@ public class TokenController {
* @return * @return
*/ */
@PostMapping("/social/callback") @PostMapping("/social/callback")
public R<Void> socialCallback(@RequestBody LoginBody loginBody) { public R<Void> socialCallback(@RequestBody SocialLoginBody loginBody) {
// 获取第三方登录信息 // 获取第三方登录信息
AuthResponse<AuthUser> response = SocialUtils.loginAuth(loginBody, socialProperties); AuthResponse<AuthUser> response = SocialUtils.loginAuth(
loginBody.getSource(), loginBody.getSocialCode(),
loginBody.getSocialState(), socialProperties);
AuthUser authUserData = response.getData(); AuthUser authUserData = response.getData();
// 判断授权响应是否成功 // 判断授权响应是否成功
if (!response.ok()) { if (!response.ok()) {

@ -1,9 +1,10 @@
package org.dromara.auth.form; package org.dromara.auth.form;
import lombok.Data;
import jakarta.validation.constraints.Email; import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank; 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 @Data
public class EmailLoginBody { @EqualsAndHashCode(callSuper = true)
public class EmailLoginBody extends LoginBody {
/**
* ID
*/
@NotBlank(message = "{tenant.number.not.blank}")
private String tenantId;
/** /**
* *

@ -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;
}

@ -1,8 +1,12 @@
package org.dromara.auth.form; package org.dromara.auth.form;
import jakarta.validation.constraints.NotBlank;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import org.dromara.common.core.domain.model.LoginBody; 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) @EqualsAndHashCode(callSuper = true)
public class RegisterBody extends LoginBody { 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; private String userType;
} }

@ -1,8 +1,9 @@
package org.dromara.auth.form; package org.dromara.auth.form;
import lombok.Data;
import jakarta.validation.constraints.NotBlank; 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 @Data
public class SmsLoginBody { @EqualsAndHashCode(callSuper = true)
public class SmsLoginBody extends LoginBody {
/**
* ID
*/
private String tenantId;
/** /**
* *

@ -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;
}

@ -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;
}

@ -1,7 +1,6 @@
package org.dromara.auth.service; package org.dromara.auth.service;
import org.dromara.auth.domain.vo.LoginVo; 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.exception.ServiceException;
import org.dromara.common.core.utils.SpringUtils; import org.dromara.common.core.utils.SpringUtils;
import org.dromara.system.api.domain.vo.RemoteClientVo; import org.dromara.system.api.domain.vo.RemoteClientVo;
@ -18,27 +17,19 @@ public interface IAuthStrategy {
/** /**
* *
*/ */
static LoginVo login(LoginBody loginBody, RemoteClientVo client) { static LoginVo login(String body, RemoteClientVo client, String grantType) {
// 授权类型和客户端id // 授权类型和客户端id
String clientId = loginBody.getClientId();
String grantType = loginBody.getGrantType();
String beanName = grantType + BASE_NAME; String beanName = grantType + BASE_NAME;
if (!SpringUtils.containsBean(beanName)) { if (!SpringUtils.containsBean(beanName)) {
throw new ServiceException("授权类型不正确!"); throw new ServiceException("授权类型不正确!");
} }
IAuthStrategy instance = SpringUtils.getBean(beanName); IAuthStrategy instance = SpringUtils.getBean(beanName);
instance.validate(loginBody); return instance.login(body, client);
return instance.login(clientId, loginBody, client);
} }
/**
*
*/
void validate(LoginBody loginBody);
/** /**
* *
*/ */
LoginVo login(String clientId, LoginBody loginBody, RemoteClientVo client); LoginVo login(String body, RemoteClientVo client);
} }

@ -132,6 +132,7 @@ public class SysLoginService {
// 注册用户信息 // 注册用户信息
RemoteUserBo remoteUserBo = new RemoteUserBo(); RemoteUserBo remoteUserBo = new RemoteUserBo();
remoteUserBo.setTenantId(tenantId);
remoteUserBo.setUserName(username); remoteUserBo.setUserName(username);
remoteUserBo.setNickName(username); remoteUserBo.setNickName(username);
remoteUserBo.setPassword(BCrypt.hashpw(password)); remoteUserBo.setPassword(BCrypt.hashpw(password));

@ -6,7 +6,7 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.auth.domain.vo.LoginVo; 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.IAuthStrategy;
import org.dromara.auth.service.SysLoginService; import org.dromara.auth.service.SysLoginService;
import org.dromara.common.core.constant.Constants; 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.ServletUtils;
import org.dromara.common.core.utils.StringUtils; import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.core.utils.ValidatorUtils; 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.redis.utils.RedisUtils;
import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.system.api.RemoteUserService; import org.dromara.system.api.RemoteUserService;
@ -41,12 +41,9 @@ public class EmailAuthStrategy implements IAuthStrategy {
private RemoteUserService remoteUserService; private RemoteUserService remoteUserService;
@Override @Override
public void validate(LoginBody loginBody) { public LoginVo login(String body, RemoteClientVo client) {
ValidatorUtils.validate(loginBody, EmailGroup.class); EmailLoginBody loginBody = JsonUtils.parseObject(body, EmailLoginBody.class);
} ValidatorUtils.validate(loginBody);
@Override
public LoginVo login(String clientId, LoginBody loginBody, RemoteClientVo client) {
String tenantId = loginBody.getTenantId(); String tenantId = loginBody.getTenantId();
String email = loginBody.getEmail(); String email = loginBody.getEmail();
String emailCode = loginBody.getEmailCode(); String emailCode = loginBody.getEmailCode();
@ -62,7 +59,7 @@ public class EmailAuthStrategy implements IAuthStrategy {
// 例如: 后台用户30分钟过期 app用户1天过期 // 例如: 后台用户30分钟过期 app用户1天过期
model.setTimeout(client.getTimeout()); model.setTimeout(client.getTimeout());
model.setActiveTimeout(client.getActiveTimeout()); model.setActiveTimeout(client.getActiveTimeout());
model.setExtra(LoginHelper.CLIENT_KEY, clientId); model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
// 生成token // 生成token
LoginHelper.login(loginUser, model); LoginHelper.login(loginUser, model);
@ -72,7 +69,7 @@ public class EmailAuthStrategy implements IAuthStrategy {
LoginVo loginVo = new LoginVo(); LoginVo loginVo = new LoginVo();
loginVo.setAccessToken(StpUtil.getTokenValue()); loginVo.setAccessToken(StpUtil.getTokenValue());
loginVo.setExpireIn(StpUtil.getTokenTimeout()); loginVo.setExpireIn(StpUtil.getTokenTimeout());
loginVo.setClientId(clientId); loginVo.setClientId(client.getClientId());
return loginVo; return loginVo;
} }

@ -7,12 +7,12 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.auth.domain.vo.LoginVo; import org.dromara.auth.domain.vo.LoginVo;
import org.dromara.auth.form.PasswordLoginBody;
import org.dromara.auth.properties.CaptchaProperties; import org.dromara.auth.properties.CaptchaProperties;
import org.dromara.auth.service.IAuthStrategy; import org.dromara.auth.service.IAuthStrategy;
import org.dromara.auth.service.SysLoginService; import org.dromara.auth.service.SysLoginService;
import org.dromara.common.core.constant.Constants; import org.dromara.common.core.constant.Constants;
import org.dromara.common.core.constant.GlobalConstants; 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.enums.LoginType;
import org.dromara.common.core.exception.CaptchaException; import org.dromara.common.core.exception.CaptchaException;
import org.dromara.common.core.exception.user.CaptchaExpireException; 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.ServletUtils;
import org.dromara.common.core.utils.StringUtils; import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.core.utils.ValidatorUtils; 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.redis.utils.RedisUtils;
import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.system.api.RemoteUserService; import org.dromara.system.api.RemoteUserService;
@ -46,12 +46,9 @@ public class PasswordAuthStrategy implements IAuthStrategy {
private RemoteUserService remoteUserService; private RemoteUserService remoteUserService;
@Override @Override
public void validate(LoginBody loginBody) { public LoginVo login(String body, RemoteClientVo client) {
ValidatorUtils.validate(loginBody, PasswordGroup.class); PasswordLoginBody loginBody = JsonUtils.parseObject(body, PasswordLoginBody.class);
} ValidatorUtils.validate(loginBody);
@Override
public LoginVo login(String clientId, LoginBody loginBody, RemoteClientVo client) {
String tenantId = loginBody.getTenantId(); String tenantId = loginBody.getTenantId();
String username = loginBody.getUsername(); String username = loginBody.getUsername();
String password = loginBody.getPassword(); String password = loginBody.getPassword();
@ -73,7 +70,7 @@ public class PasswordAuthStrategy implements IAuthStrategy {
// 例如: 后台用户30分钟过期 app用户1天过期 // 例如: 后台用户30分钟过期 app用户1天过期
model.setTimeout(client.getTimeout()); model.setTimeout(client.getTimeout());
model.setActiveTimeout(client.getActiveTimeout()); model.setActiveTimeout(client.getActiveTimeout());
model.setExtra(LoginHelper.CLIENT_KEY, clientId); model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
// 生成token // 生成token
LoginHelper.login(loginUser, model); LoginHelper.login(loginUser, model);
@ -83,7 +80,7 @@ public class PasswordAuthStrategy implements IAuthStrategy {
LoginVo loginVo = new LoginVo(); LoginVo loginVo = new LoginVo();
loginVo.setAccessToken(StpUtil.getTokenValue()); loginVo.setAccessToken(StpUtil.getTokenValue());
loginVo.setExpireIn(StpUtil.getTokenTimeout()); loginVo.setExpireIn(StpUtil.getTokenTimeout());
loginVo.setClientId(clientId); loginVo.setClientId(client.getClientId());
return loginVo; return loginVo;
} }

@ -6,7 +6,7 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.auth.domain.vo.LoginVo; 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.IAuthStrategy;
import org.dromara.auth.service.SysLoginService; import org.dromara.auth.service.SysLoginService;
import org.dromara.common.core.constant.Constants; 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.ServletUtils;
import org.dromara.common.core.utils.StringUtils; import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.core.utils.ValidatorUtils; 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.redis.utils.RedisUtils;
import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.system.api.RemoteUserService; import org.dromara.system.api.RemoteUserService;
@ -41,12 +41,9 @@ public class SmsAuthStrategy implements IAuthStrategy {
private RemoteUserService remoteUserService; private RemoteUserService remoteUserService;
@Override @Override
public void validate(LoginBody loginBody) { public LoginVo login(String body, RemoteClientVo client) {
ValidatorUtils.validate(loginBody, SmsGroup.class); SmsLoginBody loginBody = JsonUtils.parseObject(body, SmsLoginBody.class);
} ValidatorUtils.validate(loginBody);
@Override
public LoginVo login(String clientId, LoginBody loginBody, RemoteClientVo client) {
String tenantId = loginBody.getTenantId(); String tenantId = loginBody.getTenantId();
String phonenumber = loginBody.getPhonenumber(); String phonenumber = loginBody.getPhonenumber();
String smsCode = loginBody.getSmsCode(); String smsCode = loginBody.getSmsCode();
@ -62,7 +59,7 @@ public class SmsAuthStrategy implements IAuthStrategy {
// 例如: 后台用户30分钟过期 app用户1天过期 // 例如: 后台用户30分钟过期 app用户1天过期
model.setTimeout(client.getTimeout()); model.setTimeout(client.getTimeout());
model.setActiveTimeout(client.getActiveTimeout()); model.setActiveTimeout(client.getActiveTimeout());
model.setExtra(LoginHelper.CLIENT_KEY, clientId); model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
// 生成token // 生成token
LoginHelper.login(loginUser, model); LoginHelper.login(loginUser, model);
@ -72,7 +69,7 @@ public class SmsAuthStrategy implements IAuthStrategy {
LoginVo loginVo = new LoginVo(); LoginVo loginVo = new LoginVo();
loginVo.setAccessToken(StpUtil.getTokenValue()); loginVo.setAccessToken(StpUtil.getTokenValue());
loginVo.setExpireIn(StpUtil.getTokenTimeout()); loginVo.setExpireIn(StpUtil.getTokenTimeout());
loginVo.setClientId(clientId); loginVo.setClientId(client.getClientId());
return loginVo; return loginVo;
} }

@ -13,15 +13,15 @@ import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.model.AuthUser;
import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.auth.domain.vo.LoginVo; import org.dromara.auth.domain.vo.LoginVo;
import org.dromara.auth.form.SocialLoginBody;
import org.dromara.auth.service.IAuthStrategy; import org.dromara.auth.service.IAuthStrategy;
import org.dromara.auth.service.SysLoginService; import org.dromara.auth.service.SysLoginService;
import org.dromara.common.core.constant.Constants; 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.exception.ServiceException;
import org.dromara.common.core.utils.MessageUtils; import org.dromara.common.core.utils.MessageUtils;
import org.dromara.common.core.utils.ServletUtils; import org.dromara.common.core.utils.ServletUtils;
import org.dromara.common.core.utils.ValidatorUtils; 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.satoken.utils.LoginHelper;
import org.dromara.common.social.config.properties.SocialProperties; import org.dromara.common.social.config.properties.SocialProperties;
import org.dromara.common.social.utils.SocialUtils; import org.dromara.common.social.utils.SocialUtils;
@ -50,21 +50,20 @@ public class SocialAuthStrategy implements IAuthStrategy {
@DubboReference @DubboReference
private RemoteUserService remoteUserService; private RemoteUserService remoteUserService;
@Override
public void validate(LoginBody loginBody) {
ValidatorUtils.validate(loginBody, SocialGroup.class);
}
/** /**
* - * -
* *
* @param clientId id * @param clientId id
* @param loginBody * @param body
* @param client * @param client
*/ */
@Override @Override
public LoginVo login(String clientId, LoginBody loginBody, RemoteClientVo client) { public LoginVo login(String body, RemoteClientVo client) {
AuthResponse<AuthUser> response = SocialUtils.loginAuth(loginBody, socialProperties); SocialLoginBody loginBody = JsonUtils.parseObject(body, SocialLoginBody.class);
ValidatorUtils.validate(loginBody);
AuthResponse<AuthUser> response = SocialUtils.loginAuth(
loginBody.getSource(), loginBody.getSocialCode(),
loginBody.getSocialState(), socialProperties);
if (!response.ok()) { if (!response.ok()) {
throw new ServiceException(response.getMsg()); throw new ServiceException(response.getMsg());
} }
@ -99,7 +98,7 @@ public class SocialAuthStrategy implements IAuthStrategy {
// 例如: 后台用户30分钟过期 app用户1天过期 // 例如: 后台用户30分钟过期 app用户1天过期
model.setTimeout(client.getTimeout()); model.setTimeout(client.getTimeout());
model.setActiveTimeout(client.getActiveTimeout()); model.setActiveTimeout(client.getActiveTimeout());
model.setExtra(LoginHelper.CLIENT_KEY, clientId); model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
// 生成token // 生成token
LoginHelper.login(loginUser, model); LoginHelper.login(loginUser, model);
@ -109,7 +108,7 @@ public class SocialAuthStrategy implements IAuthStrategy {
LoginVo loginVo = new LoginVo(); LoginVo loginVo = new LoginVo();
loginVo.setAccessToken(StpUtil.getTokenValue()); loginVo.setAccessToken(StpUtil.getTokenValue());
loginVo.setExpireIn(StpUtil.getTokenTimeout()); loginVo.setExpireIn(StpUtil.getTokenTimeout());
loginVo.setClientId(clientId); loginVo.setClientId(client.getClientId());
return loginVo; return loginVo;
} }

@ -6,14 +6,14 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.auth.domain.vo.LoginVo; 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.IAuthStrategy;
import org.dromara.auth.service.SysLoginService; import org.dromara.auth.service.SysLoginService;
import org.dromara.common.core.constant.Constants; import org.dromara.common.core.constant.Constants;
import org.dromara.common.core.utils.MessageUtils; import org.dromara.common.core.utils.MessageUtils;
import org.dromara.common.core.utils.ServletUtils; import org.dromara.common.core.utils.ServletUtils;
import org.dromara.common.core.utils.ValidatorUtils; 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.common.satoken.utils.LoginHelper;
import org.dromara.system.api.RemoteUserService; import org.dromara.system.api.RemoteUserService;
import org.dromara.system.api.domain.vo.RemoteClientVo; import org.dromara.system.api.domain.vo.RemoteClientVo;
@ -36,14 +36,14 @@ public class XcxAuthStrategy implements IAuthStrategy {
private RemoteUserService remoteUserService; private RemoteUserService remoteUserService;
@Override @Override
public void validate(LoginBody loginBody) { public LoginVo login(String body, RemoteClientVo client) {
ValidatorUtils.validate(loginBody, WechatGroup.class); XcxLoginBody loginBody = JsonUtils.parseObject(body, XcxLoginBody.class);
} ValidatorUtils.validate(loginBody);
@Override
public LoginVo login(String clientId, LoginBody loginBody, RemoteClientVo client) {
// xcxCode 为 小程序调用 wx.login 授权后获取 // xcxCode 为 小程序调用 wx.login 授权后获取
String xcxCode = loginBody.getXcxCode(); String xcxCode = loginBody.getXcxCode();
// 多个小程序识别使用
String appid = loginBody.getAppid();
// todo 以下自行实现 // todo 以下自行实现
// 校验 appid + appsrcret + xcxCode 调用登录凭证校验接口 获取 session_key 与 openid // 校验 appid + appsrcret + xcxCode 调用登录凭证校验接口 获取 session_key 与 openid
String openid = ""; String openid = "";
@ -57,7 +57,7 @@ public class XcxAuthStrategy implements IAuthStrategy {
// 例如: 后台用户30分钟过期 app用户1天过期 // 例如: 后台用户30分钟过期 app用户1天过期
model.setTimeout(client.getTimeout()); model.setTimeout(client.getTimeout());
model.setActiveTimeout(client.getActiveTimeout()); model.setActiveTimeout(client.getActiveTimeout());
model.setExtra(LoginHelper.CLIENT_KEY, clientId); model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
// 生成token // 生成token
LoginHelper.login(loginUser, model); LoginHelper.login(loginUser, model);
@ -67,7 +67,7 @@ public class XcxAuthStrategy implements IAuthStrategy {
LoginVo loginVo = new LoginVo(); LoginVo loginVo = new LoginVo();
loginVo.setAccessToken(StpUtil.getTokenValue()); loginVo.setAccessToken(StpUtil.getTokenValue());
loginVo.setExpireIn(StpUtil.getTokenTimeout()); loginVo.setExpireIn(StpUtil.getTokenTimeout());
loginVo.setClientId(clientId); loginVo.setClientId(client.getClientId());
loginVo.setOpenid(openid); loginVo.setOpenid(openid);
return loginVo; return loginVo;
} }

@ -14,7 +14,7 @@
</description> </description>
<properties> <properties>
<revision>2.1.0</revision> <revision>2.1.1</revision>
<spring-cloud-alibaba.version>2022.0.0.0</spring-cloud-alibaba.version> <spring-cloud-alibaba.version>2022.0.0.0</spring-cloud-alibaba.version>
<sentinel.version>1.8.6</sentinel.version> <sentinel.version>1.8.6</sentinel.version>
<seata.version>1.7.1</seata.version> <seata.version>1.7.1</seata.version>

@ -14,7 +14,7 @@
</description> </description>
<properties> <properties>
<revision>2.1.0</revision> <revision>2.1.1</revision>
</properties> </properties>
<dependencyManagement> <dependencyManagement>

@ -1,13 +1,8 @@
package org.dromara.common.core.domain.model; package org.dromara.common.core.domain.model;
import jakarta.validation.constraints.Email; import jakarta.validation.constraints.NotBlank;
import org.dromara.common.core.constant.UserConstants;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; 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}") @NotBlank(message = "{auth.clientid.not.blank}")
private String clientId; private String clientId;
/**
* key
*/
private String clientKey;
/**
*
*/
private String clientSecret;
/** /**
* *
*/ */
@ -45,20 +30,6 @@ public class LoginBody {
*/ */
private String tenantId; 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; 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;
} }

@ -24,7 +24,7 @@ public class AddressUtils {
return UNKNOWN; return UNKNOWN;
} }
// 内网不查询 // 内网不查询
ip = "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : HtmlUtil.cleanHtmlTag(ip); ip = StringUtils.contains(ip, "0:0:0:0:0:0:0:1") ? "127.0.0.1" : HtmlUtil.cleanHtmlTag(ip);
if (NetUtil.isInnerIP(ip)) { if (NetUtil.isInnerIP(ip)) {
return "内网IP"; return "内网IP";
} }

@ -1,7 +0,0 @@
package org.dromara.common.core.validate.auth;
/**
* @author Michelle.Chung
*/
public interface EmailGroup {
}

@ -1,7 +0,0 @@
package org.dromara.common.core.validate.auth;
/**
* @author Michelle.Chung
*/
public interface PasswordGroup {
}

@ -1,7 +0,0 @@
package org.dromara.common.core.validate.auth;
/**
* @author Michelle.Chung
*/
public interface SmsGroup {
}

@ -1,4 +0,0 @@
package org.dromara.common.core.validate.auth;
public interface SocialGroup {
}

@ -1,7 +0,0 @@
package org.dromara.common.core.validate.auth;
/**
* @author Michelle.Chung
*/
public interface WechatGroup {
}

@ -32,6 +32,12 @@
<dependency> <dependency>
<groupId>tech.powerjob</groupId> <groupId>tech.powerjob</groupId>
<artifactId>powerjob-worker</artifactId> <artifactId>powerjob-worker</artifactId>
<exclusions>
<exclusion>
<artifactId>powerjob-remote-impl-akka</artifactId>
<groupId>tech.powerjob</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>tech.powerjob</groupId> <groupId>tech.powerjob</groupId>

@ -5,14 +5,6 @@ import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.alibaba.ttl.TransmittableThreadLocal; import com.alibaba.ttl.TransmittableThreadLocal;
import org.dromara.common.core.utils.ServletUtils;
import org.dromara.common.core.utils.SpringUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.json.utils.JsonUtils;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessStatus;
import org.dromara.common.log.event.OperLogEvent;
import org.dromara.common.satoken.utils.LoginHelper;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -22,6 +14,15 @@ import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing; import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Before;
import org.dromara.common.core.utils.ServletUtils;
import org.dromara.common.core.utils.SpringUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.json.utils.JsonUtils;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessStatus;
import org.dromara.common.log.event.OperLogEvent;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.system.api.model.LoginUser;
import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
@ -94,7 +95,9 @@ public class LogAspect {
String ip = ServletUtils.getClientIP(); String ip = ServletUtils.getClientIP();
operLog.setOperIp(ip); operLog.setOperIp(ip);
operLog.setOperUrl(StringUtils.substring(ServletUtils.getRequest().getRequestURI(), 0, 255)); operLog.setOperUrl(StringUtils.substring(ServletUtils.getRequest().getRequestURI(), 0, 255));
operLog.setOperName(LoginHelper.getUsername()); LoginUser loginUser = LoginHelper.getLoginUser();
operLog.setOperName(loginUser.getUsername());
operLog.setDeptName(loginUser.getDeptName());
if (e != null) { if (e != null) {
operLog.setStatus(BusinessStatus.FAIL.ordinal()); operLog.setStatus(BusinessStatus.FAIL.ordinal());

@ -30,17 +30,17 @@ public enum DataScopeType {
/** /**
* *
*/ */
CUSTOM("2", " #{#deptName} IN ( #{@sdss.getRoleCustom( #user.roleId )} ) ", ""), CUSTOM("2", " #{#deptName} IN ( #{@sdss.getRoleCustom( #user.roleId )} ) ", " 1 = 0 "),
/** /**
* *
*/ */
DEPT("3", " #{#deptName} = #{#user.deptId} ", ""), DEPT("3", " #{#deptName} = #{#user.deptId} ", " 1 = 0 "),
/** /**
* *
*/ */
DEPT_AND_CHILD("4", " #{#deptName} IN ( #{@sdss.getDeptAndChild( #user.deptId )} )", ""), DEPT_AND_CHILD("4", " #{#deptName} IN ( #{@sdss.getDeptAndChild( #user.deptId )} )", " 1 = 0 "),
/** /**
* *

@ -2,8 +2,6 @@ package org.dromara.common.mybatis.handler;
import cn.hutool.core.annotation.AnnotationUtil; import cn.hutool.core.annotation.AnnotationUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ConcurrentHashSet;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ClassUtil; import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -50,11 +48,6 @@ public class PlusDataPermissionHandler {
*/ */
private final Map<String, DataPermission> dataPermissionCacheMap = new ConcurrentHashMap<>(); private final Map<String, DataPermission> dataPermissionCacheMap = new ConcurrentHashMap<>();
/**
*
*/
private final Set<String> invalidCacheSet = new ConcurrentHashSet<>();
/** /**
* spel * spel
*/ */
@ -68,10 +61,6 @@ public class PlusDataPermissionHandler {
public Expression getSqlSegment(Expression where, String mappedStatementId, boolean isSelect) { public Expression getSqlSegment(Expression where, String mappedStatementId, boolean isSelect) {
DataColumn[] dataColumns = findAnnotation(mappedStatementId); DataColumn[] dataColumns = findAnnotation(mappedStatementId);
if (ArrayUtil.isEmpty(dataColumns)) {
invalidCacheSet.add(mappedStatementId);
return where;
}
LoginUser currentUser = DataPermissionHelper.getVariable("user"); LoginUser currentUser = DataPermissionHelper.getVariable("user");
if (ObjectUtil.isNull(currentUser)) { if (ObjectUtil.isNull(currentUser)) {
currentUser = LoginHelper.getLoginUser(); currentUser = LoginHelper.getLoginUser();
@ -155,7 +144,7 @@ public class PlusDataPermissionHandler {
return ""; return "";
} }
private DataColumn[] findAnnotation(String mappedStatementId) { public DataColumn[] findAnnotation(String mappedStatementId) {
StringBuilder sb = new StringBuilder(mappedStatementId); StringBuilder sb = new StringBuilder(mappedStatementId);
int index = sb.lastIndexOf("."); int index = sb.lastIndexOf(".");
String clazzName = sb.substring(0, index); String clazzName = sb.substring(0, index);
@ -189,10 +178,4 @@ public class PlusDataPermissionHandler {
return null; return null;
} }
/**
*
*/
public boolean isInvalid(String mappedStatementId) {
return invalidCacheSet.contains(mappedStatementId);
}
} }

@ -1,9 +1,12 @@
package org.dromara.common.mybatis.interceptor; package org.dromara.common.mybatis.interceptor;
import cn.hutool.core.collection.ConcurrentHashSet;
import cn.hutool.core.util.ArrayUtil;
import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper; import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper;
import com.baomidou.mybatisplus.core.toolkit.PluginUtils; import com.baomidou.mybatisplus.core.toolkit.PluginUtils;
import com.baomidou.mybatisplus.extension.parser.JsqlParserSupport; import com.baomidou.mybatisplus.extension.parser.JsqlParserSupport;
import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
import org.dromara.common.mybatis.annotation.DataColumn;
import org.dromara.common.mybatis.handler.PlusDataPermissionHandler; import org.dromara.common.mybatis.handler.PlusDataPermissionHandler;
import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.statement.delete.Delete; import net.sf.jsqlparser.statement.delete.Delete;
@ -23,6 +26,7 @@ import org.apache.ibatis.session.RowBounds;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* *
@ -33,6 +37,10 @@ import java.util.List;
public class PlusDataPermissionInterceptor extends JsqlParserSupport implements InnerInterceptor { public class PlusDataPermissionInterceptor extends JsqlParserSupport implements InnerInterceptor {
private final PlusDataPermissionHandler dataPermissionHandler = new PlusDataPermissionHandler(); private final PlusDataPermissionHandler dataPermissionHandler = new PlusDataPermissionHandler();
/**
*
*/
private final Set<String> invalidCacheSet = new ConcurrentHashSet<>();
@Override @Override
public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException { public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
@ -41,7 +49,12 @@ public class PlusDataPermissionInterceptor extends JsqlParserSupport implements
return; return;
} }
// 检查是否无效 无数据权限注解 // 检查是否无效 无数据权限注解
if (dataPermissionHandler.isInvalid(ms.getId())) { if (invalidCacheSet.contains(ms.getId())) {
return;
}
DataColumn[] dataColumns = dataPermissionHandler.findAnnotation(ms.getId());
if (ArrayUtil.isEmpty(dataColumns)) {
invalidCacheSet.add(ms.getId());
return; return;
} }
// 解析 sql 分配对应方法 // 解析 sql 分配对应方法
@ -58,6 +71,15 @@ public class PlusDataPermissionInterceptor extends JsqlParserSupport implements
if (InterceptorIgnoreHelper.willIgnoreDataPermission(ms.getId())) { if (InterceptorIgnoreHelper.willIgnoreDataPermission(ms.getId())) {
return; return;
} }
// 检查是否无效 无数据权限注解
if (invalidCacheSet.contains(ms.getId())) {
return;
}
DataColumn[] dataColumns = dataPermissionHandler.findAnnotation(ms.getId());
if (ArrayUtil.isEmpty(dataColumns)) {
invalidCacheSet.add(ms.getId());
return;
}
PluginUtils.MPBoundSql mpBs = mpSh.mPBoundSql(); PluginUtils.MPBoundSql mpBs = mpSh.mPBoundSql();
mpBs.sql(parserMulti(mpBs.sql(), ms.getId())); mpBs.sql(parserMulti(mpBs.sql(), ms.getId()));
} }

@ -96,7 +96,7 @@ public class RedisConfiguration {
* redis yml * redis yml
* *
* --- # redis () * --- # redis ()
* spring: * spring.data:
* redis: * redis:
* cluster: * cluster:
* nodes: * nodes:
@ -108,7 +108,7 @@ public class RedisConfiguration {
* # * #
* timeout: 10s * timeout: 10s
* # ssl * # ssl
* ssl: false * ssl.enabled: false
* *
* redisson: * redisson:
* # 线 * # 线

@ -43,10 +43,6 @@
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>*</artifactId> <artifactId>*</artifactId>
</exclusion> </exclusion>
<exclusion>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</exclusion>
<exclusion> <exclusion>
<groupId>org.apache.dubbo.extensions</groupId> <groupId>org.apache.dubbo.extensions</groupId>
<artifactId>dubbo-filter-seata</artifactId> <artifactId>dubbo-filter-seata</artifactId>

@ -21,4 +21,8 @@ import java.lang.annotation.Target;
@JsonSerialize(using = SensitiveHandler.class) @JsonSerialize(using = SensitiveHandler.class)
public @interface Sensitive { public @interface Sensitive {
SensitiveStrategy strategy(); SensitiveStrategy strategy();
String roleKey() default "";
String perms() default "";
} }

@ -13,6 +13,6 @@ public interface SensitiveService {
/** /**
* *
*/ */
boolean isSensitive(); boolean isSensitive(String roleKey, String perms);
} }

@ -26,12 +26,14 @@ import java.util.Objects;
public class SensitiveHandler extends JsonSerializer<String> implements ContextualSerializer { public class SensitiveHandler extends JsonSerializer<String> implements ContextualSerializer {
private SensitiveStrategy strategy; private SensitiveStrategy strategy;
private String roleKey;
private String perms;
@Override @Override
public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException { public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
try { try {
SensitiveService sensitiveService = SpringUtils.getBean(SensitiveService.class); SensitiveService sensitiveService = SpringUtils.getBean(SensitiveService.class);
if (ObjectUtil.isNotNull(sensitiveService) && sensitiveService.isSensitive()) { if (ObjectUtil.isNotNull(sensitiveService) && sensitiveService.isSensitive(roleKey, perms)) {
gen.writeString(strategy.desensitizer().apply(value)); gen.writeString(strategy.desensitizer().apply(value));
} else { } else {
gen.writeString(value); gen.writeString(value);
@ -47,6 +49,8 @@ public class SensitiveHandler extends JsonSerializer<String> implements Contextu
Sensitive annotation = property.getAnnotation(Sensitive.class); Sensitive annotation = property.getAnnotation(Sensitive.class);
if (Objects.nonNull(annotation) && Objects.equals(String.class, property.getType().getRawClass())) { if (Objects.nonNull(annotation) && Objects.equals(String.class, property.getType().getRawClass())) {
this.strategy = annotation.strategy(); this.strategy = annotation.strategy();
this.roleKey = annotation.roleKey();
this.perms = annotation.perms();
return this; return this;
} }
return prov.findValueSerializer(property.getType(), property); return prov.findValueSerializer(property.getType(), property);

@ -63,9 +63,9 @@ public class AuthMaxKeyRequest extends AuthDefaultRequest {
throw new AuthException(object.getStr("message")); throw new AuthException(object.getStr("message"));
} }
return AuthUser.builder() return AuthUser.builder()
.uuid(object.getStr("id")) .uuid(object.getStr("userId"))
.username(object.getStr("username")) .username(object.getStr("username"))
.nickname(object.getStr("name")) .nickname(object.getStr("displayName"))
.avatar(object.getStr("avatar_url")) .avatar(object.getStr("avatar_url"))
.blog(object.getStr("web_url")) .blog(object.getStr("web_url"))
.company(object.getStr("organization")) .company(object.getStr("organization"))

@ -7,7 +7,6 @@ import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthResponse; import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.request.*; import me.zhyd.oauth.request.*;
import org.dromara.common.core.domain.model.LoginBody;
import org.dromara.common.core.utils.SpringUtils; import org.dromara.common.core.utils.SpringUtils;
import org.dromara.common.social.config.properties.SocialLoginConfigProperties; import org.dromara.common.social.config.properties.SocialLoginConfigProperties;
import org.dromara.common.social.config.properties.SocialProperties; 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); private static final AuthRedisStateCache STATE_CACHE = SpringUtils.getBean(AuthRedisStateCache.class);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static AuthResponse<AuthUser> loginAuth(LoginBody loginBody, SocialProperties socialProperties) throws AuthException { public static AuthResponse<AuthUser> loginAuth(String source, String code, String state, SocialProperties socialProperties) throws AuthException {
AuthRequest authRequest = getAuthRequest(loginBody.getSource(), socialProperties); AuthRequest authRequest = getAuthRequest(source, socialProperties);
AuthCallback callback = new AuthCallback(); AuthCallback callback = new AuthCallback();
callback.setCode(loginBody.getSocialCode()); callback.setCode(code);
callback.setState(loginBody.getSocialState()); callback.setState(state);
return authRequest.login(callback); return authRequest.login(callback);
} }

@ -2,15 +2,15 @@ package org.dromara.common.tenant.handle;
import cn.hutool.core.collection.ListUtil; import cn.hutool.core.collection.ListUtil;
import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler; import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.NullValue;
import net.sf.jsqlparser.expression.StringValue;
import org.dromara.common.core.utils.StringUtils; import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.common.tenant.helper.TenantHelper; import org.dromara.common.tenant.helper.TenantHelper;
import org.dromara.common.tenant.properties.TenantProperties; import org.dromara.common.tenant.properties.TenantProperties;
import lombok.AllArgsConstructor;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.NullValue;
import net.sf.jsqlparser.expression.StringValue;
import java.util.List; import java.util.List;
@ -27,16 +27,11 @@ public class PlusTenantLineHandler implements TenantLineHandler {
@Override @Override
public Expression getTenantId() { public Expression getTenantId() {
String tenantId = LoginHelper.getTenantId(); String tenantId = TenantHelper.getTenantId();
if (StringUtils.isBlank(tenantId)) { if (StringUtils.isBlank(tenantId)) {
log.error("无法获取有效的租户id -> Null"); log.error("无法获取有效的租户id -> Null");
return new NullValue(); return new NullValue();
} }
String dynamicTenantId = TenantHelper.getDynamic();
if (StringUtils.isNotBlank(dynamicTenantId)) {
// 返回动态租户
return new StringValue(dynamicTenantId);
}
// 返回固定租户 // 返回固定租户
return new StringValue(tenantId); return new StringValue(tenantId);
} }

@ -33,7 +33,7 @@ public class TenantKeyPrefixHandler extends KeyPrefixHandler {
if (StringUtils.isBlank(tenantId)) { if (StringUtils.isBlank(tenantId)) {
log.error("无法获取有效的租户id -> Null"); log.error("无法获取有效的租户id -> Null");
} }
if (StringUtils.startsWith(name, tenantId)) { if (StringUtils.startsWith(name, tenantId + "")) {
// 如果存在则直接返回 // 如果存在则直接返回
return super.map(name); return super.map(name);
} }
@ -56,7 +56,7 @@ public class TenantKeyPrefixHandler extends KeyPrefixHandler {
if (StringUtils.isBlank(tenantId)) { if (StringUtils.isBlank(tenantId)) {
log.error("无法获取有效的租户id -> Null"); log.error("无法获取有效的租户id -> Null");
} }
if (StringUtils.startsWith(unmap, tenantId)) { if (StringUtils.startsWith(unmap, tenantId + "")) {
// 如果存在则删除 // 如果存在则删除
return unmap.substring((tenantId + ":").length()); return unmap.substring((tenantId + ":").length());
} }

@ -40,7 +40,6 @@ public class PlusWebSocketHandler extends AbstractWebSocketHandler {
@Override @Override
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
LoginUser loginUser = (LoginUser) session.getAttributes().get(LOGIN_USER_KEY); LoginUser loginUser = (LoginUser) session.getAttributes().get(LOGIN_USER_KEY);
log.info("PlusWebSocketHandler, 连接:" + session.getId() + ",已收到消息:" + message.getPayload());
List<Long> userIds = List.of(loginUser.getUserId()); List<Long> userIds = List.of(loginUser.getUserId());
WebSocketMessageDto webSocketMessageDto = new WebSocketMessageDto(); WebSocketMessageDto webSocketMessageDto = new WebSocketMessageDto();
webSocketMessageDto.setSessionKeys(userIds); webSocketMessageDto.setSessionKeys(userIds);

@ -7,7 +7,6 @@ import lombok.extern.slf4j.Slf4j;
import org.dromara.common.redis.utils.RedisUtils; import org.dromara.common.redis.utils.RedisUtils;
import org.dromara.common.websocket.dto.WebSocketMessageDto; import org.dromara.common.websocket.dto.WebSocketMessageDto;
import org.dromara.common.websocket.holder.WebSocketSessionHolder; import org.dromara.common.websocket.holder.WebSocketSessionHolder;
import org.dromara.system.api.model.LoginUser;
import org.springframework.web.socket.PongMessage; import org.springframework.web.socket.PongMessage;
import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketMessage; import org.springframework.web.socket.WebSocketMessage;
@ -18,7 +17,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
import static org.dromara.common.websocket.constant.WebSocketConstants.LOGIN_USER_KEY;
import static org.dromara.common.websocket.constant.WebSocketConstants.WEB_SOCKET_TOPIC; import static org.dromara.common.websocket.constant.WebSocketConstants.WEB_SOCKET_TOPIC;
/** /**
@ -71,7 +69,7 @@ public class WebSocketUtils {
broadcastMessage.setMessage(webSocketMessage.getMessage()); broadcastMessage.setMessage(webSocketMessage.getMessage());
broadcastMessage.setSessionKeys(unsentSessionKeys); broadcastMessage.setSessionKeys(unsentSessionKeys);
RedisUtils.publish(WEB_SOCKET_TOPIC, broadcastMessage, consumer -> { RedisUtils.publish(WEB_SOCKET_TOPIC, broadcastMessage, consumer -> {
log.info(" WebSocket发送主题订阅消息topic:{} session keys:{} message:{}", log.info("WebSocket发送主题订阅消息topic:{} session keys:{} message:{}",
WEB_SOCKET_TOPIC, unsentSessionKeys, webSocketMessage.getMessage()); WEB_SOCKET_TOPIC, unsentSessionKeys, webSocketMessage.getMessage());
}); });
} }
@ -83,13 +81,10 @@ public class WebSocketUtils {
* @param message * @param message
*/ */
public static void publishAll(String message) { public static void publishAll(String message) {
WebSocketSessionHolder.getSessionsAll().forEach(key -> {
WebSocketUtils.sendMessage(key, message);
});
WebSocketMessageDto broadcastMessage = new WebSocketMessageDto(); WebSocketMessageDto broadcastMessage = new WebSocketMessageDto();
broadcastMessage.setMessage(message); broadcastMessage.setMessage(message);
RedisUtils.publish(WEB_SOCKET_TOPIC, broadcastMessage, consumer -> { RedisUtils.publish(WEB_SOCKET_TOPIC, broadcastMessage, consumer -> {
log.info(" WebSocket发送主题订阅消息topic:{} message:{}", WEB_SOCKET_TOPIC, message); log.info("WebSocket发送主题订阅消息topic:{} message:{}", WEB_SOCKET_TOPIC, message);
}); });
} }
@ -106,10 +101,7 @@ public class WebSocketUtils {
log.error("[send] session会话已经关闭"); log.error("[send] session会话已经关闭");
} else { } else {
try { try {
// 获取当前会话中的用户
LoginUser loginUser = (LoginUser) session.getAttributes().get(LOGIN_USER_KEY);
session.sendMessage(message); session.sendMessage(message);
log.info("[send] sessionId: {},userId:{},userType:{},message:{}", session.getId(), loginUser.getUserId(), loginUser.getUserType(), message);
} catch (IOException e) { } catch (IOException e) {
log.error("[send] session({}) 发送消息({}) 异常", session, message, e); log.error("[send] session({}) 发送消息({}) 异常", session, message, e);
} }

@ -49,25 +49,25 @@ public class TestSensitiveController extends BaseController {
/** /**
* *
*/ */
@Sensitive(strategy = SensitiveStrategy.PHONE) @Sensitive(strategy = SensitiveStrategy.PHONE, roleKey = "common")
private String phone; private String phone;
/** /**
* *
*/ */
@Sensitive(strategy = SensitiveStrategy.ADDRESS) @Sensitive(strategy = SensitiveStrategy.ADDRESS, perms = "system:user:query")
private String address; private String address;
/** /**
* *
*/ */
@Sensitive(strategy = SensitiveStrategy.EMAIL) @Sensitive(strategy = SensitiveStrategy.EMAIL, roleKey = "common", perms = "system:user:query1")
private String email; private String email;
/** /**
* *
*/ */
@Sensitive(strategy = SensitiveStrategy.BANK_CARD) @Sensitive(strategy = SensitiveStrategy.BANK_CARD, roleKey = "common1", perms = "system:user:query")
private String bankCard; private String bankCard;
} }

@ -1,7 +1,10 @@
package org.dromara.demo.service.impl; package org.dromara.demo.service.impl;
import cn.dev33.satoken.stp.StpUtil;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.common.sensitive.core.SensitiveService; import org.dromara.common.sensitive.core.SensitiveService;
import org.dromara.common.tenant.helper.TenantHelper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
@ -18,7 +21,25 @@ public class SensitiveServiceImpl implements SensitiveService {
* *
*/ */
@Override @Override
public boolean isSensitive() { public boolean isSensitive(String roleKey, String perms) {
if (!StpUtil.isLogin()) {
return true;
}
boolean roleExist = StringUtils.isNotBlank(roleKey);
boolean permsExist = StringUtils.isNotBlank(perms);
if (roleExist && permsExist) {
if (StpUtil.hasRole(roleKey) && StpUtil.hasPermission(perms)) {
return false;
}
} else if (roleExist && StpUtil.hasRole(roleKey)) {
return false;
} else if (permsExist && StpUtil.hasPermission(perms)) {
return false;
}
if (TenantHelper.isEnable()) {
return !LoginHelper.isSuperAdmin() && !LoginHelper.isTenantAdmin();
}
return !LoginHelper.isSuperAdmin(); return !LoginHelper.isSuperAdmin();
} }

@ -79,7 +79,7 @@ public class GenController extends BaseController {
*/ */
@SaCheckPermission("tool:gen:list") @SaCheckPermission("tool:gen:list")
@GetMapping(value = "/column/{tableId}") @GetMapping(value = "/column/{tableId}")
public TableDataInfo<GenTableColumn> columnList(Long tableId) { public TableDataInfo<GenTableColumn> columnList(@PathVariable("tableId") Long tableId) {
TableDataInfo<GenTableColumn> dataInfo = new TableDataInfo<>(); TableDataInfo<GenTableColumn> dataInfo = new TableDataInfo<>();
List<GenTableColumn> list = genTableService.selectGenTableColumnListByTableId(tableId); List<GenTableColumn> list = genTableService.selectGenTableColumnListByTableId(tableId);
dataInfo.setRows(list); dataInfo.setRows(list);

@ -10,7 +10,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult"> <select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">
<if test="@org.dromara.common.mybatis.helper.DataBaseHelper@isMySql()"> <if test="@org.dromara.common.mybatis.helper.DataBaseHelper@isMySql()">
select column_name, select column_name,
(case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else null end) as is_required, (case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else '0' end) as is_required,
(case when column_key = 'PRI' then '1' else '0' end) as is_pk, (case when column_key = 'PRI' then '1' else '0' end) as is_pk,
ordinal_position as sort, ordinal_position as sort,
column_comment, column_comment,
@ -21,7 +21,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if> </if>
<if test="@org.dromara.common.mybatis.helper.DataBaseHelper@isOracle()"> <if test="@org.dromara.common.mybatis.helper.DataBaseHelper@isOracle()">
select lower(temp.column_name) as column_name, select lower(temp.column_name) as column_name,
(case when (temp.nullable = 'N' and temp.constraint_type != 'P') then '1' else null end) as is_required, (case when (temp.nullable = 'N' and temp.constraint_type != 'P') then '1' else '0' end) as is_required,
(case when temp.constraint_type = 'P' then '1' else '0' end) as is_pk, (case when temp.constraint_type = 'P' then '1' else '0' end) as is_pk,
temp.column_id as sort, temp.column_id as sort,
temp.comments as column_comment, temp.comments as column_comment,

@ -0,0 +1,42 @@
package org.dromara.resource.dubbo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.dromara.common.websocket.utils.WebSocketUtils;
import org.dromara.resource.api.RemoteMessageService;
import org.springframework.stereotype.Service;
/**
*
*
* @author Lion Li
*/
@Slf4j
@RequiredArgsConstructor
@Service
@DubboService
public class RemoteMessageServiceImpl implements RemoteMessageService {
/**
*
*
* @param sessionKey session id
* @param message
*/
@Override
public void sendMessage(Long sessionKey, String message) {
WebSocketUtils.sendMessage(sessionKey, message);
}
/**
* ()
*
* @param message
*/
@Override
public void publishAll(String message) {
WebSocketUtils.publishAll(message);
}
}

@ -66,8 +66,12 @@ public class SysOssServiceImpl implements ISysOssService {
for (Long id : ossIds) { for (Long id : ossIds) {
SysOssVo vo = getById(id); SysOssVo vo = getById(id);
if (ObjectUtil.isNotNull(vo)) { if (ObjectUtil.isNotNull(vo)) {
list.add(this.matchingUrl(vo)); try {
} list.add(this.matchingUrl(vo));
} catch (Exception ignored) {
// 如果oss异常无法连接则将数据直接返回
list.add(vo);
} }
} }
return list; return list;
} }
@ -78,7 +82,12 @@ public class SysOssServiceImpl implements ISysOssService {
for (Long id : StringUtils.splitTo(ossIds, Convert::toLong)) { for (Long id : StringUtils.splitTo(ossIds, Convert::toLong)) {
SysOssVo vo = SpringUtils.getAopProxy(this).getById(id); SysOssVo vo = SpringUtils.getAopProxy(this).getById(id);
if (ObjectUtil.isNotNull(vo)) { if (ObjectUtil.isNotNull(vo)) {
list.add(this.matchingUrl(vo).getUrl()); try {
list.add(this.matchingUrl(vo).getUrl());
} catch (Exception ignored) {
// 如果oss异常无法连接则将数据直接返回
list.add(vo.getUrl());
}
} }
} }
return String.join(StringUtils.SEPARATOR, list); return String.join(StringUtils.SEPARATOR, list);

@ -2,12 +2,15 @@ package org.dromara.system.controller.system;
import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.common.core.domain.R; import org.dromara.common.core.domain.R;
import org.dromara.common.core.service.DictService;
import org.dromara.common.web.core.BaseController; import org.dromara.common.web.core.BaseController;
import org.dromara.common.log.annotation.Log; import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType; import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.resource.api.RemoteMessageService;
import org.dromara.system.domain.bo.SysNoticeBo; import org.dromara.system.domain.bo.SysNoticeBo;
import org.dromara.system.domain.vo.SysNoticeVo; import org.dromara.system.domain.vo.SysNoticeVo;
import org.dromara.system.service.ISysNoticeService; import org.dromara.system.service.ISysNoticeService;
@ -26,6 +29,10 @@ import org.springframework.web.bind.annotation.*;
public class SysNoticeController extends BaseController { public class SysNoticeController extends BaseController {
private final ISysNoticeService noticeService; private final ISysNoticeService noticeService;
private final DictService dictService;
@DubboReference
private final RemoteMessageService remoteMessageService;
/** /**
* *
@ -54,7 +61,13 @@ public class SysNoticeController extends BaseController {
@Log(title = "通知公告", businessType = BusinessType.INSERT) @Log(title = "通知公告", businessType = BusinessType.INSERT)
@PostMapping @PostMapping
public R<Void> add(@Validated @RequestBody SysNoticeBo notice) { public R<Void> add(@Validated @RequestBody SysNoticeBo notice) {
return toAjax(noticeService.insertNotice(notice)); int rows = noticeService.insertNotice(notice);
if (rows <= 0) {
return R.fail();
}
String type = dictService.getDictLabel("sys_notice_type", notice.getNoticeType());
remoteMessageService.publishAll("[" + type + "] " + notice.getNoticeTitle());
return R.ok();
} }
/** /**

@ -185,7 +185,7 @@ public class SysMenu extends BaseEntity {
* *
*/ */
public static String innerLinkReplaceEach(String path) { public static String innerLinkReplaceEach(String path) {
return StringUtils.replaceEach(path, new String[]{Constants.HTTP, Constants.HTTPS, Constants.WWW, "."}, return StringUtils.replaceEach(path, new String[]{Constants.HTTP, Constants.HTTPS, Constants.WWW, ".", ":"},
new String[]{"", "", "", "/"}); new String[]{"", "", "", "/", "/"});
} }
} }

@ -82,9 +82,9 @@ public class SysDeptServiceImpl implements ISysDeptService{
lqw.eq(ObjectUtil.isNotNull(bo.getParentId()), SysDept::getParentId, bo.getParentId()); lqw.eq(ObjectUtil.isNotNull(bo.getParentId()), SysDept::getParentId, bo.getParentId());
lqw.like(StringUtils.isNotBlank(bo.getDeptName()), SysDept::getDeptName, bo.getDeptName()); lqw.like(StringUtils.isNotBlank(bo.getDeptName()), SysDept::getDeptName, bo.getDeptName());
lqw.eq(StringUtils.isNotBlank(bo.getStatus()), SysDept::getStatus, bo.getStatus()); lqw.eq(StringUtils.isNotBlank(bo.getStatus()), SysDept::getStatus, bo.getStatus());
lqw.orderByAsc(SysDept::getDeptId);
lqw.orderByAsc(SysDept::getParentId); lqw.orderByAsc(SysDept::getParentId);
lqw.orderByAsc(SysDept::getOrderNum); lqw.orderByAsc(SysDept::getOrderNum);
lqw.orderByAsc(SysDept::getDeptId);
return lqw; return lqw;
} }

@ -192,20 +192,22 @@ public class SysRoleServiceImpl implements ISysRoleService {
if (ObjectUtil.isNotNull(role.getRoleId()) && LoginHelper.isSuperAdmin(role.getRoleId())) { if (ObjectUtil.isNotNull(role.getRoleId()) && LoginHelper.isSuperAdmin(role.getRoleId())) {
throw new ServiceException("不允许操作超级管理员角色"); throw new ServiceException("不允许操作超级管理员角色");
} }
String[] keys = new String[]{TenantConstants.SUPER_ADMIN_ROLE_KEY, TenantConstants.TENANT_ADMIN_ROLE_KEY};
// 新增不允许使用 管理员标识符 // 新增不允许使用 管理员标识符
if (ObjectUtil.isNull(role.getRoleId()) if (ObjectUtil.isNull(role.getRoleId())
&& StringUtils.equalsAny(role.getRoleKey(), && StringUtils.equalsAny(role.getRoleKey(), keys)) {
TenantConstants.SUPER_ADMIN_ROLE_KEY, TenantConstants.TENANT_ADMIN_ROLE_KEY)) {
throw new ServiceException("不允许使用系统内置管理员角色标识符!"); throw new ServiceException("不允许使用系统内置管理员角色标识符!");
} }
// 修改不允许修改 管理员标识符 // 修改不允许修改 管理员标识符
if (ObjectUtil.isNotNull(role.getRoleId())) { if (ObjectUtil.isNotNull(role.getRoleId())) {
SysRole sysRole = baseMapper.selectById(role.getRoleId()); SysRole sysRole = baseMapper.selectById(role.getRoleId());
// 如果标识符不相等 判断为修改了管理员标识符 // 如果标识符不相等 判断为修改了管理员标识符
if (!StringUtils.equals(sysRole.getRoleKey(), role.getRoleKey()) if (!StringUtils.equals(sysRole.getRoleKey(), role.getRoleKey())) {
&& StringUtils.equalsAny(sysRole.getRoleKey(), if (StringUtils.equalsAny(sysRole.getRoleKey(), keys)) {
TenantConstants.SUPER_ADMIN_ROLE_KEY, TenantConstants.TENANT_ADMIN_ROLE_KEY)) { throw new ServiceException("不允许修改系统内置管理员角色标识符!");
throw new ServiceException("不允许修改系统内置管理员角色标识符!"); } else if (StringUtils.equalsAny(role.getRoleKey(), keys)) {
throw new ServiceException("不允许使用系统内置管理员角色标识符!");
}
} }
} }
} }

@ -1,5 +1,7 @@
package org.dromara.system.service.impl; package org.dromara.system.service.impl;
import cn.dev33.satoken.stp.StpUtil;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.common.sensitive.core.SensitiveService; import org.dromara.common.sensitive.core.SensitiveService;
import org.dromara.common.tenant.helper.TenantHelper; import org.dromara.common.tenant.helper.TenantHelper;
@ -20,7 +22,22 @@ public class SysSensitiveServiceImpl implements SensitiveService {
* *
*/ */
@Override @Override
public boolean isSensitive() { public boolean isSensitive(String roleKey, String perms) {
if (!StpUtil.isLogin()) {
return true;
}
boolean roleExist = StringUtils.isNotEmpty(roleKey);
boolean permsExist = StringUtils.isNotEmpty(perms);
if (roleExist && permsExist) {
if (StpUtil.hasRole(roleKey) && StpUtil.hasPermission(perms)) {
return false;
}
} else if (roleExist && StpUtil.hasRole(roleKey)) {
return false;
} else if (permsExist && StpUtil.hasPermission(perms)) {
return false;
}
if (TenantHelper.isEnable()) { if (TenantHelper.isEnable()) {
return !LoginHelper.isSuperAdmin() && !LoginHelper.isTenantAdmin(); return !LoginHelper.isSuperAdmin() && !LoginHelper.isTenantAdmin();
} }

@ -173,7 +173,7 @@ create table if not exists sys_dept
ancestors varchar(500)default ''::varchar, ancestors varchar(500)default ''::varchar,
dept_name varchar(30) default ''::varchar, dept_name varchar(30) default ''::varchar,
order_num int4 default 0, order_num int4 default 0,
leader int8 default null::varchar, leader int8 default null,
phone varchar(11) default null::varchar, phone varchar(11) default null::varchar,
email varchar(50) default null::varchar, email varchar(50) default null::varchar,
status char default '0'::bpchar, status char default '0'::bpchar,

Loading…
Cancel
Save