perf: 数据集调用鉴权接口

This commit is contained in:
fit2cloud-chenyw 2023-11-01 14:24:56 +08:00
parent 429c185b12
commit a9234ab77e
4 changed files with 57 additions and 67 deletions

View File

@ -9,8 +9,6 @@ import io.dataease.api.dataset.union.DatasetGroupInfoDTO;
import io.dataease.api.dataset.union.UnionDTO; import io.dataease.api.dataset.union.UnionDTO;
import io.dataease.api.dataset.vo.DataSetBarVO; import io.dataease.api.dataset.vo.DataSetBarVO;
import io.dataease.api.ds.vo.DatasourceDTO; import io.dataease.api.ds.vo.DatasourceDTO;
import io.dataease.api.permissions.user.api.UserApi;
import io.dataease.api.permissions.user.vo.UserFormVO;
import io.dataease.commons.constants.OptConstants; import io.dataease.commons.constants.OptConstants;
import io.dataease.dataset.dao.auto.entity.CoreDatasetGroup; import io.dataease.dataset.dao.auto.entity.CoreDatasetGroup;
import io.dataease.dataset.dao.auto.entity.CoreDatasetTable; import io.dataease.dataset.dao.auto.entity.CoreDatasetTable;
@ -36,7 +34,6 @@ import io.dataease.utils.*;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -69,8 +66,7 @@ public class DatasetGroupManage {
private CoreDatasetTableMapper coreDatasetTableMapper; private CoreDatasetTableMapper coreDatasetTableMapper;
@Resource @Resource
private CoreDatasourceMapper coreDatasourceMapper; private CoreDatasourceMapper coreDatasourceMapper;
@Autowired(required = false)
private UserApi userApi;
@Resource @Resource
private CoreUserManage coreUserManage; private CoreUserManage coreUserManage;
@ -92,13 +88,9 @@ public class DatasetGroupManage {
CoreDatasetGroup coreDatasetGroup = coreDatasetGroupMapper.selectById(datasetGroupInfoDTO.getId()); CoreDatasetGroup coreDatasetGroup = coreDatasetGroupMapper.selectById(datasetGroupInfoDTO.getId());
datasetGroupInfoDTO.setPid(coreDatasetGroup.getPid()); datasetGroupInfoDTO.setPid(coreDatasetGroup.getPid());
} }
if (userApi == null) { checkName(datasetGroupInfoDTO);
checkName(datasetGroupInfoDTO); datasetGroupInfoDTO.setUpdateBy(AuthUtils.getUser().getUserId() + "");
} datasetGroupInfoDTO.setLastUpdateTime(System.currentTimeMillis());
if (userApi != null) {
datasetGroupInfoDTO.setUpdateBy(userApi.info().getId() + "");
datasetGroupInfoDTO.setLastUpdateTime(System.currentTimeMillis());
}
if (StringUtils.equalsIgnoreCase(datasetGroupInfoDTO.getNodeType(), leafType)) { if (StringUtils.equalsIgnoreCase(datasetGroupInfoDTO.getNodeType(), leafType)) {
if (!rename && ObjectUtils.isEmpty(datasetGroupInfoDTO.getAllFields())) { if (!rename && ObjectUtils.isEmpty(datasetGroupInfoDTO.getAllFields())) {
DEException.throwException(Translator.get("i18n_no_fields")); DEException.throwException(Translator.get("i18n_no_fields"));
@ -116,10 +108,8 @@ public class DatasetGroupManage {
if (ObjectUtils.isEmpty(datasetGroupInfoDTO.getId())) { if (ObjectUtils.isEmpty(datasetGroupInfoDTO.getId())) {
isCreate = true; isCreate = true;
datasetGroupInfoDTO.setId(IDUtils.snowID()); datasetGroupInfoDTO.setId(IDUtils.snowID());
if (userApi != null) { datasetGroupInfoDTO.setCreateBy(AuthUtils.getUser().getUserId() + "");
datasetGroupInfoDTO.setCreateBy(userApi.info().getId() + ""); datasetGroupInfoDTO.setUpdateBy(AuthUtils.getUser().getUserId() + "");
datasetGroupInfoDTO.setUpdateBy(userApi.info().getId() + "");
}
datasetGroupInfoDTO.setCreateTime(time); datasetGroupInfoDTO.setCreateTime(time);
datasetGroupInfoDTO.setLastUpdateTime(time); datasetGroupInfoDTO.setLastUpdateTime(time);
datasetGroupInfoDTO.setPid(datasetGroupInfoDTO.getPid() == null ? 0L : datasetGroupInfoDTO.getPid()); datasetGroupInfoDTO.setPid(datasetGroupInfoDTO.getPid() == null ? 0L : datasetGroupInfoDTO.getPid());
@ -156,21 +146,19 @@ public class DatasetGroupManage {
CoreDatasetGroup coreDatasetGroup = BeanUtils.copyBean(new CoreDatasetGroup(), datasetGroupInfoDTO); CoreDatasetGroup coreDatasetGroup = BeanUtils.copyBean(new CoreDatasetGroup(), datasetGroupInfoDTO);
coreDatasetGroup.setLastUpdateTime(System.currentTimeMillis()); coreDatasetGroup.setLastUpdateTime(System.currentTimeMillis());
coreDatasetGroupMapper.updateById(coreDatasetGroup); coreDatasetGroupMapper.updateById(coreDatasetGroup);
coreOptRecentManage.saveOpt(datasetGroupInfoDTO.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASET,OptConstants.OPT_TYPE.UPDATE); coreOptRecentManage.saveOpt(datasetGroupInfoDTO.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASET, OptConstants.OPT_TYPE.UPDATE);
} }
@XpackInteract(value = "authResourceTree", before = false) @XpackInteract(value = "authResourceTree", before = false)
public void innerSave(DatasetGroupInfoDTO datasetGroupInfoDTO) { public void innerSave(DatasetGroupInfoDTO datasetGroupInfoDTO) {
CoreDatasetGroup coreDatasetGroup = BeanUtils.copyBean(new CoreDatasetGroup(), datasetGroupInfoDTO); CoreDatasetGroup coreDatasetGroup = BeanUtils.copyBean(new CoreDatasetGroup(), datasetGroupInfoDTO);
coreDatasetGroupMapper.insert(coreDatasetGroup); coreDatasetGroupMapper.insert(coreDatasetGroup);
coreOptRecentManage.saveOpt(coreDatasetGroup.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASET,OptConstants.OPT_TYPE.NEW); coreOptRecentManage.saveOpt(coreDatasetGroup.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASET, OptConstants.OPT_TYPE.NEW);
} }
@XpackInteract(value = "authResourceTree", before = false) @XpackInteract(value = "authResourceTree", before = false)
public DatasetGroupInfoDTO move(DatasetGroupInfoDTO datasetGroupInfoDTO) { public DatasetGroupInfoDTO move(DatasetGroupInfoDTO datasetGroupInfoDTO) {
if (userApi == null) { checkName(datasetGroupInfoDTO);
checkName(datasetGroupInfoDTO);
}
if (datasetGroupInfoDTO.getPid() != 0) { if (datasetGroupInfoDTO.getPid() != 0) {
checkMove(datasetGroupInfoDTO); checkMove(datasetGroupInfoDTO);
} }
@ -178,12 +166,10 @@ public class DatasetGroupManage {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
CoreDatasetGroup coreDatasetGroup = new CoreDatasetGroup(); CoreDatasetGroup coreDatasetGroup = new CoreDatasetGroup();
BeanUtils.copyBean(coreDatasetGroup, datasetGroupInfoDTO); BeanUtils.copyBean(coreDatasetGroup, datasetGroupInfoDTO);
if (userApi != null) { datasetGroupInfoDTO.setUpdateBy(AuthUtils.getUser().getUserId() + "");
datasetGroupInfoDTO.setUpdateBy(userApi.info().getId() + "");
}
coreDatasetGroup.setLastUpdateTime(time); coreDatasetGroup.setLastUpdateTime(time);
coreDatasetGroupMapper.updateById(coreDatasetGroup); coreDatasetGroupMapper.updateById(coreDatasetGroup);
coreOptRecentManage.saveOpt(coreDatasetGroup.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASET,OptConstants.OPT_TYPE.UPDATE); coreOptRecentManage.saveOpt(coreDatasetGroup.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASET, OptConstants.OPT_TYPE.UPDATE);
return datasetGroupInfoDTO; return datasetGroupInfoDTO;
} }
@ -194,7 +180,7 @@ public class DatasetGroupManage {
DEException.throwException("resource not exist"); DEException.throwException("resource not exist");
} }
Objects.requireNonNull(CommonBeanFactory.getBean(this.getClass())).recursionDel(id); Objects.requireNonNull(CommonBeanFactory.getBean(this.getClass())).recursionDel(id);
coreOptRecentManage.saveOpt(coreDatasetGroup.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASET,OptConstants.OPT_TYPE.DELETE); coreOptRecentManage.saveOpt(coreDatasetGroup.getId(), OptConstants.OPT_RESOURCE_TYPE.DATASET, OptConstants.OPT_TYPE.DELETE);
} }
public void recursionDel(Long id) { public void recursionDel(Long id) {
@ -235,15 +221,13 @@ public class DatasetGroupManage {
public DataSetBarVO queryBarInfo(Long id) { public DataSetBarVO queryBarInfo(Long id) {
DataSetBarVO dataSetBarVO = coreDataSetExtMapper.queryBarInfo(id); DataSetBarVO dataSetBarVO = coreDataSetExtMapper.queryBarInfo(id);
// get creator // get creator
if (userApi != null) { String userName = coreUserManage.getUserName(Long.valueOf(dataSetBarVO.getCreateBy()));
String userName = coreUserManage.getUserName(Long.valueOf(dataSetBarVO.getCreateBy())); if (StringUtils.isNotBlank(userName)) {
if (StringUtils.isNotBlank(userName)) { dataSetBarVO.setCreator(userName);
dataSetBarVO.setCreator(userName); }
} String updateUserName = coreUserManage.getUserName(Long.valueOf(dataSetBarVO.getUpdateBy()));
String updateUserName = coreUserManage.getUserName(Long.valueOf(dataSetBarVO.getUpdateBy())); if (StringUtils.isNotBlank(updateUserName)) {
if (StringUtils.isNotBlank(updateUserName)) { dataSetBarVO.setUpdater(updateUserName);
dataSetBarVO.setUpdater(updateUserName);
}
} }
dataSetBarVO.setDatasourceDTOList(getDatasource(id)); dataSetBarVO.setDatasourceDTOList(getDatasource(id));
return dataSetBarVO; return dataSetBarVO;
@ -258,13 +242,13 @@ public class DatasetGroupManage {
QueryWrapper<CoreDatasource> datasourceQueryWrapper = new QueryWrapper<>(); QueryWrapper<CoreDatasource> datasourceQueryWrapper = new QueryWrapper<>();
datasourceQueryWrapper.in("id", ids); datasourceQueryWrapper.in("id", ids);
List<DatasourceDTO> datasourceDTOList = coreDatasourceMapper.selectList(datasourceQueryWrapper).stream().map(ele -> { List<DatasourceDTO> datasourceDTOList = coreDatasourceMapper.selectList(datasourceQueryWrapper).stream().map(ele -> {
DatasourceDTO dto = new DatasourceDTO(); DatasourceDTO dto = new DatasourceDTO();
BeanUtils.copyBean(dto, ele); BeanUtils.copyBean(dto, ele);
dto.setConfiguration(null); dto.setConfiguration(null);
return dto; return dto;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
if(ids.size() != datasourceDTOList.size()){ if (ids.size() != datasourceDTOList.size()) {
DEException.throwException("由于数据集所用的数据源已被删除,无法显示数据集"); DEException.throwException("由于数据集所用的数据源已被删除,无法显示数据集");
} }
return datasourceDTOList; return datasourceDTOList;
@ -370,15 +354,13 @@ public class DatasetGroupManage {
DatasetGroupInfoDTO dto = new DatasetGroupInfoDTO(); DatasetGroupInfoDTO dto = new DatasetGroupInfoDTO();
BeanUtils.copyBean(dto, coreDatasetGroup); BeanUtils.copyBean(dto, coreDatasetGroup);
// get creator // get creator
if (userApi != null) { String userName = coreUserManage.getUserName(Long.valueOf(dto.getCreateBy()));
UserFormVO userFormVO = userApi.queryById(Long.valueOf(dto.getCreateBy())); if (StringUtils.isNotBlank(userName)) {
if (userFormVO != null) { dto.setCreator(userName);
dto.setCreator(userFormVO.getName()); }
} String updateUserName = coreUserManage.getUserName(Long.valueOf(dto.getUpdateBy()));
UserFormVO userFormVOUpdateBy = userApi.queryById(Long.valueOf(dto.getUpdateBy())); if (StringUtils.isNotBlank(updateUserName)) {
if (userFormVOUpdateBy != null) { dto.setUpdater(updateUserName);
dto.setUpdater(userFormVOUpdateBy.getName());
}
} }
dto.setUnionSql(null); dto.setUnionSql(null);
if (StringUtils.equalsIgnoreCase(dto.getNodeType(), "dataset")) { if (StringUtils.equalsIgnoreCase(dto.getNodeType(), "dataset")) {
@ -444,8 +426,8 @@ public class DatasetGroupManage {
for (CoreDatasetTable datasetTable : datasetTables) { for (CoreDatasetTable datasetTable : datasetTables) {
if (StringUtils.isNotEmpty(datasetTable.getSqlVariableDetails())) { if (StringUtils.isNotEmpty(datasetTable.getSqlVariableDetails())) {
List<SqlVariableDetails> defaultsSqlVariableDetails = JsonUtil.parseList(datasetTable.getSqlVariableDetails(), listTypeReference); List<SqlVariableDetails> defaultsSqlVariableDetails = JsonUtil.parseList(datasetTable.getSqlVariableDetails(), listTypeReference);
if(CollectionUtil.isNotEmpty(defaultsSqlVariableDetails)){ if (CollectionUtil.isNotEmpty(defaultsSqlVariableDetails)) {
List<String> fullName = new ArrayList<>(); List<String> fullName = new ArrayList<>();
geFullName(id, fullName); geFullName(id, fullName);
List<String> finalFullName = CollectionUtil.reverse(fullName); List<String> finalFullName = CollectionUtil.reverse(fullName);
defaultsSqlVariableDetails.forEach(sqlVariableDetails -> { defaultsSqlVariableDetails.forEach(sqlVariableDetails -> {

View File

@ -6,12 +6,10 @@ import io.dataease.api.dataset.dto.DatasetTableDTO;
import io.dataease.api.dataset.dto.SqlVariableDetails; import io.dataease.api.dataset.dto.SqlVariableDetails;
import io.dataease.api.dataset.union.*; import io.dataease.api.dataset.union.*;
import io.dataease.api.dataset.union.model.SQLObj; import io.dataease.api.dataset.union.model.SQLObj;
import io.dataease.api.permissions.auth.api.InteractiveAuthApi;
import io.dataease.api.permissions.auth.dto.BusiPerCheckDTO; import io.dataease.api.permissions.auth.dto.BusiPerCheckDTO;
import io.dataease.commons.utils.SqlparserUtils; import io.dataease.commons.utils.SqlparserUtils;
import io.dataease.constant.AuthEnum; import io.dataease.constant.AuthEnum;
import io.dataease.dataset.constant.DatasetTableType; import io.dataease.dataset.constant.DatasetTableType;
import io.dataease.dataset.dao.auto.mapper.CoreDatasetTableMapper;
import io.dataease.dataset.dto.DatasourceSchemaDTO; import io.dataease.dataset.dto.DatasourceSchemaDTO;
import io.dataease.dataset.utils.DatasetTableTypeConstants; import io.dataease.dataset.utils.DatasetTableTypeConstants;
import io.dataease.dataset.utils.SqlUtils; import io.dataease.dataset.utils.SqlUtils;
@ -24,6 +22,7 @@ import io.dataease.engine.constant.ExtFieldConstant;
import io.dataease.engine.constant.SQLConstants; import io.dataease.engine.constant.SQLConstants;
import io.dataease.exception.DEException; import io.dataease.exception.DEException;
import io.dataease.i18n.Translator; import io.dataease.i18n.Translator;
import io.dataease.system.manage.CorePermissionManage;
import io.dataease.utils.BeanUtils; import io.dataease.utils.BeanUtils;
import io.dataease.utils.JsonUtil; import io.dataease.utils.JsonUtil;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
@ -31,7 +30,6 @@ import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -44,16 +42,14 @@ import java.util.stream.Collectors;
*/ */
@Component @Component
public class DatasetSQLManage { public class DatasetSQLManage {
@Resource
private CoreDatasetTableMapper coreDatasetTableMapper;
@Resource
private DatasetTableFieldManage datasetTableFieldManage;
@Resource @Resource
private CoreDatasourceMapper coreDatasourceMapper; private CoreDatasourceMapper coreDatasourceMapper;
@Resource @Resource
private EngineServer engineServer; private EngineServer engineServer;
@Autowired(required = false)
private InteractiveAuthApi interactiveAuthApi; @Resource
private CorePermissionManage corePermissionManage;
private static Logger logger = LoggerFactory.getLogger(DatasetSQLManage.class); private static Logger logger = LoggerFactory.getLogger(DatasetSQLManage.class);
@ -328,17 +324,15 @@ public class DatasetSQLManage {
private String putObj2Map(Map<Long, DatasourceSchemaDTO> dsMap, DatasetTableDTO ds) throws Exception { private String putObj2Map(Map<Long, DatasourceSchemaDTO> dsMap, DatasetTableDTO ds) throws Exception {
// 通过datasource id校验数据源权限 // 通过datasource id校验数据源权限
if (interactiveAuthApi != null) { BusiPerCheckDTO dto = new BusiPerCheckDTO();
BusiPerCheckDTO dto = new BusiPerCheckDTO(); dto.setId(ds.getDatasourceId());
dto.setId(ds.getDatasourceId()); dto.setAuthEnum(AuthEnum.READ);
dto.setAuthEnum(AuthEnum.READ); boolean checked = corePermissionManage.checkAuth(dto);
try { if (!checked) {
interactiveAuthApi.checkAuth(dto); DEException.throwException(Translator.get("i18n_no_datasource_permission"));
} catch (Exception e) {
DEException.throwException(Translator.get("i18n_no_datasource_permission"));
}
} }
String schemaAlias; String schemaAlias;
if (StringUtils.equalsIgnoreCase(ds.getType(), DatasetTableType.DB) || StringUtils.equalsIgnoreCase(ds.getType(), DatasetTableType.SQL)) { if (StringUtils.equalsIgnoreCase(ds.getType(), DatasetTableType.DB) || StringUtils.equalsIgnoreCase(ds.getType(), DatasetTableType.SQL)) {
CoreDatasource coreDatasource = coreDatasourceMapper.selectById(ds.getDatasourceId()); CoreDatasource coreDatasource = coreDatasourceMapper.selectById(ds.getDatasourceId());

View File

@ -0,0 +1,14 @@
package io.dataease.system.manage;
import io.dataease.api.permissions.auth.dto.BusiPerCheckDTO;
import io.dataease.license.config.XpackInteract;
import org.springframework.stereotype.Component;
@Component
public class CorePermissionManage {
@XpackInteract(value = "corePermissionManage", replace = true)
public boolean checkAuth(BusiPerCheckDTO dto) {
return true;
}
}

@ -1 +1 @@
Subproject commit 7a4f9a2de62a8ff0b544f2660bef3838cc09d6de Subproject commit 91f3ae793906139d6d761704b95c162de7d26a3d