Merge remote-tracking branch 'origin/master'
# Conflicts: # cloud-auth/src/main/resources/bootstrap.yml # cloud-gateway/src/main/resources/bootstrap.yml # cloud-modules/cloud-modules-file/src/main/resources/bootstrap.yml # cloud-modules/cloud-modules-gen/src/main/resources/bootstrap.yml # cloud-modules/cloud-modules-system/src/main/resources/bootstrap.yml # cloud-visual/cloud-visual-monitor/src/main/resources/bootstrap.ymlmaster
commit
50a58d2470
|
@ -7,7 +7,7 @@ nacos:
|
||||||
addr: 106.15.136.7:8848
|
addr: 106.15.136.7:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: lyb
|
namespace: xzr
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
|
|
|
@ -45,4 +45,9 @@ public class SecurityConstants {
|
||||||
* 角色权限
|
* 角色权限
|
||||||
*/
|
*/
|
||||||
public static final String ROLE_PERMISSION = "role_permission";
|
public static final String ROLE_PERMISSION = "role_permission";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SaaS标识
|
||||||
|
*/
|
||||||
|
public static final String SAAS_KEY = "ent-code";
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,4 +162,13 @@ public class JwtUtils {
|
||||||
public static String getValue (Claims claims, String key) {
|
public static String getValue (Claims claims, String key) {
|
||||||
return Convert.toStr(claims.get(key), "");
|
return Convert.toStr(claims.get(key), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据身份信息获取SaaS标识
|
||||||
|
* @param claims 身份信息
|
||||||
|
* @return Saas标识
|
||||||
|
*/
|
||||||
|
public static String getSaaSKey (Claims claims) {
|
||||||
|
return getValue(claims, SecurityConstants.SAAS_KEY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import com.muyu.cloud.common.saas.domain.model.EntInfo;
|
||||||
import com.muyu.cloud.common.saas.exception.SaaSException;
|
import com.muyu.cloud.common.saas.exception.SaaSException;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.common.core.utils.SpringUtils;
|
import com.muyu.common.core.utils.SpringUtils;
|
||||||
|
import com.muyu.common.core.utils.StringUtils;
|
||||||
import com.muyu.common.system.domain.SysUser;
|
import com.muyu.common.system.domain.SysUser;
|
||||||
import com.muyu.common.system.remote.RemoteUserService;
|
import com.muyu.common.system.remote.RemoteUserService;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
@ -78,7 +79,7 @@ public class ManyDataSource implements ApplicationRunner {
|
||||||
)
|
)
|
||||||
.toList();
|
.toList();
|
||||||
}else {
|
}else {
|
||||||
log.error("远调数据源错误,远调数据为:{}", JSON.toJSONString(data));
|
log.error("远调数据源异常,异常信息:{}", JSON.toJSONString(entListResult.getMsg()));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,29 +92,21 @@ public class ManyDataSource implements ApplicationRunner {
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public DynamicDataSource dynamicDataSource(DruidDataSourceFactory druidDataSourceFactory) {
|
public DynamicDataSource dynamicDataSource(DruidDataSourceFactory druidDataSourceFactory) {
|
||||||
List<DataSourceInfo> sourceInfoList = dataSourceInfoList().stream()
|
List<EntInfo> entInfoList = dataSourceInfoList();
|
||||||
|
if(StringUtils.isEmpty(entInfoList)){
|
||||||
|
throw new SaaSException("数据源信息列表为空或为null");
|
||||||
|
}
|
||||||
|
Map<Object, Object> dataSourceMap = dataSourceInfoList().stream()
|
||||||
.map(entInfo -> DataSourceInfo.hostAndPortBuild(
|
.map(entInfo -> DataSourceInfo.hostAndPortBuild(
|
||||||
entInfo.getEntCode(),
|
entInfo.getEntCode(),
|
||||||
entInfo.getIp(),
|
entInfo.getIp(),
|
||||||
entInfo.getPort()
|
entInfo.getPort()
|
||||||
)
|
)
|
||||||
).toList();
|
)
|
||||||
|
.collect(Collectors.toMap(
|
||||||
Map<Object, Object> dataSourceMap = sourceInfoList.stream().collect(Collectors.toMap(
|
|
||||||
dataSourceInfo -> dataSourceInfo.getKey(),
|
dataSourceInfo -> dataSourceInfo.getKey(),
|
||||||
dataSourceInfo -> druidDataSourceFactory.create(dataSourceInfo)
|
dataSourceInfo -> druidDataSourceFactory.create(dataSourceInfo)
|
||||||
));
|
));
|
||||||
// Map<Object, Object> dataSourceMap = dataSourceInfoList().stream()
|
|
||||||
// .map(entInfo -> DataSourceInfo.hostAndPortBuild(
|
|
||||||
// entInfo.getEntCode(),
|
|
||||||
// entInfo.getIp(),
|
|
||||||
// entInfo.getPort()
|
|
||||||
// )
|
|
||||||
// )
|
|
||||||
// .collect(Collectors.toMap(
|
|
||||||
// dataSourceInfo -> dataSourceInfo.getKey(),
|
|
||||||
// dataSourceInfo -> druidDataSourceFactory.create(dataSourceInfo)
|
|
||||||
// ));
|
|
||||||
|
|
||||||
//设置动态数据源
|
//设置动态数据源
|
||||||
DynamicDataSource dynamicDataSource = new DynamicDataSource();
|
DynamicDataSource dynamicDataSource = new DynamicDataSource();
|
||||||
|
@ -121,19 +114,4 @@ public class ManyDataSource implements ApplicationRunner {
|
||||||
dynamicDataSource.setDefineTargetDataSources(dataSourceMap);
|
dynamicDataSource.setDefineTargetDataSources(dataSourceMap);
|
||||||
return dynamicDataSource;
|
return dynamicDataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建 SqlSessionFactory Bean,用于 MyBatis 数据库操作。
|
|
||||||
* 该方法接收动态数据源并配置 SqlSessionFactory,返回
|
|
||||||
* 用于与数据库交互的 SqlSessionFactory 实例。
|
|
||||||
* @param dataSource 动态数据源
|
|
||||||
* @return 配置好的 SqlSessionFactory 实例
|
|
||||||
* @throws Exception 可能抛出的异常
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public SqlSessionFactory sqlSessionFactory(DynamicDataSource dataSource) throws Exception {
|
|
||||||
SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
|
|
||||||
sessionFactory.setDataSource(dataSource);
|
|
||||||
return sessionFactory.getObject();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,7 @@ public class TokenService {
|
||||||
claimsMap.put(SecurityConstants.USER_KEY, token);
|
claimsMap.put(SecurityConstants.USER_KEY, token);
|
||||||
claimsMap.put(SecurityConstants.DETAILS_USER_ID, userId);
|
claimsMap.put(SecurityConstants.DETAILS_USER_ID, userId);
|
||||||
claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName);
|
claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName);
|
||||||
|
claimsMap.put(SecurityConstants.SAAS_KEY, loginUser.getSysUser().getDatabaseName());
|
||||||
|
|
||||||
// 接口返回信息
|
// 接口返回信息
|
||||||
Map<String, Object> rspMap = new HashMap<String, Object>();
|
Map<String, Object> rspMap = new HashMap<String, Object>();
|
||||||
|
|
|
@ -63,7 +63,8 @@ public class AuthFilter implements GlobalFilter, Ordered {
|
||||||
}
|
}
|
||||||
String userid = JwtUtils.getUserId(claims);
|
String userid = JwtUtils.getUserId(claims);
|
||||||
String username = JwtUtils.getUserName(claims);
|
String username = JwtUtils.getUserName(claims);
|
||||||
if (StringUtils.isEmpty(userid) || StringUtils.isEmpty(username)) {
|
String saaSKey = JwtUtils.getSaaSKey(claims);
|
||||||
|
if (StringUtils.isEmpty(userid) || StringUtils.isEmpty(username) || StringUtils.isEmpty(saaSKey)) {
|
||||||
return unauthorizedResponse(exchange, "令牌验证失败");
|
return unauthorizedResponse(exchange, "令牌验证失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,6 +72,8 @@ public class AuthFilter implements GlobalFilter, Ordered {
|
||||||
addHeader(mutate, SecurityConstants.USER_KEY, userkey);
|
addHeader(mutate, SecurityConstants.USER_KEY, userkey);
|
||||||
addHeader(mutate, SecurityConstants.DETAILS_USER_ID, userid);
|
addHeader(mutate, SecurityConstants.DETAILS_USER_ID, userid);
|
||||||
addHeader(mutate, SecurityConstants.DETAILS_USERNAME, username);
|
addHeader(mutate, SecurityConstants.DETAILS_USERNAME, username);
|
||||||
|
addHeader(mutate, SecurityConstants.SAAS_KEY, saaSKey);
|
||||||
|
|
||||||
// 内部请求来源参数清除
|
// 内部请求来源参数清除
|
||||||
removeHeader(mutate, SecurityConstants.FROM_SOURCE);
|
removeHeader(mutate, SecurityConstants.FROM_SOURCE);
|
||||||
return chain.filter(exchange.mutate().request(mutate.build()).build());
|
return chain.filter(exchange.mutate().request(mutate.build()).build());
|
||||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
||||||
addr: 106.15.136.7:8848
|
addr: 106.15.136.7:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: lyb
|
namespace: xzr
|
||||||
|
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
spring:
|
||||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
||||||
addr: 106.15.136.7:8848
|
addr: 106.15.136.7:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: crj
|
namespace: xzr
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
||||||
addr: 106.15.136.7:8848
|
addr: 106.15.136.7:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: lyb
|
namespace: xzr
|
||||||
|
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
spring:
|
||||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
||||||
addr: 106.15.136.7:8848
|
addr: 106.15.136.7:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: lyb
|
namespace: xzr
|
||||||
|
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
spring:
|
||||||
|
|
|
@ -7,9 +7,15 @@ nacos:
|
||||||
addr: 106.15.136.7:8848
|
addr: 106.15.136.7:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: lyb
|
namespace: xzr
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
|
amqp:
|
||||||
|
deserialization:
|
||||||
|
trust:
|
||||||
|
all: true
|
||||||
|
main:
|
||||||
|
allow-bean-definition-overriding: true
|
||||||
application:
|
application:
|
||||||
# 应用名称
|
# 应用名称
|
||||||
name: cloud-system
|
name: cloud-system
|
||||||
|
@ -44,6 +50,10 @@ spring:
|
||||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
# 系统环境Config共享配置
|
# 系统环境Config共享配置
|
||||||
- application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
- application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
# xxl-job 配置文件
|
||||||
|
- application-xxl-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
# rabbit 配置文件
|
||||||
|
- application-rabbit-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
com.muyu.system.mapper: DEBUG
|
com.muyu.system.mapper: DEBUG
|
||||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
||||||
addr: 106.15.136.7:8848
|
addr: 106.15.136.7:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: lyb
|
namespace: xzr
|
||||||
|
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
spring:
|
||||||
|
|
Loading…
Reference in New Issue