提交 2bfee7de 编写于 作者: M mxd

支持数据源加密存储

上级 f2478911
......@@ -136,6 +136,8 @@ public class MagicAPIAutoConfiguration implements WebMvcConfigurer, WebSocketCon
private final ObjectProvider<MagicNotifyService> magicNotifyServiceProvider;
private final ObjectProvider<DataSourceEncryptProvider> dataSourceEncryptProvider;
private final Environment environment;
private final MagicCorsFilter magicCorsFilter = new MagicCorsFilter();
......@@ -171,6 +173,7 @@ public class MagicAPIAutoConfiguration implements WebMvcConfigurer, WebSocketCon
ObjectProvider<MagicNotifyService> magicNotifyServiceProvider,
ObjectProvider<AuthorizationInterceptor> authorizationInterceptorProvider,
ObjectProvider<List<NamedTableInterceptor>> namedTableInterceptorsProvider,
ObjectProvider<DataSourceEncryptProvider> dataSourceEncryptProvider,
Environment environment,
ApplicationContext applicationContext
) {
......@@ -185,6 +188,7 @@ public class MagicAPIAutoConfiguration implements WebMvcConfigurer, WebSocketCon
this.magicNotifyServiceProvider = magicNotifyServiceProvider;
this.authorizationInterceptorProvider = authorizationInterceptorProvider;
this.namedTableInterceptorsProvider = namedTableInterceptorsProvider;
this.dataSourceEncryptProvider = dataSourceEncryptProvider;
this.environment = environment;
this.applicationContext = applicationContext;
}
......@@ -400,7 +404,7 @@ public class MagicAPIAutoConfiguration implements WebMvcConfigurer, WebSocketCon
MagicFunctionManager magicFunctionManager,
Resource workspace,
MagicBackupService magicBackupService) {
return new DefaultMagicAPIService(mappingHandlerMapping, apiServiceProvider, functionServiceProvider, groupServiceProvider, resultProvider, magicDynamicDataSource, magicFunctionManager, magicNotifyServiceProvider.getObject(), properties.getClusterConfig().getInstanceId(), workspace, magicBackupService, properties.isThrowException());
return new DefaultMagicAPIService(mappingHandlerMapping, apiServiceProvider, functionServiceProvider, groupServiceProvider, resultProvider, magicDynamicDataSource, magicFunctionManager, magicNotifyServiceProvider.getObject(), properties.getClusterConfig().getInstanceId(), workspace, magicBackupService, dataSourceEncryptProvider.getIfAvailable() , properties.isThrowException());
}
/**
......
package org.ssssssss.magicapi.provider;
import org.ssssssss.magicapi.model.DataSourceInfo;
/**
* 数据源加解密
*
* @since 1.7.0
*/
public interface DataSourceEncryptProvider {
/**
* 加密
* @param dataSourceInfo 数据源信息
*/
void encrypt(DataSourceInfo dataSourceInfo);
/**
* 解密
* @param dataSourceInfo 数据源信息
*/
void decrypt(DataSourceInfo dataSourceInfo);
}
......@@ -82,6 +82,7 @@ public class DefaultMagicAPIService implements MagicAPIService, JsonCodeConstant
private final Resource workspace;
private final Resource datasourceResource;
private final MagicBackupService backupService;
private final DataSourceEncryptProvider dataSourceEncryptProvider;
public DefaultMagicAPIService(MappingHandlerMapping mappingHandlerMapping,
ApiServiceProvider apiServiceProvider,
......@@ -94,6 +95,7 @@ public class DefaultMagicAPIService implements MagicAPIService, JsonCodeConstant
String instanceId,
Resource workspace,
MagicBackupService backupService,
DataSourceEncryptProvider dataSourceEncryptProvider,
boolean throwException) {
this.mappingHandlerMapping = mappingHandlerMapping;
this.apiServiceProvider = apiServiceProvider;
......@@ -106,6 +108,7 @@ public class DefaultMagicAPIService implements MagicAPIService, JsonCodeConstant
this.workspace = workspace;
this.throwException = throwException;
this.instanceId = instanceId;
this.dataSourceEncryptProvider = dataSourceEncryptProvider;
this.backupService = backupService;
this.datasourceResource = workspace.getDirectory(PATH_DATASOURCE);
if (!this.datasourceResource.exists()) {
......@@ -462,6 +465,9 @@ public class DefaultMagicAPIService implements MagicAPIService, JsonCodeConstant
private String registerDataSource(DataSourceInfo properties) {
if (properties != null) {
if(dataSourceEncryptProvider != null){
dataSourceEncryptProvider.decrypt(properties);
}
String key = properties.get("key");
String name = properties.getOrDefault("name", key);
String dsId = properties.remove("id");
......@@ -535,6 +541,9 @@ public class DefaultMagicAPIService implements MagicAPIService, JsonCodeConstant
// 注册数据源
magicDynamicDataSource.put(dsId, key, name, createDataSource(properties), maxRows);
properties.put("id", dsId);
if(dataSourceEncryptProvider != null){
dataSourceEncryptProvider.encrypt(properties);
}
datasourceResource.getResource(dsId + ".json").write(JsonUtils.toJsonString(properties));
backupService.backup(properties);
magicNotifyService.sendNotify(new MagicNotify(instanceId, dsId, action, NOTIFY_ACTION_DATASOURCE));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册