From 03219ca88bcfbb3ab6511e1d0879722581f65cff Mon Sep 17 00:00:00 2001 From: wangqi Date: Sat, 13 Jul 2024 21:14:46 +0800 Subject: [PATCH 1/8] feature: update flink-cdc form --- .../ws/WsArtifactFlinkCDCController.java | 5 ++- .../doris/sink/DorisSinkPlugin.java | 45 +++++++++++++------ .../mysql/source/MySQLSourcePlugin.java | 38 +++++++++++++--- .../starrocks/sink/StarRocksSinkPlugin.java | 29 ++++++++++-- .../generator/MybatisPlusGenerator.java | 4 +- .../Steps/Connector/ConnectorForm.tsx | 15 ++++--- .../Connector/Sink/SinkDorisConnector.tsx | 14 +++--- .../Connector/Sink/SinkKafkaConnector.tsx | 21 ++++----- .../Connector/Sink/SinkStarRocksConnector.tsx | 22 ++++----- .../Connector/Source/SourceKafkaConnector.tsx | 42 ----------------- .../Connector/Source/SourceMySQLConnector.tsx | 36 +++++++-------- .../Steps/New/Config/ConfigStepDataSource.tsx | 4 +- .../FlinkCDC/Steps/New/index.tsx | 3 +- .../project/WsArtifactFlinkCDCService.ts | 7 +-- .../service/WsArtifactFlinkCDCService.java | 3 +- .../impl/WsArtifactFlinkCDCServiceImpl.java | 24 ++-------- 16 files changed, 162 insertions(+), 150 deletions(-) delete mode 100644 scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/Source/SourceKafkaConnector.tsx diff --git a/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/ws/WsArtifactFlinkCDCController.java b/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/ws/WsArtifactFlinkCDCController.java index 1b13429e7..4e50d6b14 100644 --- a/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/ws/WsArtifactFlinkCDCController.java +++ b/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/ws/WsArtifactFlinkCDCController.java @@ -25,6 +25,7 @@ import cn.sliew.scaleph.workspace.flink.cdc.service.dto.WsArtifactFlinkCDCDTO; import cn.sliew.scaleph.workspace.flink.cdc.service.param.*; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.fasterxml.jackson.databind.JsonNode; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; @@ -119,8 +120,8 @@ public ResponseEntity deleteArtifact(@PathVariable("artifactId") Lon @Logging @PostMapping("preview") @Operation(summary = "预览 flink cdc 配置", description = "预览 flink cdc 配置") - public ResponseEntity> previewJob(@RequestBody WsArtifactFlinkCDCDTO dto) throws Exception { - String conf = wsArtifactFlinkCDCService.buildConfig(dto); + public ResponseEntity> previewJob(@RequestBody WsArtifactFlinkCDCDTO dto) throws Exception { + JsonNode conf = wsArtifactFlinkCDCService.buildConfig(dto); return new ResponseEntity<>(ResponseVO.success(conf), HttpStatus.OK); } } \ No newline at end of file diff --git a/scaleph-plugins/scaleph-plugin-flinkcdc/src/main/java/cn/sliew/scaleph/plugin/flink/cdc/connectors/doris/sink/DorisSinkPlugin.java b/scaleph-plugins/scaleph-plugin-flinkcdc/src/main/java/cn/sliew/scaleph/plugin/flink/cdc/connectors/doris/sink/DorisSinkPlugin.java index a8fbb805e..763e2e470 100644 --- a/scaleph-plugins/scaleph-plugin-flinkcdc/src/main/java/cn/sliew/scaleph/plugin/flink/cdc/connectors/doris/sink/DorisSinkPlugin.java +++ b/scaleph-plugins/scaleph-plugin-flinkcdc/src/main/java/cn/sliew/scaleph/plugin/flink/cdc/connectors/doris/sink/DorisSinkPlugin.java @@ -19,10 +19,16 @@ package cn.sliew.scaleph.plugin.flink.cdc.connectors.doris.sink; import cn.sliew.scaleph.common.dict.flink.cdc.FlinkCDCPluginMapping; +import cn.sliew.scaleph.ds.modal.AbstractDataSource; +import cn.sliew.scaleph.ds.modal.olap.DorisDataSource; import cn.sliew.scaleph.plugin.flink.cdc.FlinkCDCPipilineConnectorPlugin; import cn.sliew.scaleph.plugin.flink.cdc.connectors.CommonProperties; import cn.sliew.scaleph.plugin.framework.core.PluginInfo; import cn.sliew.scaleph.plugin.framework.property.PropertyDescriptor; +import cn.sliew.scaleph.plugin.framework.resource.ResourceProperties; +import cn.sliew.scaleph.plugin.framework.resource.ResourceProperty; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.auto.service.AutoService; import java.util.ArrayList; @@ -30,6 +36,8 @@ import java.util.List; import static cn.sliew.scaleph.plugin.flink.cdc.connectors.doris.sink.DorisSinkProperties.*; +import static cn.sliew.scaleph.plugin.flink.cdc.connectors.mysql.source.MySQLSourceProperties.PASSWORD; +import static cn.sliew.scaleph.plugin.flink.cdc.connectors.mysql.source.MySQLSourceProperties.USERNAME; @AutoService(FlinkCDCPipilineConnectorPlugin.class) public class DorisSinkPlugin extends FlinkCDCPipilineConnectorPlugin { @@ -41,22 +49,33 @@ public DorisSinkPlugin() { final List props = new ArrayList<>(); props.add(CommonProperties.NAME); props.add(CommonProperties.TYPE); -// props.add(FENODES); -// props.add(BENODES); -// props.add(JDBC_URL); -// props.add(USERNAME); -// props.add(PASSWORD); -// props.add(AUTO_REDIRECT); -// props.add(SINK_ENABLE_BATCH_MODE); -// props.add(SINK_FLUSH_QUEUE_SIZE); -// props.add(SINK_BUFFER_FLUSH_MAX_ROWS); -// props.add(SINK_BUFFER_FLUSH_MAX_BYTES); -// props.add(SINK_BUFFER_FLUSH_INTERVAL); -// props.add(SINK_PROPERTIES); -// props.add(TABLE_CREATE_PROPERTIES); + props.add(AUTO_REDIRECT); + props.add(SINK_ENABLE_BATCH_MODE); + props.add(SINK_FLUSH_QUEUE_SIZE); + props.add(SINK_BUFFER_FLUSH_MAX_ROWS); + props.add(SINK_BUFFER_FLUSH_MAX_BYTES); + props.add(SINK_BUFFER_FLUSH_INTERVAL); + props.add(SINK_PROPERTIES); + props.add(TABLE_CREATE_PROPERTIES); this.supportedProperties = Collections.unmodifiableList(props); } + @Override + public List getRequiredResources() { + return Collections.singletonList(ResourceProperties.DATASOURCE_RESOURCE); + } + + @Override + public ObjectNode createConf() { + ObjectNode conf = super.createConf(); + JsonNode jsonNode = properties.get(ResourceProperties.DATASOURCE); + DorisDataSource dataSource = (DorisDataSource) AbstractDataSource.fromDsInfo((ObjectNode) jsonNode); + conf.putPOJO(FENODES.getName(), dataSource.getNodeUrls()); + conf.putPOJO(USERNAME.getName(), dataSource.getUsername()); + conf.putPOJO(PASSWORD.getName(), dataSource.getPassword()); + return conf; + } + @Override protected FlinkCDCPluginMapping getPluginMapping() { return FlinkCDCPluginMapping.SINK_DORIS; diff --git a/scaleph-plugins/scaleph-plugin-flinkcdc/src/main/java/cn/sliew/scaleph/plugin/flink/cdc/connectors/mysql/source/MySQLSourcePlugin.java b/scaleph-plugins/scaleph-plugin-flinkcdc/src/main/java/cn/sliew/scaleph/plugin/flink/cdc/connectors/mysql/source/MySQLSourcePlugin.java index 6c8857944..6b24cf025 100644 --- a/scaleph-plugins/scaleph-plugin-flinkcdc/src/main/java/cn/sliew/scaleph/plugin/flink/cdc/connectors/mysql/source/MySQLSourcePlugin.java +++ b/scaleph-plugins/scaleph-plugin-flinkcdc/src/main/java/cn/sliew/scaleph/plugin/flink/cdc/connectors/mysql/source/MySQLSourcePlugin.java @@ -18,13 +18,22 @@ package cn.sliew.scaleph.plugin.flink.cdc.connectors.mysql.source; +import cn.sliew.milky.common.exception.Rethrower; import cn.sliew.scaleph.common.dict.flink.cdc.FlinkCDCPluginMapping; +import cn.sliew.scaleph.ds.modal.AbstractDataSource; +import cn.sliew.scaleph.ds.modal.jdbc.MySQLDataSource; import cn.sliew.scaleph.plugin.flink.cdc.FlinkCDCPipilineConnectorPlugin; import cn.sliew.scaleph.plugin.flink.cdc.connectors.CommonProperties; import cn.sliew.scaleph.plugin.framework.core.PluginInfo; import cn.sliew.scaleph.plugin.framework.property.PropertyDescriptor; +import cn.sliew.scaleph.plugin.framework.resource.ResourceProperties; +import cn.sliew.scaleph.plugin.framework.resource.ResourceProperty; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.auto.service.AutoService; +import java.net.URI; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -41,11 +50,7 @@ public MySQLSourcePlugin() { final List props = new ArrayList<>(); props.add(CommonProperties.NAME); props.add(CommonProperties.TYPE); -// props.add(HOSTNAME); -// props.add(PORT); -// props.add(USERNAME); -// props.add(PASSWORD); -// props.add(TABLES); + props.add(TABLES); props.add(SCHEMA_CHANGE_ENABLED); props.add(SERVER_ID); props.add(SCAN_INCREMENTAL_CLOSE_IDLE_READER_ENABLED); @@ -66,6 +71,29 @@ public MySQLSourcePlugin() { this.supportedProperties = Collections.unmodifiableList(props); } + @Override + public List getRequiredResources() { + return Collections.singletonList(ResourceProperties.DATASOURCE_RESOURCE); + } + + @Override + public ObjectNode createConf() { + try { + ObjectNode conf = super.createConf(); + JsonNode jsonNode = properties.get(ResourceProperties.DATASOURCE); + MySQLDataSource dataSource = (MySQLDataSource) AbstractDataSource.fromDsInfo((ObjectNode) jsonNode); + URI url = new URI(dataSource.getUrl().replace("jdbc:", "")); + conf.putPOJO(HOSTNAME.getName(), url.getHost()); + conf.putPOJO(PORT.getName(), url.getPort()); + conf.putPOJO(USERNAME.getName(), dataSource.getUser()); + conf.putPOJO(PASSWORD.getName(), dataSource.getPassword()); + return conf; + } catch (URISyntaxException e) { + Rethrower.throwAs(e); + return null; + } + } + @Override protected FlinkCDCPluginMapping getPluginMapping() { return FlinkCDCPluginMapping.SOURCE_MYSQL; diff --git a/scaleph-plugins/scaleph-plugin-flinkcdc/src/main/java/cn/sliew/scaleph/plugin/flink/cdc/connectors/starrocks/sink/StarRocksSinkPlugin.java b/scaleph-plugins/scaleph-plugin-flinkcdc/src/main/java/cn/sliew/scaleph/plugin/flink/cdc/connectors/starrocks/sink/StarRocksSinkPlugin.java index cd9dcea4a..86a5d7982 100644 --- a/scaleph-plugins/scaleph-plugin-flinkcdc/src/main/java/cn/sliew/scaleph/plugin/flink/cdc/connectors/starrocks/sink/StarRocksSinkPlugin.java +++ b/scaleph-plugins/scaleph-plugin-flinkcdc/src/main/java/cn/sliew/scaleph/plugin/flink/cdc/connectors/starrocks/sink/StarRocksSinkPlugin.java @@ -19,16 +19,24 @@ package cn.sliew.scaleph.plugin.flink.cdc.connectors.starrocks.sink; import cn.sliew.scaleph.common.dict.flink.cdc.FlinkCDCPluginMapping; +import cn.sliew.scaleph.ds.modal.AbstractDataSource; +import cn.sliew.scaleph.ds.modal.olap.StarRocksDataSource; import cn.sliew.scaleph.plugin.flink.cdc.FlinkCDCPipilineConnectorPlugin; import cn.sliew.scaleph.plugin.flink.cdc.connectors.CommonProperties; import cn.sliew.scaleph.plugin.framework.core.PluginInfo; import cn.sliew.scaleph.plugin.framework.property.PropertyDescriptor; +import cn.sliew.scaleph.plugin.framework.resource.ResourceProperties; +import cn.sliew.scaleph.plugin.framework.resource.ResourceProperty; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.auto.service.AutoService; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import static cn.sliew.scaleph.plugin.flink.cdc.connectors.mysql.source.MySQLSourceProperties.PASSWORD; +import static cn.sliew.scaleph.plugin.flink.cdc.connectors.mysql.source.MySQLSourceProperties.USERNAME; import static cn.sliew.scaleph.plugin.flink.cdc.connectors.starrocks.sink.StarRocksSinkProperties.*; @AutoService(FlinkCDCPipilineConnectorPlugin.class) @@ -41,10 +49,6 @@ public StarRocksSinkPlugin() { final List props = new ArrayList<>(); props.add(CommonProperties.NAME); props.add(CommonProperties.TYPE); - props.add(JDBC_URL); - props.add(LOAD_URL); - props.add(USERNAME); - props.add(PASSWORD); props.add(SINK_LABEL_PREFIX); props.add(SINK_CONNECT_TIMEOUT_MS); props.add(SINK_WAIT_FOR_CONTINUE_TIMEOUT_MS); @@ -60,6 +64,23 @@ public StarRocksSinkPlugin() { this.supportedProperties = Collections.unmodifiableList(props); } + @Override + public List getRequiredResources() { + return Collections.singletonList(ResourceProperties.DATASOURCE_RESOURCE); + } + + @Override + public ObjectNode createConf() { + ObjectNode conf = super.createConf(); + JsonNode jsonNode = properties.get(ResourceProperties.DATASOURCE); + StarRocksDataSource dataSource = (StarRocksDataSource) AbstractDataSource.fromDsInfo((ObjectNode) jsonNode); + conf.putPOJO(JDBC_URL.getName(), dataSource.getNodeUrls()); + conf.putPOJO(LOAD_URL.getName(), dataSource.getNodeUrls()); + conf.putPOJO(USERNAME.getName(), dataSource.getUsername()); + conf.putPOJO(PASSWORD.getName(), dataSource.getPassword()); + return conf; + } + @Override protected FlinkCDCPluginMapping getPluginMapping() { return FlinkCDCPluginMapping.SINK_STARROCKS; diff --git a/scaleph-support/scaleph-generator/src/main/java/cn/sliew/scaleph/generator/MybatisPlusGenerator.java b/scaleph-support/scaleph-generator/src/main/java/cn/sliew/scaleph/generator/MybatisPlusGenerator.java index 60ddc017a..8899e9ec0 100644 --- a/scaleph-support/scaleph-generator/src/main/java/cn/sliew/scaleph/generator/MybatisPlusGenerator.java +++ b/scaleph-support/scaleph-generator/src/main/java/cn/sliew/scaleph/generator/MybatisPlusGenerator.java @@ -44,7 +44,7 @@ public class MybatisPlusGenerator { private final static String AUTHOR = "wangqi"; - private final static String URL = "jdbc:mysql://127.0.0.1:3306/scaleph"; + private final static String URL = "jdbc:mysql://127.0.0.1:3306/carp"; private final static String USERNAME = "root"; private final static String PASSWORD = "123456"; //NOSONAR private static final String BASE_PACKAGE = "cn.sliew"; @@ -54,7 +54,7 @@ public class MybatisPlusGenerator { /** * just add table names here and run the {@link #main(String[])} method. */ - private static final String[] TABLES = {"dag_instance", "dag_link", "dag_step"}; + private static final String[] TABLES = {"sec_application"}; public static void main(String[] args) { //自动生成配置 diff --git a/scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/ConnectorForm.tsx b/scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/ConnectorForm.tsx index 124d5b182..7b0540d5a 100644 --- a/scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/ConnectorForm.tsx +++ b/scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/ConnectorForm.tsx @@ -6,15 +6,16 @@ import SinkDorisConnectorForm from "@/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/Sink/SinkDorisConnector"; import SinkStarRocksConnectorForm from "@/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/Sink/SinkStarRocksConnector"; -import SourceKafkaConnectorForm - from "@/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/Source/SourceKafkaConnector"; +import SinkKafkaConnectorForm + from "@/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/Sink/SinkKafkaConnector"; type ConnectorProps = { + prefix: string; type: string; dsId: number; }; -const FlinkCDCConnectorForm: React.FC = ({type, dsId}) => { +const FlinkCDCConnectorForm: React.FC = ({prefix, type, dsId}) => { const [content, setConstent] = useState(<>) @@ -27,13 +28,13 @@ const FlinkCDCConnectorForm: React.FC = ({type, dsId}) => { DsInfoService.selectOne(dsId).then((response) => { if (response.data) { if (type === 'source' && response.data.dsType.type.value == 'MySQL') { - setConstent() + setConstent() } else if (type === 'sink' && response.data.dsType.type.value === 'Doris') { - setConstent() + setConstent() } else if (type === 'sink' && response.data.dsType.type.value === 'StarRocks') { - setConstent() + setConstent() } else if (type === 'sink' && response.data.dsType.type.value === 'Kafka') { - setConstent() + setConstent() } } }) diff --git a/scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/Sink/SinkDorisConnector.tsx b/scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/Sink/SinkDorisConnector.tsx index d538d1442..15e679b00 100644 --- a/scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/Sink/SinkDorisConnector.tsx +++ b/scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/Sink/SinkDorisConnector.tsx @@ -3,17 +3,17 @@ import {useIntl} from "@umijs/max"; import {ProFormDependency, ProFormDigit, ProFormGroup, ProFormSwitch, ProFormText} from "@ant-design/pro-components"; import {DorisParams} from "@/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/constant"; -const SinkDorisConnectorForm: React.FC = () => { +const SinkDorisConnectorForm: React.FC<{prefix: string}> = ({prefix}) => { const intl = useIntl(); return ( @@ -22,7 +22,7 @@ const SinkDorisConnectorForm: React.FC = () => { if (sinkEnableBatchModeParam) { return { }} /> { }} /> { }} /> { +const SinkKafkaConnectorForm: React.FC<{prefix: string}> = ({prefix}) => { const intl = useIntl(); return ( ); }; -export default SourceKafkaConnectorForm; +export default SinkKafkaConnectorForm; diff --git a/scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/Sink/SinkStarRocksConnector.tsx b/scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/Sink/SinkStarRocksConnector.tsx index a787a20ef..9a3cac06b 100644 --- a/scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/Sink/SinkStarRocksConnector.tsx +++ b/scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/Sink/SinkStarRocksConnector.tsx @@ -3,22 +3,22 @@ import {useIntl} from "@umijs/max"; import {ProFormDigit, ProFormGroup, ProFormSwitch, ProFormText} from "@ant-design/pro-components"; import {StarRocksParams} from "@/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/constant"; -const SinkStarRocksConnectorForm: React.FC = () => { +const SinkStarRocksConnectorForm: React.FC<{prefix: string}> = ({prefix}) => { const intl = useIntl(); return ( { }} /> { }} /> { }} /> { }} /> { }} /> { }} /> diff --git a/scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/Source/SourceKafkaConnector.tsx b/scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/Source/SourceKafkaConnector.tsx deleted file mode 100644 index 5e679a848..000000000 --- a/scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/Source/SourceKafkaConnector.tsx +++ /dev/null @@ -1,42 +0,0 @@ -import React from 'react'; -import {useIntl} from "@umijs/max"; -import {ProFormDigit, ProFormGroup, ProFormSelect, ProFormSwitch, ProFormText} from "@ant-design/pro-components"; -import { - KafkaParams, - StarRocksParams -} from "@/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/constant"; - -const SourceKafkaConnectorForm: React.FC = () => { - const intl = useIntl(); - - return ( - - - - - - - - ); -}; - -export default SourceKafkaConnectorForm; diff --git a/scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/Source/SourceMySQLConnector.tsx b/scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/Source/SourceMySQLConnector.tsx index cf62a6027..d0681b418 100644 --- a/scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/Source/SourceMySQLConnector.tsx +++ b/scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/Source/SourceMySQLConnector.tsx @@ -10,26 +10,26 @@ import { } from "@ant-design/pro-components"; import {MySQLParams} from "@/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/Connector/constant"; -const SourceMySQLConnectorForm: React.FC = () => { +const SourceMySQLConnectorForm: React.FC<{ prefix: string }> = ({prefix}) => { const intl = useIntl(); return ( { }} /> { }} /> { if (scanStartupMode == 'specific-offset') { return { }} /> @@ -89,7 +89,7 @@ const SourceMySQLConnectorForm: React.FC = () => { { }} /> { defaultCollapsed={true} > { }} /> { /> diff --git a/scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/New/Config/ConfigStepDataSource.tsx b/scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/New/Config/ConfigStepDataSource.tsx index 6b18c9a85..1e9b62338 100644 --- a/scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/New/Config/ConfigStepDataSource.tsx +++ b/scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/New/Config/ConfigStepDataSource.tsx @@ -74,7 +74,7 @@ const DataIntegrationFlinkCDCStepConfigDataSource: React.FC = () => { return {intl.formatMessage({id: 'pages.project.di.flink-cdc.step.config.dataSource.fromDsConfig'})} - + }} @@ -84,7 +84,7 @@ const DataIntegrationFlinkCDCStepConfigDataSource: React.FC = () => { return {intl.formatMessage({id: 'pages.project.di.flink-cdc.step.config.dataSource.toDsConfig'})} - + }} diff --git a/scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/New/index.tsx b/scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/New/index.tsx index 693ba58f5..01947b5ad 100644 --- a/scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/New/index.tsx +++ b/scaleph-ui-react/src/pages/Project/Workspace/DataIntegration/FlinkCDC/Steps/New/index.tsx @@ -33,6 +33,7 @@ const DataIntegrationFlinkCDCNewSteps: React.FC = (props: any) => { const onConfigStepFinish = (values: Record) => { try { + console.log('onConfigStepFinish', values) const instance: WsArtifactFlinkCDC = WsArtifactFlinkCDCService.formatData(props.flinkCDCSteps.instance, values) editFlinkCDCConfig(instance) } catch (unused) { @@ -68,7 +69,7 @@ const DataIntegrationFlinkCDCNewSteps: React.FC = (props: any) => { transform: values.transform, route: values.route } - return WsArtifactFlinkCDCService.add(param); + return WsArtifactFlinkCDCService.add(param).then(response => response.success); }} > { - return request>(`${WsArtifactFlinkCDCService.url}/preview`, { + return request>(`${WsArtifactFlinkCDCService.url}/preview`, { method: 'POST', data: param }); @@ -99,7 +98,9 @@ export const WsArtifactFlinkCDCService = { formatData: (data: WsArtifactFlinkCDC, value: Record) => { data.fromDsId = value.fromDsId + data.fromDsConfig = value.fromDsConfig data.toDsId = value.toDsId + data.toDsConfig = value.toDsConfig data.transform = value.transform data.route = value.route return data; diff --git a/scaleph-workspace/scaleph-workspace-flink-cdc/src/main/java/cn/sliew/scaleph/workspace/flink/cdc/service/WsArtifactFlinkCDCService.java b/scaleph-workspace/scaleph-workspace-flink-cdc/src/main/java/cn/sliew/scaleph/workspace/flink/cdc/service/WsArtifactFlinkCDCService.java index 068fdae3c..bf939df6e 100644 --- a/scaleph-workspace/scaleph-workspace-flink-cdc/src/main/java/cn/sliew/scaleph/workspace/flink/cdc/service/WsArtifactFlinkCDCService.java +++ b/scaleph-workspace/scaleph-workspace-flink-cdc/src/main/java/cn/sliew/scaleph/workspace/flink/cdc/service/WsArtifactFlinkCDCService.java @@ -22,6 +22,7 @@ import cn.sliew.scaleph.workspace.flink.cdc.service.dto.WsArtifactFlinkCDCDTO; import cn.sliew.scaleph.workspace.flink.cdc.service.param.*; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.fasterxml.jackson.databind.JsonNode; import java.util.List; import java.util.Optional; @@ -40,7 +41,7 @@ public interface WsArtifactFlinkCDCService { WsArtifactFlinkCDCDTO selectCurrent(Long artifactId); - String buildConfig(WsArtifactFlinkCDCDTO dto) throws Exception; + JsonNode buildConfig(WsArtifactFlinkCDCDTO dto) throws Exception; WsArtifactFlinkCDCDTO insert(WsArtifactFlinkCDCAddParam param); diff --git a/scaleph-workspace/scaleph-workspace-flink-cdc/src/main/java/cn/sliew/scaleph/workspace/flink/cdc/service/impl/WsArtifactFlinkCDCServiceImpl.java b/scaleph-workspace/scaleph-workspace-flink-cdc/src/main/java/cn/sliew/scaleph/workspace/flink/cdc/service/impl/WsArtifactFlinkCDCServiceImpl.java index 581da7bb3..1b1ac279e 100644 --- a/scaleph-workspace/scaleph-workspace-flink-cdc/src/main/java/cn/sliew/scaleph/workspace/flink/cdc/service/impl/WsArtifactFlinkCDCServiceImpl.java +++ b/scaleph-workspace/scaleph-workspace-flink-cdc/src/main/java/cn/sliew/scaleph/workspace/flink/cdc/service/impl/WsArtifactFlinkCDCServiceImpl.java @@ -37,8 +37,7 @@ import cn.sliew.scaleph.plugin.flink.cdc.pipeline.PipelineProperties; import cn.sliew.scaleph.plugin.flink.cdc.util.FlinkCDCPluginUtil; import cn.sliew.scaleph.plugin.framework.exception.PluginException; -import cn.sliew.scaleph.plugin.framework.resource.ResourceProperty; -import cn.sliew.scaleph.resource.service.ResourceService; +import cn.sliew.scaleph.plugin.framework.resource.ResourceProperties; import cn.sliew.scaleph.workspace.flink.cdc.service.FlinkCDCConnectorService; import cn.sliew.scaleph.workspace.flink.cdc.service.WsArtifactFlinkCDCService; import cn.sliew.scaleph.workspace.flink.cdc.service.convert.WsArtifactFlinkCDCConvert; @@ -52,7 +51,6 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ObjectNode; -import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; import org.apache.commons.lang3.EnumUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -67,9 +65,6 @@ @Service public class WsArtifactFlinkCDCServiceImpl implements WsArtifactFlinkCDCService { - // todo 迁移到 JacksonUtil - private YAMLMapper yamlMapper = new YAMLMapper(); - @Autowired private WsArtifactFlinkCDCMapper wsArtifactFlinkCDCMapper; @Autowired @@ -77,8 +72,6 @@ public class WsArtifactFlinkCDCServiceImpl implements WsArtifactFlinkCDCService @Autowired private FlinkCDCConnectorService flinkCDCConnectorService; @Autowired - private ResourceService resourceService; - @Autowired private DsInfoService dsInfoService; @Override @@ -134,7 +127,7 @@ public WsArtifactFlinkCDCDTO selectCurrent(Long artifactId) { } @Override - public String buildConfig(WsArtifactFlinkCDCDTO dto) throws Exception { + public JsonNode buildConfig(WsArtifactFlinkCDCDTO dto) throws Exception { ObjectNode conf = JacksonUtil.createObjectNode(); conf.set("pipeline", buildPipeline(dto)); if (dto.getFromDsId() != null) { @@ -145,7 +138,7 @@ public String buildConfig(WsArtifactFlinkCDCDTO dto) throws Exception { } conf.set("transform", dto.getTransform()); conf.set("route", dto.getRoute()); - return yamlMapper.writeValueAsString(conf); + return conf; } private ObjectNode buildPipeline(WsArtifactFlinkCDCDTO dto) { @@ -187,16 +180,7 @@ private Properties mergeJobAttrs(FlinkCDCPluginType pluginType, FlinkCDCPluginNa })); properties.put(CommonProperties.TYPE.getName(), pluginName.getValue()); properties.put(CommonProperties.NAME.getName(), dsInfoDTO.getName()); - FlinkCDCPipilineConnectorPlugin connector = flinkCDCConnectorService.getConnector(pluginType, pluginName); - for (ResourceProperty resource : connector.getRequiredResources()) { - String name = resource.getProperty().getName(); - if (properties.containsKey(name)) { - Object property = properties.get(name); - // fixme force conform property to resource id - Object value = resourceService.getRaw(resource.getType(), Long.valueOf(property.toString())); - properties.put(name, JacksonUtil.toJsonString(value)); - } - } + properties.put(ResourceProperties.DATASOURCE.getName(), JacksonUtil.toJsonString(dsInfoDTO)); return properties; } From 5f0bf414ce9437c231ab5a0c04b82f4763c493af Mon Sep 17 00:00:00 2001 From: wangqi <1942460489@qq.com> Date: Tue, 16 Jul 2024 22:39:39 +0800 Subject: [PATCH 2/8] feature: update flink cdc steps --- .../release-manual-docker-flink-cdc.yml | 4 +- tools/docker/build/flink-cdc/Dockerfile | 23 +++++++-- .../build/flink-cdc/mysql-to-kafka.yaml | 34 +++++++++++++ .../values-prometheus-operator.yaml | 50 +++++++++++++++++++ 4 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 tools/docker/build/flink-cdc/mysql-to-kafka.yaml diff --git a/.github/workflows/release-manual-docker-flink-cdc.yml b/.github/workflows/release-manual-docker-flink-cdc.yml index cfc6ea146..40bfd645f 100644 --- a/.github/workflows/release-manual-docker-flink-cdc.yml +++ b/.github/workflows/release-manual-docker-flink-cdc.yml @@ -22,10 +22,10 @@ on: flinkCDCVersion: description: 'flink-cdc version' required: true - default: '3.0.0' + default: '3.1.1' type: choice options: - - 3.0.0 + - 3.1.1 flinkVersion: description: 'flink version' required: true diff --git a/tools/docker/build/flink-cdc/Dockerfile b/tools/docker/build/flink-cdc/Dockerfile index d312336e1..21563c3d8 100644 --- a/tools/docker/build/flink-cdc/Dockerfile +++ b/tools/docker/build/flink-cdc/Dockerfile @@ -18,13 +18,30 @@ ARG FLINK_VERSION=1.18 FROM flink:${FLINK_VERSION} -ARG FLINK_CDC_VERSION=3.1.0 +ARG FLINK_CDC_VERSION=3.1.1 ARG TAR_FILE=flink-cdc-${FLINK_CDC_VERSION}-bin.tar.gz ENV FLINK_CDC_HOME=/opt/flink-cdc +ENV FLINK_CDC_CONF=$FLINK_CDC_HOME/conf +ENV FLINK_CDC_LIB=$FLINK_CDC_HOME/lib +ENV FLINK_CDC_LOG=$FLINK_CDC_HOME/log RUN mkdir -p $FLINK_CDC_HOME +RUN mkdir -p $FLINK_CDC_HOME/yaml +COPY tools/docker/build/flink-cdc/mysql-to-kafka.yaml $FLINK_CDC_HOME/yaml/mysql-to-kafka.yaml + # 本地构建时,可以切换成国内镜像:https://mirrors.cloud.tencent.com/apache/flink/flink-cdc-${FLINK_CDC_VERSION}/$TAR_FILE -RUN wget https://archive.apache.org/dist/flink/flink-cdc-${FLINK_CDC_VERSION}/$TAR_FILE ; \ +# RUN wget https://archive.apache.org/dist/flink/flink-cdc-${FLINK_CDC_VERSION}/$TAR_FILE ; \ +RUN wget https://mirrors.cloud.tencent.com/apache/flink/flink-cdc-${FLINK_CDC_VERSION}/$TAR_FILE ; \ tar -zxf $TAR_FILE --strip 1 -C $FLINK_CDC_HOME ; \ - rm $TAR_FILE \ No newline at end of file + rm $TAR_FILE + +RUN wget https://repo.maven.apache.org/maven2/org/apache/flink/flink-cdc-pipeline-connector-mysql/${FLINK_CDC_VERSION}/flink-cdc-pipeline-connector-mysql-${FLINK_CDC_VERSION}.jar -O $FLINK_CDC_HOME/lib/flink-cdc-pipeline-connector-mysql.jar +RUN wget https://repo.maven.apache.org/maven2/org/apache/flink/flink-cdc-pipeline-connector-doris/${FLINK_CDC_VERSION}/flink-cdc-pipeline-connector-doris-${FLINK_CDC_VERSION}.jar -O $FLINK_CDC_HOME/lib/flink-cdc-pipeline-connector-doris.jar +RUN wget https://repo.maven.apache.org/maven2/org/apache/flink/flink-cdc-pipeline-connector-starrocks/${FLINK_CDC_VERSION}/flink-cdc-pipeline-connector-starrocks-${FLINK_CDC_VERSION}.jar -O $FLINK_CDC_HOME/lib/flink-cdc-pipeline-connector-starrocks.jar +RUN wget https://repo.maven.apache.org/maven2/org/apache/flink/flink-cdc-pipeline-connector-kafka/${FLINK_CDC_VERSION}/flink-cdc-pipeline-connector-kafka-${FLINK_CDC_VERSION}.jar -O $FLINK_CDC_HOME/lib/flink-cdc-pipeline-connector-kafka.jar +RUN wget https://repo.maven.apache.org/maven2/org/apache/flink/flink-cdc-pipeline-connector-paimon/${FLINK_CDC_VERSION}/flink-cdc-pipeline-connector-paimon-${FLINK_CDC_VERSION}.jar -O $FLINK_CDC_HOME/lib/flink-cdc-pipeline-connector-paimon.jar + +RUN wget https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.27/mysql-connector-java-8.0.27.jar -O $FLINK_CDC_HOME/lib/mysql-connector-java-8.0.27.jar + +ENV CLASSPATH=$FLINK_HOME/lib/:$FLINK_CDC_LIB/* \ No newline at end of file diff --git a/tools/docker/build/flink-cdc/mysql-to-kafka.yaml b/tools/docker/build/flink-cdc/mysql-to-kafka.yaml new file mode 100644 index 000000000..0a87d80e4 --- /dev/null +++ b/tools/docker/build/flink-cdc/mysql-to-kafka.yaml @@ -0,0 +1,34 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +source: + type: mysql + name: MySQL Source + hostname: 127.0.0.1 + port: 3306 + username: root + password: 123456 + tables: scaleph.log_action + server-id: 5401-5404 + +sink: + type: kafka + name: Kafka Sink + properties.bootstrap.servers: PLAINTEXT://localhost:62510 + +pipeline: + name: MySQL to Kafka Pipeline + parallelism: 2 \ No newline at end of file diff --git a/tools/kubernetes/prometheus/values-prometheus-operator.yaml b/tools/kubernetes/prometheus/values-prometheus-operator.yaml index 6d61b91df..2a5922962 100644 --- a/tools/kubernetes/prometheus/values-prometheus-operator.yaml +++ b/tools/kubernetes/prometheus/values-prometheus-operator.yaml @@ -35,6 +35,56 @@ alertmanager: nodePort: 30903 ## Service type type: NodePort + ## Configuration for creating a ServiceMonitor for AlertManager + serviceMonitor: + ## If true, a ServiceMonitor will be created for the AlertManager service. + selfMonitor: false + ## Alertmanager configuration directives + ## ref: https://prometheus.io/docs/alerting/configuration/#configuration-file + ## https://prometheus.io/webtools/alerting/routing-tree-editor/ + config: + inhibit_rules: + - source_matchers: + - 'severity = critical' + target_matchers: + - 'severity =~ warning|info' + equal: + - 'namespace' + - 'alertname' + - source_matchers: + - 'severity = warning' + target_matchers: + - 'severity = info' + equal: + - 'namespace' + - 'alertname' + - source_matchers: + - 'alertname = InfoInhibitor' + target_matchers: + - 'severity = info' + equal: + - 'namespace' + - target_matchers: + - 'alertname = InfoInhibitor' + route: + group_by: ['namespace'] + group_wait: 30s + group_interval: 5m + repeat_interval: 12h + receiver: 'wechat' + routes: + - receiver: 'wechat' + matchers: + - alertname = "Watchdog" + receivers: + - name: 'wechat' + webhook-configs: + send-resolved: true + # 替换企微机器人的真正key +# url: https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key= + + templates: + - '/etc/alertmanager/config/*.tmpl' ## Using default values from https://github.com/grafana/helm-charts/blob/main/charts/grafana/values.yaml ## Grafana isn't managed by prometheus From 75163c8fe6884c2d0bc4ac5432365ca08cccec16 Mon Sep 17 00:00:00 2001 From: wangqi Date: Thu, 18 Jul 2024 21:15:02 +0800 Subject: [PATCH 3/8] feature: replace basic modules and components --- .../src/main/java/cn/sliew/scaleph/Application.java | 2 +- .../main/java/cn/sliew/scaleph/api/config/I18nConfig.java | 4 ++-- .../java/cn/sliew/scaleph/api/config/RedissionConfig.java | 4 ++-- .../java/cn/sliew/scaleph/api/config/SwaggerConfig.java | 3 ++- .../java/cn/sliew/scaleph/api/config/WebMvcConfig.java | 6 ++++-- .../cn/sliew/scaleph/api/config/WebSecurityConfig.java | 8 ++++---- .../api/controller/admin/SecResourceWebController.java | 2 +- .../scaleph/api/controller/admin/SecRoleController.java | 2 +- .../scaleph/api/controller/admin/SecUserController.java | 2 +- .../scaleph/api/exception/GlobalExceptionHandler.java | 2 +- .../main/java/cn/sliew/scaleph/common/util/I18nUtil.java | 2 +- .../dao/mapper/master/security/SecResourceWebMapper.java | 2 +- .../mapper/master/security/SecResourceWebRoleMapper.java | 2 +- .../scaleph/dao/mapper/master/security/SecRoleMapper.java | 2 +- .../scaleph/dao/mapper/master/security/SecUserMapper.java | 2 +- .../dao/mapper/master/security/SecUserRoleMapper.java | 2 +- scaleph-security/pom.xml | 6 ++++++ .../security/service/impl/SecResourceWebServiceImpl.java | 2 +- .../scaleph/security/service/impl/SecRoleServiceImpl.java | 2 +- .../security/service/impl/SecUserRoleServiceImpl.java | 2 +- .../scaleph/security/service/impl/SecUserServiceImpl.java | 2 +- 21 files changed, 35 insertions(+), 26 deletions(-) diff --git a/scaleph-api/src/main/java/cn/sliew/scaleph/Application.java b/scaleph-api/src/main/java/cn/sliew/scaleph/Application.java index ce7bd0675..ba1b87b20 100644 --- a/scaleph-api/src/main/java/cn/sliew/scaleph/Application.java +++ b/scaleph-api/src/main/java/cn/sliew/scaleph/Application.java @@ -21,7 +21,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -@SpringBootApplication +@SpringBootApplication(scanBasePackages = "cn.sliew") public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); diff --git a/scaleph-api/src/main/java/cn/sliew/scaleph/api/config/I18nConfig.java b/scaleph-api/src/main/java/cn/sliew/scaleph/api/config/I18nConfig.java index 95e82db2b..bd5b2af87 100644 --- a/scaleph-api/src/main/java/cn/sliew/scaleph/api/config/I18nConfig.java +++ b/scaleph-api/src/main/java/cn/sliew/scaleph/api/config/I18nConfig.java @@ -31,7 +31,7 @@ /** * @author gleiyu */ -@Configuration +//@Configuration public class I18nConfig { /** * 配置默认解析器 @@ -51,7 +51,7 @@ public LocaleResolver localeResolver() { * * @return WebMvcConfigurer */ - @Bean +// @Bean public WebMvcConfigurer localeInterceptor() { return new WebMvcConfigurer() { @Override diff --git a/scaleph-api/src/main/java/cn/sliew/scaleph/api/config/RedissionConfig.java b/scaleph-api/src/main/java/cn/sliew/scaleph/api/config/RedissionConfig.java index b9c61e2b2..9b27fc338 100644 --- a/scaleph-api/src/main/java/cn/sliew/scaleph/api/config/RedissionConfig.java +++ b/scaleph-api/src/main/java/cn/sliew/scaleph/api/config/RedissionConfig.java @@ -26,8 +26,8 @@ import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.context.annotation.Configuration; -@Configuration -@AutoConfigureBefore(RedissonAutoConfiguration.class) +//@Configuration +//@AutoConfigureBefore(RedissonAutoConfiguration.class) public class RedissionConfig implements RedissonAutoConfigurationCustomizer { @Override diff --git a/scaleph-api/src/main/java/cn/sliew/scaleph/api/config/SwaggerConfig.java b/scaleph-api/src/main/java/cn/sliew/scaleph/api/config/SwaggerConfig.java index aa114bcca..a9df2053b 100644 --- a/scaleph-api/src/main/java/cn/sliew/scaleph/api/config/SwaggerConfig.java +++ b/scaleph-api/src/main/java/cn/sliew/scaleph/api/config/SwaggerConfig.java @@ -29,7 +29,8 @@ import java.util.Map; -@Configuration +// fixme 这里要用 scaleph 自己的,不能用 carp 的 +//@Configuration public class SwaggerConfig { /** diff --git a/scaleph-api/src/main/java/cn/sliew/scaleph/api/config/WebMvcConfig.java b/scaleph-api/src/main/java/cn/sliew/scaleph/api/config/WebMvcConfig.java index 9af6a8dff..53f63dc6a 100644 --- a/scaleph-api/src/main/java/cn/sliew/scaleph/api/config/WebMvcConfig.java +++ b/scaleph-api/src/main/java/cn/sliew/scaleph/api/config/WebMvcConfig.java @@ -50,7 +50,9 @@ import java.util.Set; @Slf4j -@Configuration + + +//@Configuration public class WebMvcConfig implements WebMvcConfigurer { @Autowired @@ -90,7 +92,7 @@ public void addInterceptors(InterceptorRegistry registry) { * 这玩意会造成异步请求结果无法响应,换成{@code AsyncHandlerInterceptor}就一切正常了 */ @Slf4j - @Component +// @Component public static class RequestResponseCacheFilter extends OncePerRequestFilter implements Ordered { @Override diff --git a/scaleph-api/src/main/java/cn/sliew/scaleph/api/config/WebSecurityConfig.java b/scaleph-api/src/main/java/cn/sliew/scaleph/api/config/WebSecurityConfig.java index f1ae3c354..575144fc0 100644 --- a/scaleph-api/src/main/java/cn/sliew/scaleph/api/config/WebSecurityConfig.java +++ b/scaleph-api/src/main/java/cn/sliew/scaleph/api/config/WebSecurityConfig.java @@ -57,10 +57,10 @@ /** * https://spring.io/blog/2022/02/21/spring-security-without-the-websecurityconfigureradapter */ -@Configuration -@EnableWebSecurity -@EnableRedisHttpSession(redisNamespace = "${spring.application.name}") -@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true) +//@Configuration +//@EnableWebSecurity +//@EnableRedisHttpSession(redisNamespace = "${spring.application.name}") +//@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true) public class WebSecurityConfig { @Autowired diff --git a/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/admin/SecResourceWebController.java b/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/admin/SecResourceWebController.java index ad670fa70..4423b648c 100644 --- a/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/admin/SecResourceWebController.java +++ b/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/admin/SecResourceWebController.java @@ -42,7 +42,7 @@ import java.util.List; -@RestController +//@RestController @RequestMapping("/api/admin/resource/web") @Tag(name = "系统管理-资源管理-Web") public class SecResourceWebController { diff --git a/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/admin/SecRoleController.java b/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/admin/SecRoleController.java index aa1e38912..4f935e3c7 100644 --- a/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/admin/SecRoleController.java +++ b/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/admin/SecRoleController.java @@ -56,7 +56,7 @@ * * @author liyu */ -@RestController +//@RestController @RequestMapping("/api/admin/role") @Tag(name = "系统管理-角色管理") public class SecRoleController { diff --git a/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/admin/SecUserController.java b/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/admin/SecUserController.java index 7a981cecf..ff7a602ec 100644 --- a/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/admin/SecUserController.java +++ b/scaleph-api/src/main/java/cn/sliew/scaleph/api/controller/admin/SecUserController.java @@ -73,7 +73,7 @@ * * @author liyu */ -@RestController +//@RestController @RequestMapping("/api") @Tag(name = "系统管理-用户管理") public class SecUserController { diff --git a/scaleph-api/src/main/java/cn/sliew/scaleph/api/exception/GlobalExceptionHandler.java b/scaleph-api/src/main/java/cn/sliew/scaleph/api/exception/GlobalExceptionHandler.java index 8045fe378..9fe3d835b 100644 --- a/scaleph-api/src/main/java/cn/sliew/scaleph/api/exception/GlobalExceptionHandler.java +++ b/scaleph-api/src/main/java/cn/sliew/scaleph/api/exception/GlobalExceptionHandler.java @@ -47,7 +47,7 @@ * @author gleiyu */ @Slf4j -@ControllerAdvice +//@ControllerAdvice public class GlobalExceptionHandler { /** diff --git a/scaleph-common/src/main/java/cn/sliew/scaleph/common/util/I18nUtil.java b/scaleph-common/src/main/java/cn/sliew/scaleph/common/util/I18nUtil.java index 24f2b5fe8..042a26dd6 100644 --- a/scaleph-common/src/main/java/cn/sliew/scaleph/common/util/I18nUtil.java +++ b/scaleph-common/src/main/java/cn/sliew/scaleph/common/util/I18nUtil.java @@ -26,7 +26,7 @@ /** * @author gleiyu */ -@Component +//@Component public class I18nUtil { private static MessageSource messageSource; diff --git a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecResourceWebMapper.java b/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecResourceWebMapper.java index 7dc845385..94c01bf0a 100644 --- a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecResourceWebMapper.java +++ b/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecResourceWebMapper.java @@ -28,7 +28,7 @@ /** * 资源-web Mapper 接口 */ -@Repository +//@Repository public interface SecResourceWebMapper extends BaseMapper { List listByPidAndUserId(@Param("pid") Long pid, @Param("userId") Long userId, @Param("name") String name, @Param("layout") Boolean layout); diff --git a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecResourceWebRoleMapper.java b/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecResourceWebRoleMapper.java index b68f0fe38..8d549caf4 100644 --- a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecResourceWebRoleMapper.java +++ b/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecResourceWebRoleMapper.java @@ -32,7 +32,7 @@ /** * 资源-web与角色关联表 Mapper 接口 */ -@Repository +//@Repository public interface SecResourceWebRoleMapper extends BaseMapper { /** diff --git a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecRoleMapper.java b/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecRoleMapper.java index cff382e6d..7149cd6e3 100644 --- a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecRoleMapper.java +++ b/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecRoleMapper.java @@ -34,7 +34,7 @@ * @author liyu * @since 2021-08-01 */ -@Repository +//@Repository public interface SecRoleMapper extends BaseMapper { /** diff --git a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecUserMapper.java b/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecUserMapper.java index 63ee1585e..ecb98cd2b 100644 --- a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecUserMapper.java +++ b/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecUserMapper.java @@ -37,7 +37,7 @@ * @author liyu * @since 2021-08-01 */ -@Repository +//@Repository public interface SecUserMapper extends BaseMapper { /** diff --git a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecUserRoleMapper.java b/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecUserRoleMapper.java index 4cc877770..cdf0308af 100644 --- a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecUserRoleMapper.java +++ b/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecUserRoleMapper.java @@ -38,7 +38,7 @@ * @author liyu * @since 2021-08-01 */ -@Repository +//@Repository public interface SecUserRoleMapper extends BaseMapper { /** diff --git a/scaleph-security/pom.xml b/scaleph-security/pom.xml index 1f56c1744..41aa7d1b2 100644 --- a/scaleph-security/pom.xml +++ b/scaleph-security/pom.xml @@ -53,6 +53,12 @@ org.springframework.session spring-session-data-redis + + + cn.sliew + carp-module-security-spring + 0.0.1-SNAPSHOT + \ No newline at end of file diff --git a/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecResourceWebServiceImpl.java b/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecResourceWebServiceImpl.java index 421684ab8..edccab14b 100644 --- a/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecResourceWebServiceImpl.java +++ b/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecResourceWebServiceImpl.java @@ -38,7 +38,7 @@ import java.util.List; -@Service +//@Service public class SecResourceWebServiceImpl implements SecResourceWebService { @Autowired diff --git a/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecRoleServiceImpl.java b/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecRoleServiceImpl.java index 34da93cc2..391aa6ce8 100644 --- a/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecRoleServiceImpl.java +++ b/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecRoleServiceImpl.java @@ -50,7 +50,7 @@ * @author liyu * @since 2021-08-01 */ -@Service +//@Service public class SecRoleServiceImpl implements SecRoleService { @Autowired diff --git a/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecUserRoleServiceImpl.java b/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecUserRoleServiceImpl.java index 2054d8ec7..624bdb940 100644 --- a/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecUserRoleServiceImpl.java +++ b/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecUserRoleServiceImpl.java @@ -38,7 +38,7 @@ * @author liyu * @since 2021-08-01 */ -@Service +//@Service public class SecUserRoleServiceImpl implements SecUserRoleService { @Autowired diff --git a/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecUserServiceImpl.java b/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecUserServiceImpl.java index 93fee5342..ba40a6d83 100644 --- a/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecUserServiceImpl.java +++ b/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecUserServiceImpl.java @@ -48,7 +48,7 @@ * @author liyu * @since 2021-08-01 */ -@Service +//@Service public class SecUserServiceImpl implements SecUserService { @Autowired From 5c074c539ca1f822a96a3bae189043635a43bbb0 Mon Sep 17 00:00:00 2001 From: wangqi Date: Thu, 18 Jul 2024 21:27:20 +0800 Subject: [PATCH 4/8] feature: replace basic modules and components --- .../scaleph/api/config/MybatisConfig.java | 2 +- .../master/security/SecResourceWebMapper.java | 36 ----- .../security/SecResourceWebRoleMapper.java | 58 ------- .../mapper/master/security/SecRoleMapper.java | 48 ------ .../mapper/master/security/SecUserMapper.java | 91 ----------- .../master/security/SecUserRoleMapper.java | 73 --------- .../services/impl/SessionServiceImpl.java | 67 ++++----- .../UserDetailsServiceImpl.java | 44 +----- .../impl/SecAuthenticateServiceImpl.java | 69 +-------- .../service/impl/SecAuthorizeServiceImpl.java | 142 ++---------------- .../impl/SecResourceWebServiceImpl.java | 57 +------ .../service/impl/SecRoleServiceImpl.java | 61 ++------ .../service/impl/SecUserRoleServiceImpl.java | 19 +-- .../service/impl/SecUserServiceImpl.java | 73 ++------- .../security/web/OnlineUserService.java | 53 +------ 15 files changed, 90 insertions(+), 803 deletions(-) delete mode 100644 scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecResourceWebMapper.java delete mode 100644 scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecResourceWebRoleMapper.java delete mode 100644 scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecRoleMapper.java delete mode 100644 scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecUserMapper.java delete mode 100644 scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecUserRoleMapper.java diff --git a/scaleph-api/src/main/java/cn/sliew/scaleph/api/config/MybatisConfig.java b/scaleph-api/src/main/java/cn/sliew/scaleph/api/config/MybatisConfig.java index 3e2f9ae3c..bc651fbec 100644 --- a/scaleph-api/src/main/java/cn/sliew/scaleph/api/config/MybatisConfig.java +++ b/scaleph-api/src/main/java/cn/sliew/scaleph/api/config/MybatisConfig.java @@ -31,7 +31,7 @@ import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; -@Configuration +//@Configuration public class MybatisConfig { @Bean diff --git a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecResourceWebMapper.java b/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecResourceWebMapper.java deleted file mode 100644 index 94c01bf0a..000000000 --- a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecResourceWebMapper.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.dao.mapper.master.security; - -import cn.sliew.scaleph.dao.entity.master.security.SecResourceWeb; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import org.apache.ibatis.annotations.Param; -import org.springframework.stereotype.Repository; - -import java.util.List; - -/** - * 资源-web Mapper 接口 - */ -//@Repository -public interface SecResourceWebMapper extends BaseMapper { - - List listByPidAndUserId(@Param("pid") Long pid, @Param("userId") Long userId, @Param("name") String name, @Param("layout") Boolean layout); - -} diff --git a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecResourceWebRoleMapper.java b/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecResourceWebRoleMapper.java deleted file mode 100644 index 8d549caf4..000000000 --- a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecResourceWebRoleMapper.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.dao.mapper.master.security; - -import cn.sliew.scaleph.common.dict.security.RoleStatus; -import cn.sliew.scaleph.dao.entity.master.security.SecResourceWebRole; -import cn.sliew.scaleph.dao.entity.master.security.SecResourceWebVO; -import cn.sliew.scaleph.dao.entity.master.security.SecRole; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import org.apache.ibatis.annotations.Param; -import org.springframework.stereotype.Repository; - -import java.util.List; - -/** - * 资源-web与角色关联表 Mapper 接口 - */ -//@Repository -public interface SecResourceWebRoleMapper extends BaseMapper { - - /** - * 查询 资源-web 关联的角色 - */ - Page selectRelatedRolesByWebResource(Page page, - @Param("resourceWebId") Long resourceWebId, - @Param("status") RoleStatus status, - @Param("name") String name); - - /** - * 查询 资源-web 未关联的角色 - */ - Page selectUnrelatedRolesByWebResource(Page page, - @Param("resourceWebId") Long resourceWebId, - @Param("status") RoleStatus status, - @Param("name") String name); - - /** - * 查询所有 资源-web,包含角色关联信息 - */ - List selectAllResourceWebWithAuthorizeStatus(@Param("roleId") Long roleId, @Param("pid") Long pid); -} diff --git a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecRoleMapper.java b/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecRoleMapper.java deleted file mode 100644 index 7149cd6e3..000000000 --- a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecRoleMapper.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.dao.mapper.master.security; - -import cn.sliew.scaleph.dao.entity.master.security.SecRole; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import org.apache.ibatis.annotations.Param; -import org.springframework.stereotype.Repository; - -import java.io.Serializable; -import java.util.List; - -/** - *

- * 角色表 Mapper 接口 - *

- * - * @author liyu - * @since 2021-08-01 - */ -//@Repository -public interface SecRoleMapper extends BaseMapper { - - /** - * 查询部门对应的角色信息 - * - * @param grant 是否授权 - * @param deptId 部门id - * @return list - */ - List selectRoleByDept(@Param("grant") String grant, @Param("deptId") Serializable deptId); -} diff --git a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecUserMapper.java b/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecUserMapper.java deleted file mode 100644 index ecb98cd2b..000000000 --- a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecUserMapper.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.dao.mapper.master.security; - -import java.util.List; - -import cn.sliew.scaleph.dao.entity.master.security.SecRole; -import cn.sliew.scaleph.dao.entity.master.security.SecUser; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import org.apache.ibatis.annotations.Param; -import org.apache.ibatis.annotations.Update; -import org.springframework.stereotype.Repository; - -/** - *

- * 用户基本信息表 Mapper 接口 - *

- * - * @author liyu - * @since 2021-08-01 - */ -//@Repository -public interface SecUserMapper extends BaseMapper { - - /** - * 批量修改用户状态 - * - * @param idList 用户id列表 - * @param userStatus 用户状态 - * @return int - */ - @Update({""}) - int batchUpdateUserStatus(@Param("idList") List idList, - @Param("userStatus") String userStatus); - - /** - * 分页查询 - * - * @param page 分页参数 - * @param deptId 部门编码 - * @param roleId 角色编码 - * @param secUser 用户参数 - * @return list - */ - Page selectPage(IPage page, @Param("deptId") String deptId, - @Param("roleId") String roleId, @Param("user") SecUser secUser); - - /** - * 根据角色或者部门id查询 - * - * @param deptId 部门id - * @param roleId 角色id - * @param userName userName - * @param direction 1:target 0:source - * @return list - */ - List selectByRoleOrDept(@Param("deptId") String deptId, @Param("roleId") String roleId, - @Param("userName") String userName, - @Param("direction") String direction); - - /** - * 查询用户对应所有角色权限信息 - * - * @param userName user name - * @return role list - */ - List selectAllPrivilege(@Param("userName") String userName); -} diff --git a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecUserRoleMapper.java b/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecUserRoleMapper.java deleted file mode 100644 index cdf0308af..000000000 --- a/scaleph-dao/src/main/java/cn/sliew/scaleph/dao/mapper/master/security/SecUserRoleMapper.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cn.sliew.scaleph.dao.mapper.master.security; - -import cn.sliew.scaleph.common.dict.security.RoleStatus; -import cn.sliew.scaleph.common.dict.security.UserStatus; -import cn.sliew.scaleph.dao.entity.master.security.SecRole; -import cn.sliew.scaleph.dao.entity.master.security.SecUser; -import cn.sliew.scaleph.dao.entity.master.security.SecUserRole; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import org.apache.ibatis.annotations.Param; -import org.springframework.stereotype.Repository; - -import java.util.List; - -/** - *

- * 用户角色关联表 Mapper 接口 - *

- * - * @author liyu - * @since 2021-08-01 - */ -//@Repository -public interface SecUserRoleMapper extends BaseMapper { - - /** - * 查询角色关联的用户 - */ - Page selectRelatedUsersByRole(Page page, - @Param("roleId") Long roleId, - @Param("status") UserStatus status, - @Param("userName") String userName); - - /** - * 查询角色未关联的用户 - */ - Page selectUnrelatedUsersByRole(Page page, - @Param("roleId") Long roleId, - @Param("status") UserStatus status, - @Param("userName") String userName); - - /** - * 查询用户关联的角色 - */ - List selectRelatedRolesByUser(@Param("userId") Long userId, - @Param("status") RoleStatus status, - @Param("name") String name); - - /** - * 查询用户未关联的角色 - */ - List selectUnrelatedRolesByUser(@Param("userId") Long userId, - @Param("status") RoleStatus status, - @Param("name") String name); -} diff --git a/scaleph-engine/scaleph-engine-sql-gateway/src/main/java/cn/sliew/scaleph/engine/sql/gateway/services/impl/SessionServiceImpl.java b/scaleph-engine/scaleph-engine-sql-gateway/src/main/java/cn/sliew/scaleph/engine/sql/gateway/services/impl/SessionServiceImpl.java index e6fff4d76..8b741f793 100644 --- a/scaleph-engine/scaleph-engine-sql-gateway/src/main/java/cn/sliew/scaleph/engine/sql/gateway/services/impl/SessionServiceImpl.java +++ b/scaleph-engine/scaleph-engine-sql-gateway/src/main/java/cn/sliew/scaleph/engine/sql/gateway/services/impl/SessionServiceImpl.java @@ -18,15 +18,22 @@ package cn.sliew.scaleph.engine.sql.gateway.services.impl; -import java.time.Duration; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - +import cn.sliew.milky.common.util.JacksonUtil; +import cn.sliew.scaleph.dao.DataSourceConstants; +import cn.sliew.scaleph.dao.entity.master.ws.WsFlinkSqlGatewayCatalog; +import cn.sliew.scaleph.dao.entity.master.ws.WsFlinkSqlGatewaySession; +import cn.sliew.scaleph.dao.mapper.master.ws.WsFlinkSqlGatewayCatalogMapper; +import cn.sliew.scaleph.dao.mapper.master.ws.WsFlinkSqlGatewaySessionMapper; +import cn.sliew.scaleph.engine.sql.gateway.services.SessionService; +import cn.sliew.scaleph.engine.sql.gateway.services.dto.FlinkSqlGatewaySession; +import cn.sliew.scaleph.engine.sql.gateway.util.CatalogUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.fasterxml.jackson.core.type.TypeReference; +import com.github.benmanes.caffeine.cache.Caffeine; +import com.github.benmanes.caffeine.cache.LoadingCache; +import com.github.benmanes.caffeine.cache.RemovalCause; +import lombok.extern.slf4j.Slf4j; import org.apache.flink.configuration.Configuration; import org.apache.flink.table.catalog.Catalog; import org.apache.flink.table.gateway.api.endpoint.EndpointVersion; @@ -41,32 +48,18 @@ import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.fasterxml.jackson.core.type.TypeReference; -import com.github.benmanes.caffeine.cache.Caffeine; -import com.github.benmanes.caffeine.cache.LoadingCache; -import com.github.benmanes.caffeine.cache.RemovalCause; -import com.zaxxer.hikari.HikariDataSource; - -import cn.sliew.milky.common.util.JacksonUtil; -import cn.sliew.scaleph.dao.entity.master.ws.WsFlinkSqlGatewayCatalog; -import cn.sliew.scaleph.dao.entity.master.ws.WsFlinkSqlGatewaySession; -import cn.sliew.scaleph.dao.mapper.master.ws.WsFlinkSqlGatewayCatalogMapper; -import cn.sliew.scaleph.dao.mapper.master.ws.WsFlinkSqlGatewaySessionMapper; -import cn.sliew.scaleph.engine.sql.gateway.services.SessionService; -import cn.sliew.scaleph.engine.sql.gateway.services.dto.FlinkSqlGatewaySession; -import cn.sliew.scaleph.engine.sql.gateway.util.CatalogUtil; -import lombok.extern.slf4j.Slf4j; +import javax.sql.DataSource; +import java.time.Duration; +import java.util.*; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; -import static cn.sliew.scaleph.engine.sql.gateway.store.JdbcCatalogStoreOptions.DRIVER; -import static cn.sliew.scaleph.engine.sql.gateway.store.JdbcCatalogStoreOptions.JDBC_URL; -import static cn.sliew.scaleph.engine.sql.gateway.store.JdbcCatalogStoreOptions.PASSWORD; -import static cn.sliew.scaleph.engine.sql.gateway.store.JdbcCatalogStoreOptions.USERNAME; +import static cn.sliew.scaleph.engine.sql.gateway.store.JdbcCatalogStoreOptions.*; import static cn.sliew.scaleph.engine.sql.gateway.store.ScalephCatalogStoreOptions.IDENTIFIER; import static cn.sliew.scaleph.engine.sql.gateway.store.ScalephCatalogStoreOptions.SESSION_HANDLE; import static org.apache.flink.table.catalog.CommonCatalogOptions.TABLE_CATALOG_STORE_KIND; @@ -88,8 +81,9 @@ public class SessionServiceImpl implements SessionService, InitializingBean, Dis @Autowired private WsFlinkSqlGatewayCatalogMapper wsFlinkSqlGatewayCatalogMapper; + @Qualifier(DataSourceConstants.MASTER_DATA_SOURCE_FACTORY) @Autowired - private HikariDataSource dataSource; + private DataSource dataSource; // TODO Initialize cache by settings private final LoadingCache sessions = Caffeine.newBuilder() @@ -245,16 +239,17 @@ private FlinkSqlGatewaySession convertSession(WsFlinkSqlGatewaySession record) { Map sessionConfig = new HashMap<>(); if (StringUtils.hasText(record.getSessionConfig())) { sessionConfig = JacksonUtil.parseJsonString( - record.getSessionConfig(), new TypeReference>() {}); + record.getSessionConfig(), new TypeReference>() { + }); } // Set catalog store configuration final String catalogStoreOptionPrefix = TABLE_CATALOG_STORE_OPTION_PREFIX + IDENTIFIER + "."; sessionConfig.put(TABLE_CATALOG_STORE_KIND.key(), IDENTIFIER); sessionConfig.put(catalogStoreOptionPrefix + SESSION_HANDLE.key(), sessionId.toString()); - sessionConfig.put(catalogStoreOptionPrefix + DRIVER.key(), dataSource.getDriverClassName()); - sessionConfig.put(catalogStoreOptionPrefix + JDBC_URL.key(), dataSource.getJdbcUrl()); - sessionConfig.put(catalogStoreOptionPrefix + USERNAME.key(), dataSource.getUsername()); - sessionConfig.put(catalogStoreOptionPrefix + PASSWORD.key(), dataSource.getPassword()); +// sessionConfig.put(catalogStoreOptionPrefix + DRIVER.key(), dataSource.getDriverClassName()); +// sessionConfig.put(catalogStoreOptionPrefix + JDBC_URL.key(), dataSource.getJdbcUrl()); +// sessionConfig.put(catalogStoreOptionPrefix + USERNAME.key(), dataSource.getUsername()); +// sessionConfig.put(catalogStoreOptionPrefix + PASSWORD.key(), dataSource.getPassword()); session.setSessionConfig(sessionConfig); diff --git a/scaleph-security/src/main/java/cn/sliew/scaleph/security/authentication/UserDetailsServiceImpl.java b/scaleph-security/src/main/java/cn/sliew/scaleph/security/authentication/UserDetailsServiceImpl.java index 31f6ab461..83b1b194a 100644 --- a/scaleph-security/src/main/java/cn/sliew/scaleph/security/authentication/UserDetailsServiceImpl.java +++ b/scaleph-security/src/main/java/cn/sliew/scaleph/security/authentication/UserDetailsServiceImpl.java @@ -45,48 +45,8 @@ @Service public class UserDetailsServiceImpl implements UserDetailsService { - @Autowired - private SecUserService secUserService; - - /** - * 根据用户名查询登录用户信息 - * - * @param userName 用户名 - * @return 用户信息 - * @throws UsernameNotFoundException UsernameNotFoundException - */ @Override - public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException { - try { - SecUserDTO secUserDTO = secUserService.selectOne(userName); - if (secUserDTO == null) { - throw new BadCredentialsException(I18nUtil.get("response.error.login.password")); - } - - if (secUserDTO.getStatus() != UserStatus.ENABLED) { - throw new BadCredentialsException(I18nUtil.get("response.error.login.disable")); - } - - UserDetailInfo user = new UserDetailInfo(); - user.setUser(secUserDTO); - //查询用户角色权限信息 - List privileges = secUserService.getAllPrivilegeByUserName(userName); - user.setAuthorities(toGrantedAuthority(privileges)); - return user; - } catch (Exception e) { - log.error("获取用户信息异常! userName: {}", userName, e); - throw new UsernameNotFoundException(e.getMessage(), e); - } - } - - private List toGrantedAuthority(List roles) { - if (CollectionUtils.isEmpty(roles)) { - return Collections.emptyList(); - } - String[] privileges = roles.stream() - .flatMap(role -> role.getPrivileges().stream()) - .map(SecPrivilegeDTO::getPrivilegeCode) - .toArray(length -> new String[length]); - return AuthorityUtils.createAuthorityList(privileges); + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + return null; } } diff --git a/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecAuthenticateServiceImpl.java b/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecAuthenticateServiceImpl.java index 98d3988b2..f1daa719d 100644 --- a/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecAuthenticateServiceImpl.java +++ b/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecAuthenticateServiceImpl.java @@ -57,85 +57,24 @@ @Service public class SecAuthenticateServiceImpl implements SecAuthenticateService { - @Autowired - private RedisUtil redisUtil; - @Autowired - private AuthenticationManagerBuilder authenticationManagerBuilder; - @Autowired - private TokenProvider tokenProvider; - @Autowired - private SecUserService secUserService; - - @Autowired - private OnlineUserService onlineUserService; @Override public SecCaptchaDTO getCaptcha() { - LineCaptcha lineCaptcha = - CaptchaUtil.createLineCaptcha(150, 32, 5, RandomUtil.randomInt(6, 10)); - Font font = new Font("Stencil", Font.BOLD + Font.ITALIC, 20); - lineCaptcha.setFont(font); - lineCaptcha.setBackground(new Color(246, 250, 254)); - lineCaptcha.createCode(); - String uuid = Constants.AUTH_CODE_KEY + UUID.randomUUID(); - // 过期时间 10min - redisUtil.set(uuid, lineCaptcha.getCode(), 10 * 60); - SecCaptchaDTO dto = new SecCaptchaDTO(); - dto.setUuid(uuid); - dto.setImg(lineCaptcha.getImageBase64Data()); - return dto; + return null; } @Override public boolean verityCaptcha(String uuid, String authCode) { - String redisAuthCode = (String) redisUtil.get(uuid); - redisUtil.delKeys(uuid); - return StringUtils.hasText(authCode) && redisAuthCode.equalsIgnoreCase(authCode); + return false; } @Override public ResponseVO login(HttpServletRequest request, SecLoginParam param) { - if (verityCaptcha(param.getUuid(), param.getAuthCode()) == false) { - return ResponseVO.error( - ResponseCodeEnum.ERROR_CUSTOM.getCode(), - I18nUtil.get("response.error.authCode"), - ErrorShowTypeEnum.ERROR_MESSAGE); - } - - try { - authenticate(param); - final UserDetailInfo userInfo = (UserDetailInfo) SecurityUtil.getCurrentUser(); - userInfo.setLoginTime(new Date()); - userInfo.setLoginIpAddress(WebUtil.getClientIP(request)); - userInfo.setRemember(param.getRemember()); - //查询用户权限信息,同时存储到redis onlineuser中 - List roles = secUserService.getAllPrivilegeByUserName(userInfo.getUsername()); - userInfo.getUser().setRoles(roles); - //存储信息到redis中 - - //生成token 使用uuid作为token - String token = tokenProvider.createToken(); - onlineUserService.insert(userInfo, token); - //验证成功返回token - return ResponseVO.success(token); - } catch (BadCredentialsException | InternalAuthenticationServiceException e) { - return ResponseVO.error( - ResponseCodeEnum.ERROR_CUSTOM.getCode(), - I18nUtil.get("response.error.login.password"), - ErrorShowTypeEnum.ERROR_MESSAGE); - } - } - - private void authenticate(SecLoginParam param) { - //检查用户名密码 - UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(param.getUserName(), param.getPassword()); - //spring security框架调用userDetailsService获取用户信息并验证,验证通过后返回一个Authentication对象,存储到线程的SecurityContext中 - Authentication authentication = authenticationManagerBuilder.getObject().authenticate(authenticationToken); - SecurityContextHolder.getContext().setAuthentication(authentication); + return null; } @Override public void logout(String token) { - onlineUserService.logoutByToken(token); + } } diff --git a/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecAuthorizeServiceImpl.java b/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecAuthorizeServiceImpl.java index 57ec4d4b6..5d94bb0c4 100644 --- a/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecAuthorizeServiceImpl.java +++ b/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecAuthorizeServiceImpl.java @@ -19,8 +19,6 @@ package cn.sliew.scaleph.security.service.impl; import cn.sliew.scaleph.dao.entity.master.security.*; -import cn.sliew.scaleph.dao.mapper.master.security.SecResourceWebRoleMapper; -import cn.sliew.scaleph.dao.mapper.master.security.SecUserRoleMapper; import cn.sliew.scaleph.security.authentication.UserDetailInfo; import cn.sliew.scaleph.security.service.SecAuthorizeService; import cn.sliew.scaleph.security.service.SecResourceWebService; @@ -43,191 +41,83 @@ @Service public class SecAuthorizeServiceImpl implements SecAuthorizeService { - - @Autowired - private SecResourceWebService secResourceWebService; - @Autowired - private SecResourceWebRoleMapper secResourceWebRoleMapper; - @Autowired - private SecUserRoleMapper secUserRoleMapper; - @Autowired - private UserDetailsService userDetailsService; - @Override public List getWebRoute() { - UserDetailInfo userDetails = (UserDetailInfo) userDetailsService.loadUserByUsername(SecurityUtil.getCurrentUserName()); - return buildRouteByPid(0L, userDetails.getUser().getId()); - } - - private List buildRouteByPid(Long pid, Long userId) { - List secResourceWebDTOS = secResourceWebService.listByPidAndUserId(pid, userId, null); - List routes = new ArrayList<>(secResourceWebDTOS.size()); - for (SecResourceWebDTO secResourceWebDTO : secResourceWebDTOS) { - UmiRoute route = new UmiRoute(); - route.setName(secResourceWebDTO.getMenuName()); - route.setPath(secResourceWebDTO.getPath()); - route.setRedirect(secResourceWebDTO.getRedirect()); - route.setIcon(secResourceWebDTO.getIcon()); - route.setComponent(secResourceWebDTO.getComponent()); - List childRoutes = buildRouteByPid(secResourceWebDTO.getId(), userId); - if (CollectionUtils.isEmpty(childRoutes) == false) { - route.setRoutes(childRoutes); - } - routes.add(route); - } - return routes; + return null; } @Override public Page listAuthorizedRolesByResourceWebId(SecRoleListByResourceWebParam param) { - Page page = new Page(param.getCurrent(), param.getPageSize()); - Page secRolePage = secResourceWebRoleMapper.selectRelatedRolesByWebResource(page, param.getResourceWebId(), param.getStatus(), param.getName()); - Page result = new Page<>(secRolePage.getCurrent(), secRolePage.getSize(), secRolePage.getTotal()); - List secRoleDTOS = SecRoleConvert.INSTANCE.toDto(secRolePage.getRecords()); - result.setRecords(secRoleDTOS); - return result; + return null; } @Override public Page listUnauthorizedRolesByResourceWebId(SecRoleListByResourceWebParam param) { - Page page = new Page(param.getCurrent(), param.getPageSize()); - Page secRolePage = secResourceWebRoleMapper.selectUnrelatedRolesByWebResource(page, param.getResourceWebId(), param.getStatus(), param.getName()); - Page result = new Page<>(secRolePage.getCurrent(), secRolePage.getSize(), secRolePage.getTotal()); - List secRoleDTOS = SecRoleConvert.INSTANCE.toDto(secRolePage.getRecords()); - result.setRecords(secRoleDTOS); - return result; + return null; } @Override public void authorize(SecRoleBatchAuthorizeForResourceWebParam param) { - for (Long roleId : param.getRoleIds()) { - SecResourceWebRole record = new SecResourceWebRole(); - record.setResourceWebId(param.getResourceWebId()); - record.setRoleId(roleId); - secResourceWebRoleMapper.insert(record); - } + } @Override public void unauthorize(SecRoleBatchAuthorizeForResourceWebParam param) { - for (Long roleId : param.getRoleIds()) { - LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(SecResourceWebRole.class) - .eq(SecResourceWebRole::getResourceWebId, param.getResourceWebId()) - .eq(SecResourceWebRole::getRoleId, roleId); - secResourceWebRoleMapper.delete(queryWrapper); - } + } @Override public List listResourceWebsByRoleId(SecResourceWebListByRoleParam param) { - List secResourceWebVOS = secResourceWebRoleMapper.selectAllResourceWebWithAuthorizeStatus(param.getRoleId(), 0L); - List result = SecResourceWebWithAuthorizeConvert.INSTANCE.toDto(secResourceWebVOS); - result.forEach(dto -> recurse(param.getRoleId(), dto)); - return result; - } - - private void recurse(Long roleId, SecResourceWebWithAuthorizeDTO resourceWebDTO) { - List children = listResourceWebsByRoleIdAndPid(roleId, resourceWebDTO.getId()); - if (CollectionUtils.isEmpty(children) == false) { - resourceWebDTO.setChildren(children); - children.forEach(child -> recurse(roleId, child)); - } - } - - private List listResourceWebsByRoleIdAndPid(Long roleId, Long pid) { - List secResourceWebVOS = secResourceWebRoleMapper.selectAllResourceWebWithAuthorizeStatus(roleId, pid); - return SecResourceWebWithAuthorizeConvert.INSTANCE.toDto(secResourceWebVOS); + return null; } @Override public void authorize(SecResourceWebBatchAuthorizeForRoleParam param) { - for (Long resourceWebId : param.getResourceWebIds()) { - SecResourceWebRole record = new SecResourceWebRole(); - record.setResourceWebId(resourceWebId); - record.setRoleId(param.getRoleId()); - secResourceWebRoleMapper.insert(record); - } + } @Override public void unauthorize(SecResourceWebBatchAuthorizeForRoleParam param) { - for (Long resourceWebId : param.getResourceWebIds()) { - LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(SecResourceWebRole.class) - .eq(SecResourceWebRole::getResourceWebId, resourceWebId) - .eq(SecResourceWebRole::getRoleId, param.getRoleId()); - secResourceWebRoleMapper.delete(queryWrapper); - } + } @Override public Page listAuthorizedUsersByRoleId(SecUserListByRoleParam param) { - Page page = new Page(param.getCurrent(), param.getPageSize()); - Page secUserPage = secUserRoleMapper.selectRelatedUsersByRole(page, param.getRoleId(), param.getStatus(), param.getUserName()); - Page result = new Page<>(secUserPage.getCurrent(), secUserPage.getSize(), secUserPage.getTotal()); - List secUserDTOS = SecUserConvert.INSTANCE.toDto(secUserPage.getRecords()); - result.setRecords(secUserDTOS); - return result; + return null; } @Override public Page listUnauthorizedUsersByRoleId(SecUserListByRoleParam param) { - Page page = new Page(param.getCurrent(), param.getPageSize()); - Page secUserPage = secUserRoleMapper.selectUnrelatedUsersByRole(page, param.getRoleId(), param.getStatus(), param.getUserName()); - Page result = new Page<>(secUserPage.getCurrent(), secUserPage.getSize(), secUserPage.getTotal()); - List secUserDTOS = SecUserConvert.INSTANCE.toDto(secUserPage.getRecords()); - result.setRecords(secUserDTOS); - return result; + return null; } @Override public void authorize(SecUserBatchAuthorizeForRoleParam param) { - for (Long userId : param.getUserIds()) { - SecUserRole record = new SecUserRole(); - record.setUserId(userId); - record.setRoleId(param.getRoleId()); - secUserRoleMapper.insert(record); - } + } @Override public void unauthorize(SecUserBatchAuthorizeForRoleParam param) { - for (Long userId : param.getUserIds()) { - LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(SecUserRole.class) - .eq(SecUserRole::getUserId, userId) - .eq(SecUserRole::getRoleId, param.getRoleId()); - secUserRoleMapper.delete(queryWrapper); - } + } @Override public List listAuthorizedRolesByUserId(SecRoleListByUserParam param) { - List secRoleList = secUserRoleMapper.selectRelatedRolesByUser(param.getUserId(), param.getStatus(), param.getName()); - return SecRoleConvert.INSTANCE.toDto(secRoleList); + return null; } @Override public List listUnauthorizedRolesByUserId(SecRoleListByUserParam param) { - List secRoleList = secUserRoleMapper.selectUnrelatedRolesByUser(param.getUserId(), param.getStatus(), param.getName()); - return SecRoleConvert.INSTANCE.toDto(secRoleList); + return null; } @Override public void authorize(SecRoleBatchAuthorizeForUserParam param) { - for (Long roleId : param.getRoleIds()) { - SecUserRole record = new SecUserRole(); - record.setUserId(param.getUserId()); - record.setRoleId(roleId); - secUserRoleMapper.insert(record); - } + } @Override public void unauthorize(SecRoleBatchAuthorizeForUserParam param) { - for (Long roleId : param.getRoleIds()) { - LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(SecUserRole.class) - .eq(SecUserRole::getUserId, param.getUserId()) - .eq(SecUserRole::getRoleId, roleId); - secUserRoleMapper.delete(queryWrapper); - } + } } diff --git a/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecResourceWebServiceImpl.java b/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecResourceWebServiceImpl.java index edccab14b..b3c418664 100644 --- a/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecResourceWebServiceImpl.java +++ b/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecResourceWebServiceImpl.java @@ -21,7 +21,6 @@ import cn.sliew.scaleph.common.dict.security.ResourceType; import cn.sliew.scaleph.common.util.BeanUtil; import cn.sliew.scaleph.dao.entity.master.security.SecResourceWeb; -import cn.sliew.scaleph.dao.mapper.master.security.SecResourceWebMapper; import cn.sliew.scaleph.security.service.SecResourceWebService; import cn.sliew.scaleph.security.service.convert.SecResourceWebConvert; import cn.sliew.scaleph.security.service.dto.SecResourceWebDTO; @@ -40,83 +39,43 @@ //@Service public class SecResourceWebServiceImpl implements SecResourceWebService { - - @Autowired - private SecResourceWebMapper secResourceWebMapper; - @Override public Page listByPage(SecResourceWebListParam param) { - Page page = new Page<>(param.getCurrent(), param.getPageSize()); - LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(SecResourceWeb.class) - .eq(SecResourceWeb::getPid, param.getPid()) - .like(StringUtils.hasText(param.getName()), SecResourceWeb::getName, param.getName()); - Page list = secResourceWebMapper.selectPage(page, queryWrapper); - Page result = new Page<>(list.getCurrent(), list.getSize(), list.getTotal()); - List dtoList = SecResourceWebConvert.INSTANCE.toDto(list.getRecords()); - dtoList.forEach(dto -> recurse(dto, param.getName())); - result.setRecords(dtoList); - return result; - } - - private void recurse(SecResourceWebDTO resourceWebDTO, String name) { - List children = listByPid(resourceWebDTO.getId(), name); - if (CollectionUtils.isEmpty(children) == false) { - resourceWebDTO.setChildren(children); - children.forEach(child -> recurse(child, name)); - } + return null; } @Override public List listAll(ResourceType resourceType) { - List list = secResourceWebMapper.selectList(new LambdaQueryWrapper() - .eq(resourceType != null, SecResourceWeb::getType, resourceType)); - return SecResourceWebConvert.INSTANCE.toDto(list); + return null; } @Override public List listByPid(Long pid, String name) { - LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(SecResourceWeb.class) - .eq(SecResourceWeb::getPid, pid) - .like(StringUtils.hasText(name), SecResourceWeb::getName, name); - List list = secResourceWebMapper.selectList(queryWrapper); - return SecResourceWebConvert.INSTANCE.toDto(list); + return null; } @Override public List listByPidAndUserId(Long pid, Long userId, String name) { - List list = secResourceWebMapper.listByPidAndUserId(pid, userId, name, true); - return SecResourceWebConvert.INSTANCE.toDto(list); + return null; } @Override public int insert(SecResourceWebAddParam param) { - SecResourceWeb record = BeanUtil.copy(param, new SecResourceWeb()); - return secResourceWebMapper.insert(record); + return 0; } @Override public int update(SecResourceWebUpdateParam param) { - SecResourceWeb record = BeanUtil.copy(param, new SecResourceWeb()); - return secResourceWebMapper.updateById(record); + return 0; } @Override public int deleteById(Long id) { - List secResourceWebDTOS = listByPid(id, null); - for (SecResourceWebDTO resourceWebDTO : secResourceWebDTOS) { - deleteById(resourceWebDTO.getId()); - } - return secResourceWebMapper.deleteById(id); + return 0; } @Override public int deleteBatch(List ids) { - if (CollectionUtils.isEmpty(ids)) { - return 0; - } - for (Long id : ids) { - deleteById(id); - } - return ids.size(); + return 0; } } diff --git a/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecRoleServiceImpl.java b/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecRoleServiceImpl.java index 391aa6ce8..715af1f6d 100644 --- a/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecRoleServiceImpl.java +++ b/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecRoleServiceImpl.java @@ -20,7 +20,6 @@ import cn.sliew.scaleph.dao.DataSourceConstants; import cn.sliew.scaleph.dao.entity.master.security.SecRole; -import cn.sliew.scaleph.dao.mapper.master.security.SecRoleMapper; import cn.sliew.scaleph.security.service.SecDeptRoleService; import cn.sliew.scaleph.security.service.SecRolePrivilegeService; import cn.sliew.scaleph.security.service.SecRoleService; @@ -52,90 +51,48 @@ */ //@Service public class SecRoleServiceImpl implements SecRoleService { - - @Autowired - private SecRoleMapper secRoleMapper; - @Autowired - private SecUserRoleService secUserRoleService; - @Autowired - private SecRolePrivilegeService secRolePrivilegeService; - @Autowired - private SecDeptRoleService secDeptRoleService; - @Override public int insert(SecRoleAddParam param) { - SecRole record = new SecRole(); - BeanUtils.copyProperties(param, record); - return this.secRoleMapper.insert(record); + return 0; } @Override public int update(SecRoleUpdateParam param) { - SecRole record = new SecRole(); - BeanUtils.copyProperties(param, record); - return this.secRoleMapper.updateById(record); + return 0; } @Override - @Transactional(rollbackFor = Exception.class, transactionManager = DataSourceConstants.MASTER_TRANSACTION_MANAGER_FACTORY) public int deleteById(Long id) { - this.secUserRoleService.deleteByRoleId(id); - this.secRolePrivilegeService.deleteByRoleId(id); - this.secDeptRoleService.deleteByRoleId(id); - return this.secRoleMapper.deleteById(id); + return 0; } @Override - @Transactional(rollbackFor = Exception.class, transactionManager = DataSourceConstants.MASTER_TRANSACTION_MANAGER_FACTORY) public int deleteBatch(List ids) { - if (CollectionUtils.isEmpty(ids)) { - return 0; - } - for (Long id : ids) { - deleteById(id); - } - return ids.size(); + return 0; } @Override public SecRoleDTO selectOne(Long id) { - SecRole secRole = this.secRoleMapper.selectById(id); - return SecRoleConvert.INSTANCE.toDto(secRole); + return null; } @Override public SecRoleDTO selectOne(String roleCode) { - SecRole secRole = this.secRoleMapper.selectOne( - new LambdaQueryWrapper().eq(SecRole::getCode, roleCode)); - return SecRoleConvert.INSTANCE.toDto(secRole); + return null; } @Override public List listAll() { - List list = this.secRoleMapper.selectList( - new LambdaQueryWrapper().orderByAsc(SecRole::getId)); - return SecRoleConvert.INSTANCE.toDto(list); + return null; } @Override public Page listByPage(SecRoleListParam param) { - Page page = new Page<>(param.getCurrent(), param.getPageSize()); - LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(SecRole.class) - .eq(param.getType() != null, SecRole::getType, param.getType()) - .eq(param.getStatus() != null, SecRole::getStatus, param.getStatus()) - .like(StringUtils.hasText(param.getName()), SecRole::getName, param.getName()) - .orderByAsc(SecRole::getId); - Page secRolePage = secRoleMapper.selectPage(page, queryWrapper); - Page result = new Page<>(secRolePage.getCurrent(), secRolePage.getSize(), secRolePage.getTotal()); - List secRoleDTOS = SecRoleConvert.INSTANCE.toDto(secRolePage.getRecords()); - result.setRecords(secRoleDTOS); - return result; + return null; } @Override public List selectRoleByDept(String grant, Long deptId) { - List list = this.secRoleMapper.selectRoleByDept(grant, deptId); - return SecRoleConvert.INSTANCE.toDto(list); + return null; } - } diff --git a/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecUserRoleServiceImpl.java b/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecUserRoleServiceImpl.java index 624bdb940..19b433461 100644 --- a/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecUserRoleServiceImpl.java +++ b/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecUserRoleServiceImpl.java @@ -22,7 +22,6 @@ import java.util.List; import cn.sliew.scaleph.dao.entity.master.security.SecUserRole; -import cn.sliew.scaleph.dao.mapper.master.security.SecUserRoleMapper; import cn.sliew.scaleph.security.service.SecUserRoleService; import cn.sliew.scaleph.security.service.convert.SecUserRoleConvert; import cn.sliew.scaleph.security.service.dto.SecUserRoleDTO; @@ -41,33 +40,23 @@ //@Service public class SecUserRoleServiceImpl implements SecUserRoleService { - @Autowired - private SecUserRoleMapper secUserRoleMapper; - @Override public int insert(SecUserRoleDTO secUserRoleDTO) { - SecUserRole secUserRole = SecUserRoleConvert.INSTANCE.toDo(secUserRoleDTO); - return this.secUserRoleMapper.insert(secUserRole); + return 0; } @Override public int deleteByRoleId(Serializable roleId) { - return this.secUserRoleMapper.delete(new LambdaQueryWrapper() - .eq(SecUserRole::getRoleId, roleId)); + return 0; } @Override public int delete(SecUserRoleDTO secUserRoleDTO) { - return this.secUserRoleMapper.delete(new LambdaQueryWrapper() - .eq(SecUserRole::getRoleId, secUserRoleDTO.getRoleId()) - .eq(SecUserRole::getUserId, secUserRoleDTO.getUserId()) - ); + return 0; } @Override public List listByRoleId(Serializable roleId) { - List list = this.secUserRoleMapper.selectList(new LambdaQueryWrapper() - .eq(SecUserRole::getRoleId, roleId)); - return SecUserRoleConvert.INSTANCE.toDto(list); + return null; } } diff --git a/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecUserServiceImpl.java b/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecUserServiceImpl.java index ba40a6d83..2c4efd755 100644 --- a/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecUserServiceImpl.java +++ b/scaleph-security/src/main/java/cn/sliew/scaleph/security/service/impl/SecUserServiceImpl.java @@ -22,7 +22,6 @@ import cn.sliew.scaleph.common.enums.UserStatusEnum; import cn.sliew.scaleph.dao.entity.master.security.SecRole; import cn.sliew.scaleph.dao.entity.master.security.SecUser; -import cn.sliew.scaleph.dao.mapper.master.security.SecUserMapper; import cn.sliew.scaleph.security.service.SecUserService; import cn.sliew.scaleph.security.service.convert.SecRoleConvert; import cn.sliew.scaleph.security.service.convert.SecUserConvert; @@ -51,114 +50,68 @@ //@Service public class SecUserServiceImpl implements SecUserService { - @Autowired - private SecUserMapper secUserMapper; - @Override public int insert(SecUserDTO secUserDTO) { - SecUser secUser = SecUserConvert.INSTANCE.toDo(secUserDTO); - return this.secUserMapper.insert(secUser); + return 0; } @Override public int update(SecUserDTO secUserDTO) { - SecUser secUser = SecUserConvert.INSTANCE.toDo(secUserDTO); - return this.secUserMapper.updateById(secUser); + return 0; } @Override public int updateByUserName(SecUserDTO secUserDTO) { - SecUser secUser = SecUserConvert.INSTANCE.toDo(secUserDTO); - return this.secUserMapper.update(secUser, new LambdaQueryWrapper() - .eq(SecUser::getUserName, secUser.getUserName()) - ); + return 0; } @Override public int deleteById(Long id) { - SecUser secUser = new SecUser(); - secUser.setId(id); - secUser.setStatus(UserStatus.DELETED); - return this.secUserMapper.updateById(secUser); + return 0; } @Override public int deleteBatch(Map map) { - List list = new ArrayList<>(); - for (Map.Entry entry : map.entrySet()) { - list.add((Integer) entry.getValue()); - } - - return this.secUserMapper.batchUpdateUserStatus(list, UserStatusEnum.LOGOFF.getValue()); - + return 0; } @Override public SecUserDTO selectOne(Long id) { - SecUser secUser = this.secUserMapper.selectById(id); - return SecUserConvert.INSTANCE.toDto(secUser); + return null; } @Override public SecUserDTO selectOne(String userName) { - SecUser secUser = this.secUserMapper.selectOne( - Wrappers.lambdaQuery(SecUser.class).eq(SecUser::getUserName, userName)); - return SecUserConvert.INSTANCE.toDto(secUser); + return null; } @Override public Page listByPage(SecUserParam secUserParam) { - SecUser secUser = new SecUser(); - secUser.setUserName(secUserParam.getUserName()); - secUser.setNickName(secUserParam.getNickName()); - secUser.setEmail(secUserParam.getEmail()); - secUser.setStatus(secUserParam.getUserStatus()); - Page result = new Page<>(); - Page list = this.secUserMapper.selectPage( - new Page<>(secUserParam.getCurrent(), secUserParam.getPageSize()), - secUserParam.getDeptId(), - secUserParam.getRoleId(), - secUser - ); - List dtoList = SecUserConvert.INSTANCE.toDto(list.getRecords()); - result.setCurrent(list.getCurrent()); - result.setSize(list.getSize()); - result.setRecords(dtoList); - result.setTotal(list.getTotal()); - return result; + return null; } @Override public SecUserDTO selectByEmail(String email) { - SecUser secUser = - this.secUserMapper.selectOne(new LambdaQueryWrapper().eq(SecUser::getEmail, email)); - return SecUserConvert.INSTANCE.toDto(secUser); + return null; } @Override public List listByRole(Long roleId, String userName, String direction) { - List list = - this.secUserMapper.selectByRoleOrDept("", String.valueOf(roleId), userName, direction); - return SecUserConvert.INSTANCE.toDto(list); + return null; } @Override public List listByDept(Long deptId, String userName, String direction) { - List list = - this.secUserMapper.selectByRoleOrDept(String.valueOf(deptId), "", userName, direction); - return SecUserConvert.INSTANCE.toDto(list); + return null; } @Override public List listByUserName(String userName) { - List list = this.secUserMapper.selectList(new LambdaQueryWrapper() - .like(SecUser::getUserName, userName)); - return SecUserConvert.INSTANCE.toDto(list); + return null; } @Override public List getAllPrivilegeByUserName(String userName) { - List list = this.secUserMapper.selectAllPrivilege(userName); - return SecRoleConvert.INSTANCE.toDto(list); + return null; } } diff --git a/scaleph-security/src/main/java/cn/sliew/scaleph/security/web/OnlineUserService.java b/scaleph-security/src/main/java/cn/sliew/scaleph/security/web/OnlineUserService.java index e9a5616e0..748f33fa7 100644 --- a/scaleph-security/src/main/java/cn/sliew/scaleph/security/web/OnlineUserService.java +++ b/scaleph-security/src/main/java/cn/sliew/scaleph/security/web/OnlineUserService.java @@ -49,10 +49,6 @@ public class OnlineUserService { private SecurityProperties properties; @Autowired private RedisUtil redisUtil; - @Autowired - private SecUserService secUserService; - @Autowired - private SecRoleService secRoleService; /** * 存储登录用户信息到redis中 @@ -127,58 +123,13 @@ public void logoutByToken(String token) { public OnlineUserVO getAllPrivilegeByToken(String token) { - OnlineUserVO onlineUser = - (OnlineUserVO) this.redisUtil.get(Constants.ONLINE_TOKEN_KEY + token); - long now = System.currentTimeMillis(); - long time = this.redisUtil.getExipre(Constants.ONLINE_TOKEN_KEY + token); - if (onlineUser != null && onlineUser.getPrivileges() != null && - onlineUser.getRoles() != null) { - onlineUser.setExpireTime((time * 1000) + now); - return onlineUser; - } else if (onlineUser != null) { - //缓存中信息失效,从数据库中获取权限信息并刷新缓存 - String userName = onlineUser.getUserName(); - List roleList = this.secUserService.getAllPrivilegeByUserName(userName); - Set roles = new TreeSet<>(); - Set privileges = new TreeSet<>(); - for (SecRoleDTO role : roleList) { - roles.add(role.getCode().toLowerCase()); - if (role.getPrivileges() == null) { - continue; - } - for (SecPrivilegeDTO privilege : role.getPrivileges()) { - privileges.add(privilege.getPrivilegeCode().toLowerCase()); - } - } - onlineUser.setRoles(new ArrayList<>(roles)); - onlineUser.setPrivileges(new ArrayList<>(privileges)); - onlineUser.setExpireTime((time * 1000) + now); - return onlineUser; - } else { - return null; - } + return null; } @Async public void disableOnlineCacheRole(Long roleId) { - SecRoleDTO secRoleDTO = secRoleService.selectOne(roleId); - if (!StringUtils.isEmpty(secRoleDTO.getCode())) { - List keys = redisUtil.scan(Constants.ONLINE_TOKEN_KEY + "*"); - for (String key : keys) { - OnlineUserVO onlineUser = (OnlineUserVO) redisUtil.get(key); - if (onlineUser != null && onlineUser.getRoles() != null) { - for (String r : onlineUser.getRoles()) { - if (secRoleDTO.getCode().equalsIgnoreCase(r)) { - //清空权限数据 - onlineUser.setPrivileges(null); - onlineUser.setRoles(null); - redisUtil.set(key, onlineUser); - } - } - } - } - } + } From 2e1bfc6d31983bb5c1ed365a8d52db1dbf91f31b Mon Sep 17 00:00:00 2001 From: wangqi Date: Thu, 18 Jul 2024 21:40:51 +0800 Subject: [PATCH 5/8] feature: replace basic modules and components --- .../src/main/resources/application-dev.yml | 5 ++ .../src/pages/User/Login/index.tsx | 5 +- .../admin/security/authentication.service.ts | 46 +++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 scaleph-ui-react/src/services/admin/security/authentication.service.ts diff --git a/scaleph-api/src/main/resources/application-dev.yml b/scaleph-api/src/main/resources/application-dev.yml index 2fc893d9b..27c0df64c 100644 --- a/scaleph-api/src/main/resources/application-dev.yml +++ b/scaleph-api/src/main/resources/application-dev.yml @@ -17,6 +17,11 @@ spring: datasource: + carp: + driver-class-name: com.mysql.cj.jdbc.Driver + jdbc-url: jdbc:mysql://${MYSQL_HOST:127.0.0.1}:${MYSQL_PORT:3306}/carp?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useAffectedRows=true + username: ${MYSQL_USERNAME:root} + password: ${MYSQL_PASSWORD:123456} master: driver-class-name: com.mysql.cj.jdbc.Driver jdbc-url: jdbc:mysql://${MYSQL_HOST:127.0.0.1}:${MYSQL_PORT:3306}/scaleph?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useAffectedRows=true diff --git a/scaleph-ui-react/src/pages/User/Login/index.tsx b/scaleph-ui-react/src/pages/User/Login/index.tsx index 504765380..eb8fd31f2 100644 --- a/scaleph-ui-react/src/pages/User/Login/index.tsx +++ b/scaleph-ui-react/src/pages/User/Login/index.tsx @@ -9,6 +9,7 @@ import {AuthService} from "@/services/auth"; import {UserService} from "@/services/admin/user.service"; import styles from "../index.less"; import { AuthCode,LoginInfo } from "@/typings"; +import {AuthenticationService} from "@/services/admin/security/authentication.service"; const Lang = () => { const langClassName = useEmotionCss(({token}) => { @@ -42,14 +43,14 @@ const Login: React.FC = () => { }, []); const refreshAuthCode = async () => { - AuthService.refreshAuthImage().then((data) => setAuthCode(data)) + AuthenticationService.getAuthImage().then((response) => setAuthCode(response.data)) }; const handleSubmit = async () => { try { form.validateFields().then((values: LoginInfo) => { const params: LoginInfo = {...values, uuid: authCode?.uuid as string,}; - AuthService.login(params).then(async (resp) => { + AuthenticationService.login(params).then(async (resp) => { if (resp.success) { localStorage.setItem(USER_AUTH.token, resp.data); message.success(intl.formatMessage({id: "pages.user.login.success"})); diff --git a/scaleph-ui-react/src/services/admin/security/authentication.service.ts b/scaleph-ui-react/src/services/admin/security/authentication.service.ts new file mode 100644 index 000000000..1c8c63101 --- /dev/null +++ b/scaleph-ui-react/src/services/admin/security/authentication.service.ts @@ -0,0 +1,46 @@ +import {USER_AUTH} from '@/constants/constant'; +import {AuthCode, LoginInfo, OnlineUserInfo, ResponseBody} from '@/typings'; +import {request} from '@umijs/max'; + +export const AuthenticationService = { + url: '/api/carp/security/authentication', + + getAuthImage: async () => { + return request>(`${AuthenticationService.url}/captcha`, { + method: 'GET' + }); + }, + + login: async (loginInfo: LoginInfo) => { + return request>(`${AuthenticationService.url}/login`, { + method: 'POST', + data: loginInfo, + }); + }, + + + setSession: async (userInfo: OnlineUserInfo) => { + localStorage.setItem(USER_AUTH.userInfo, JSON.stringify(userInfo)); + let pCodes: string[] = []; + if (userInfo.roles != null && userInfo.roles != undefined) { + userInfo.roles.forEach((d) => { + pCodes.push(d); + }); + } + if (userInfo.privileges != null && userInfo.privileges != undefined) { + userInfo.privileges.forEach((d) => { + pCodes.push(d); + }); + } + localStorage.setItem(USER_AUTH.expireTime, userInfo.expireTime + ''); + localStorage.setItem(USER_AUTH.pCodes, JSON.stringify(pCodes)); + }, + + logout: async () => { + let token: string = localStorage.getItem(USER_AUTH.token) || ''; + request>('/api/user/logout', { + method: 'POST', + params: {token: token}, + }); + }, +}; From 8998e2f9a9299d7f3376888ef5e02393296885c8 Mon Sep 17 00:00:00 2001 From: wangqi Date: Sat, 27 Jul 2024 17:13:18 +0800 Subject: [PATCH 6/8] feature: replace basic modules and components --- tools/docker/mysql/init.d/carp-security.sql | 141 ++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 tools/docker/mysql/init.d/carp-security.sql diff --git a/tools/docker/mysql/init.d/carp-security.sql b/tools/docker/mysql/init.d/carp-security.sql new file mode 100644 index 000000000..3705e9e56 --- /dev/null +++ b/tools/docker/mysql/init.d/carp-security.sql @@ -0,0 +1,141 @@ +create database if not exists carp default character set utf8mb4 collate utf8mb4_unicode_ci; +use carp; + +drop table if exists carp_sec_application; +create table carp_sec_application +( + `id` bigint not null auto_increment comment '自增主键', + `type` varchar(4) not null comment '用户类型。系统,用户自定义', + `code` varchar(32) not null comment '应用标识', + `name` varchar(64) not null comment '应用名称', + `logo` varchar(255) not null comment '应用logo', + `url` varchar(255) not null comment '应用 url', + `order` int not null default 0 comment '排序', + `status` varchar(4) not null comment '应用状态。启用,禁用', + `remark` varchar(255) comment '备注', + `creator` varchar(32) comment '创建人', + `create_time` datetime not null default current_timestamp comment '创建时间', + `editor` varchar(32) comment '修改人', + `update_time` datetime not null default current_timestamp on update current_timestamp comment '更新时间', + primary key (id), + unique key (code) +) engine = innodb comment = 'security application'; + +drop table if exists carp_sec_user; +create table carp_sec_user +( + `id` bigint not null auto_increment comment '自增主键', + `type` varchar(4) not null comment '用户类型。系统,用户自定义', + `user_name` varchar(32) not null comment '用户名', + `nick_name` varchar(50) comment '昵称', + `avatar` varchar(255) comment '头像', + `email` varchar(128) comment '邮箱', + `phone` varchar(16) comment '手机', + `password` varchar(64) not null comment '密码', + `salt` varchar(64) not null comment '密码盐值', + `order` int not null default 0 comment '排序', + `status` varchar(4) not null comment '用户状态。启用,禁用', + `remark` varchar(255) comment '备注', + `creator` varchar(32) comment '创建人', + `create_time` datetime not null default current_timestamp comment '创建时间', + `editor` varchar(32) comment '修改人', + `update_time` datetime not null default current_timestamp on update current_timestamp comment '更新时间', + primary key (id), + unique key (user_name), + key (update_time) +) engine = innodb comment = 'security user'; + +insert into carp_sec_user (id, type, user_name, nick_name, avatar, email, phone, password, + `salt`, `order`, `status`, remark, creator, editor) +values (1, '0', 'sys_admin', '超级管理员', null, 'test@admin.com', null, + 'dfed150b0806844c2533c9c0ed70df51', 'ce5gT8lVxGdFN8RnSNAcjFUz8dMrRd7B', + 0, '0', null, 'sys', 'sys'); + +/* 角色表 */ +drop table if exists carp_sec_role; +create table carp_sec_role +( + `id` bigint not null auto_increment comment '自增主键', + `type` varchar(4) not null comment '角色类型。系统,用户自定义', + `code` varchar(32) not null comment '角色编码', + `name` varchar(64) not null comment '角色名称', + `order` int not null default 0 comment '排序', + `status` varchar(4) not null comment '角色状态', + `remark` varchar(255) comment '备注', + `creator` varchar(32) comment '创建人', + `create_time` datetime not null default current_timestamp comment '创建时间', + `editor` varchar(32) comment '修改人', + `update_time` datetime not null default current_timestamp on update current_timestamp comment '更新时间', + primary key (id), + unique key (code), + key (update_time) +) engine = innodb comment = '角色表'; + +insert into carp_sec_role (id, type, `code`, `name`, `order`, `status`, `creator`, `editor`) +values (1, '01', 'sys_super_admin', '超级系统管理员', 0, '1', 'sys', 'sys'); +insert into carp_sec_role (id, type, `code`, `name`, `order`, `status`, `creator`, `editor`) +values (2, '01', 'sys_admin', '系统管理员', 1, '1', 'sys', 'sys'); +insert into carp_sec_role (id, type, `code`, `name`, `order`, `status`, `creator`, `editor`) +values (3, '01', 'sys_normal', '普通用户', 2, '1', 'sys', 'sys'); + +drop table if exists carp_sec_resource_web; +create table carp_sec_resource_web +( + `id` bigint not null auto_increment comment '自增主键', + `type` varchar(128) not null comment '资源类型。导航,菜单,页面,按钮', + `pid` bigint not null default '0' comment '上级资源id', + `value` varchar(128) comment '资源code', + `label` varchar(128) comment '资源名称', + `path` varchar(128) comment '路由路径', + `order` int not null default 0 comment '排序', + `status` varchar(4) not null comment '角色状态', + `remark` varchar(256) comment '备注', + `creator` varchar(32) comment '创建人', + `create_time` datetime not null default current_timestamp comment '创建时间', + `editor` varchar(32) comment '修改人', + `update_time` datetime not null default current_timestamp on update current_timestamp comment '修改时间', + primary key (id), + unique key (type, pid, path) +) engine = innodb comment = '资源-web'; + +drop table if exists carp_sec_resource_web_role; +create table carp_sec_resource_web_role +( + `id` bigint not null auto_increment comment '自增主键', + `resource_web_id` bigint not null, + `role_id` bigint not null, + `creator` varchar(32) comment '创建人', + `create_time` datetime not null default current_timestamp comment '创建时间', + `editor` varchar(32) comment '修改人', + `update_time` datetime not null default current_timestamp on update current_timestamp comment '修改时间', + primary key (id), + unique key (resource_web_id, role_id) +) engine = innodb comment = '资源-web与角色关联表'; + +insert into carp_sec_resource_web_role (resource_web_id, role_id, creator, editor) +select t1.id as resource_web_id, + t2.id as role_id, + 'sys' as creator, + 'sys' as editor +from carp_sec_resource_web t1, + carp_sec_role t2 +where t2.`code` in ('sys_admin', 'sys_super_admin'); + +/* 用户角色关联表 */ +drop table if exists carp_sec_user_role; +create table carp_sec_user_role +( + `id` bigint not null auto_increment comment '自增主键', + `user_id` bigint not null comment '用户id', + `role_id` bigint not null comment '角色id', + `creator` varchar(32) comment '创建人', + `create_time` datetime not null default current_timestamp comment '创建时间', + `editor` varchar(32) comment '修改人', + `update_time` datetime not null default current_timestamp on update current_timestamp comment '更新时间', + primary key (id), + unique key (user_id, role_id), + key (update_time) +) engine = innodb comment = 'security user-role relation'; + +insert into carp_sec_user_role (id, user_id, role_id, creator, editor) +values (1, 1, 1, 'sys', 'sys'); \ No newline at end of file From 09305c0ba84ccd698f7e460b7777f4493e3830db Mon Sep 17 00:00:00 2001 From: wangqi <1942460489@qq.com> Date: Sun, 28 Jul 2024 11:42:36 +0800 Subject: [PATCH 7/8] feature: replace security module --- .../UserDetailsServiceImpl.java | 2 +- .../SecurityValidateService.java | 40 ++++--------------- .../security/config/TokenConfigurer.java | 2 +- .../scaleph/security/web/TokenFilter.java | 2 +- scaleph-ui-react/src/app.tsx | 5 ++- .../src/pages/User/Login/index.tsx | 29 ++++++-------- .../admin/security/authentication.service.ts | 26 +++++++----- scaleph-ui-react/src/services/auth.ts | 27 ------------- scaleph-ui-react/src/typings.d.ts | 11 ++++- 9 files changed, 53 insertions(+), 91 deletions(-) diff --git a/scaleph-security/src/main/java/cn/sliew/scaleph/security/authentication/UserDetailsServiceImpl.java b/scaleph-security/src/main/java/cn/sliew/scaleph/security/authentication/UserDetailsServiceImpl.java index 83b1b194a..1480b8f14 100644 --- a/scaleph-security/src/main/java/cn/sliew/scaleph/security/authentication/UserDetailsServiceImpl.java +++ b/scaleph-security/src/main/java/cn/sliew/scaleph/security/authentication/UserDetailsServiceImpl.java @@ -42,7 +42,7 @@ * @author gleiyu */ @Slf4j -@Service +//@Service public class UserDetailsServiceImpl implements UserDetailsService { @Override diff --git a/scaleph-security/src/main/java/cn/sliew/scaleph/security/authorization/SecurityValidateService.java b/scaleph-security/src/main/java/cn/sliew/scaleph/security/authorization/SecurityValidateService.java index 9b3c9c735..b08d7b5ef 100644 --- a/scaleph-security/src/main/java/cn/sliew/scaleph/security/authorization/SecurityValidateService.java +++ b/scaleph-security/src/main/java/cn/sliew/scaleph/security/authorization/SecurityValidateService.java @@ -18,19 +18,14 @@ package cn.sliew.scaleph.security.authorization; -import cn.sliew.scaleph.common.constant.Constants; -import cn.sliew.scaleph.security.util.SecurityUtil; +import cn.sliew.carp.module.security.spring.authorization.CarpSecurityValidateService; import jakarta.servlet.http.HttpServletRequest; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.Authentication; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.web.access.intercept.RequestAuthorizationContext; import org.springframework.stereotype.Service; -import java.util.Arrays; -import java.util.List; import java.util.function.Supplier; -import java.util.stream.Collectors; /** * @author gleiyu @@ -38,37 +33,18 @@ @Service(value = "svs") public class SecurityValidateService { - /** - * 自定义权限拦截逻辑。避免权限硬编码,从而实现页面动态调整角色权限,动态生效 - */ + @Autowired + private CarpSecurityValidateService carpSecurityValidateService; + public boolean support(HttpServletRequest request) { - return false; + return carpSecurityValidateService.support(request); } - /** - * 自定义权限认证逻辑。避免权限硬编码,从而实现页面动态调整角色权限,动态生效 - */ public boolean access(Supplier authentication, RequestAuthorizationContext context) { - return false; + return carpSecurityValidateService.access(authentication, context); } - /** - * 检查用户角色权限,有权限则放行。 - * 如果是SUPER ADMIN角色则直接放行 - * - * @param privileges 权限标识字符串 - * @return true/false - */ public boolean validate(String... privileges) { - UserDetails userDetails = SecurityUtil.getCurrentUser(); - if (userDetails == null) { - return false; - } - - List privilegeList = userDetails.getAuthorities().stream() - .map(GrantedAuthority::getAuthority) - .collect(Collectors.toList()); - return privilegeList.contains(Constants.ROLE_SYS_ADMIN) || - Arrays.stream(privileges).anyMatch(privilegeList::contains); + return carpSecurityValidateService.validate(privileges); } } diff --git a/scaleph-security/src/main/java/cn/sliew/scaleph/security/config/TokenConfigurer.java b/scaleph-security/src/main/java/cn/sliew/scaleph/security/config/TokenConfigurer.java index f7c31c6f2..50eeb1a3e 100644 --- a/scaleph-security/src/main/java/cn/sliew/scaleph/security/config/TokenConfigurer.java +++ b/scaleph-security/src/main/java/cn/sliew/scaleph/security/config/TokenConfigurer.java @@ -31,7 +31,7 @@ * * @author gleiyu */ -@Component +//@Component public class TokenConfigurer implements SecurityConfigurer { @Autowired diff --git a/scaleph-security/src/main/java/cn/sliew/scaleph/security/web/TokenFilter.java b/scaleph-security/src/main/java/cn/sliew/scaleph/security/web/TokenFilter.java index b5155cafe..4971bd04a 100644 --- a/scaleph-security/src/main/java/cn/sliew/scaleph/security/web/TokenFilter.java +++ b/scaleph-security/src/main/java/cn/sliew/scaleph/security/web/TokenFilter.java @@ -47,7 +47,7 @@ * * @author gleiyu */ -@Component +//@Component public class TokenFilter extends GenericFilterBean { @Autowired diff --git a/scaleph-ui-react/src/app.tsx b/scaleph-ui-react/src/app.tsx index 64c8665d3..9593657bf 100644 --- a/scaleph-ui-react/src/app.tsx +++ b/scaleph-ui-react/src/app.tsx @@ -13,6 +13,7 @@ import Icon from './icon'; import {OnlineUserInfo, ResponseBody} from "@/typings"; import {UserService} from "@/services/admin/user.service"; import {AuthService} from "@/services/auth"; +import {AuthenticationService} from "@/services/admin/security/authentication.service"; const isDev = process.env.NODE_ENV === "development"; const whiteList: string[] = ["/user/login", "/user/register"]; @@ -30,7 +31,7 @@ export async function getInitialState(): Promise<{ const fetchUserInfo = async () => { let user: OnlineUserInfo = {}; try { - await UserService.getOnlineUserInfo(localStorage.getItem(USER_AUTH.token)).then((resp) => { + await AuthenticationService.getOnlineUserInfo().then((resp) => { if (resp.success && resp.data) { user = resp.data; } else { @@ -100,7 +101,7 @@ export const layout: RunTimeLayoutConfig = ({initialState, setInitialState}) => return (<>{defaultDom}); }, rightContentRender: () => , - menuDataRender: () => defaultMenus, + // menuDataRender: () => defaultMenus, menuItemRender: (menuItemProps: any, defaultDom: any) => { return ( diff --git a/scaleph-ui-react/src/pages/User/Login/index.tsx b/scaleph-ui-react/src/pages/User/Login/index.tsx index eb8fd31f2..28c987289 100644 --- a/scaleph-ui-react/src/pages/User/Login/index.tsx +++ b/scaleph-ui-react/src/pages/User/Login/index.tsx @@ -51,23 +51,20 @@ const Login: React.FC = () => { form.validateFields().then((values: LoginInfo) => { const params: LoginInfo = {...values, uuid: authCode?.uuid as string,}; AuthenticationService.login(params).then(async (resp) => { - if (resp.success) { - localStorage.setItem(USER_AUTH.token, resp.data); + if (resp.success && resp.data) { + const onlineUserInfo = resp.data + localStorage.setItem(USER_AUTH.token, onlineUserInfo.token); message.success(intl.formatMessage({id: "pages.user.login.success"})); - UserService.getOnlineUserInfo(resp.data).then(async (response) => { - if (response.success && response.data) { - await flushSync(() => { - setInitialState((state) => ({ - ...state, - currentUser: response.data, - })); - }); - AuthService.setSession(response.data) - setTimeout(() => { - navigate("/"); - }, 500); - } - }) + await flushSync(() => { + setInitialState((state) => ({ + ...state, + currentUser: onlineUserInfo, + })); + }); + AuthenticationService.storeSession(onlineUserInfo) + setTimeout(() => { + navigate("/"); + }, 500); } else { refreshAuthCode(); } diff --git a/scaleph-ui-react/src/services/admin/security/authentication.service.ts b/scaleph-ui-react/src/services/admin/security/authentication.service.ts index 1c8c63101..3d5da45c0 100644 --- a/scaleph-ui-react/src/services/admin/security/authentication.service.ts +++ b/scaleph-ui-react/src/services/admin/security/authentication.service.ts @@ -12,30 +12,36 @@ export const AuthenticationService = { }, login: async (loginInfo: LoginInfo) => { - return request>(`${AuthenticationService.url}/login`, { + return request>(`${AuthenticationService.url}/login`, { method: 'POST', data: loginInfo, }); }, - - setSession: async (userInfo: OnlineUserInfo) => { + storeSession: async (userInfo: OnlineUserInfo) => { localStorage.setItem(USER_AUTH.userInfo, JSON.stringify(userInfo)); let pCodes: string[] = []; - if (userInfo.roles != null && userInfo.roles != undefined) { - userInfo.roles.forEach((d) => { - pCodes.push(d); + if (userInfo.roles) { + userInfo.roles.forEach((role) => { + pCodes.push(role.code); }); } - if (userInfo.privileges != null && userInfo.privileges != undefined) { - userInfo.privileges.forEach((d) => { - pCodes.push(d); + + if (userInfo.resourceWebs) { + userInfo.resourceWebs.forEach((resourceWeb) => { + pCodes.push(resourceWeb.name); }); } - localStorage.setItem(USER_AUTH.expireTime, userInfo.expireTime + ''); + localStorage.setItem(USER_AUTH.pCodes, JSON.stringify(pCodes)); }, + getOnlineUserInfo: async () => { + return request>(`${AuthenticationService.url}/onlineUser`, { + method: 'GET', + }); + }, + logout: async () => { let token: string = localStorage.getItem(USER_AUTH.token) || ''; request>('/api/user/logout', { diff --git a/scaleph-ui-react/src/services/auth.ts b/scaleph-ui-react/src/services/auth.ts index bcf412665..1dec1bda3 100644 --- a/scaleph-ui-react/src/services/auth.ts +++ b/scaleph-ui-react/src/services/auth.ts @@ -3,12 +3,6 @@ import {AuthCode, LoginInfo, OnlineUserInfo, RegisterInfo, ResponseBody} from '@ import {request} from '@umijs/max'; export const AuthService = { - login: async (loginInfo: LoginInfo) => { - return request>('/api/user/login', { - method: 'POST', - data: loginInfo, - }); - }, menuRoutes: async () => { return request>('/api/admin/authorize/routes', { @@ -23,27 +17,6 @@ export const AuthService = { }); }, - setSession: async (userInfo: OnlineUserInfo) => { - localStorage.setItem(USER_AUTH.userInfo, JSON.stringify(userInfo)); - let pCodes: string[] = []; - if (userInfo.roles != null && userInfo.roles != undefined) { - userInfo.roles.forEach((d) => { - pCodes.push(d); - }); - } - if (userInfo.privileges != null && userInfo.privileges != undefined) { - userInfo.privileges.forEach((d) => { - pCodes.push(d); - }); - } - localStorage.setItem(USER_AUTH.expireTime, userInfo.expireTime + ''); - localStorage.setItem(USER_AUTH.pCodes, JSON.stringify(pCodes)); - }, - - isUserLoggedIn: async () => { - return localStorage.getItem(USER_AUTH.token) ? true : false; - }, - hasPrivilege: async (code: string) => { let pCodes: string[] = JSON.parse(localStorage.getItem(USER_AUTH.pCodes) + ''); if (pCodes != null && pCodes != undefined) { diff --git a/scaleph-ui-react/src/typings.d.ts b/scaleph-ui-react/src/typings.d.ts index a6c3b7494..4dcf5b3c0 100644 --- a/scaleph-ui-react/src/typings.d.ts +++ b/scaleph-ui-react/src/typings.d.ts @@ -1,3 +1,5 @@ +import {SecResourceWeb, SecRole} from "@/services/admin/typings"; + declare module "slash2"; declare module "*.css"; declare module "*.less"; @@ -101,9 +103,16 @@ type RegisterInfo = { }; export type OnlineUserInfo = { + token: string; + userId?: number; + type?: string; + status?: string; userName?: string; + nickName?: string; + roles?: Array; + resourceWebs?: Array; + email?: string; - token?: string; privileges?: string[]; roles?: string[]; expireTime?: bigint; From c237e55ff30c5726690530018eb94adbdb552b26 Mon Sep 17 00:00:00 2001 From: wangqi <1942460489@qq.com> Date: Sun, 28 Jul 2024 16:06:53 +0800 Subject: [PATCH 8/8] feature: replace security module --- pom.xml | 7 +++++++ scaleph-security/pom.xml | 1 - 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 62c2f0f24..4308ceb8d 100644 --- a/pom.xml +++ b/pom.xml @@ -26,6 +26,7 @@ pom scaleph Scaleph System + https://github.com/flowerfine/scaleph @@ -150,6 +151,7 @@ 4.10.0 32.1.3-jre 8.3.8 + 0.0.1 1.0.13 1.0.2 3.3.4 @@ -492,6 +494,11 @@ ${disruptor.version} + + cn.sliew + carp-module-security-spring + ${carp.version} + cn.sliew milky-common diff --git a/scaleph-security/pom.xml b/scaleph-security/pom.xml index 41aa7d1b2..07587ed0f 100644 --- a/scaleph-security/pom.xml +++ b/scaleph-security/pom.xml @@ -57,7 +57,6 @@ cn.sliew carp-module-security-spring - 0.0.1-SNAPSHOT