diff --git a/db/nacos.sql b/db/nacos.sql index a1fde34..82cf265 100644 --- a/db/nacos.sql +++ b/db/nacos.sql @@ -11,7 +11,7 @@ Target Server Version : 50732 File Encoding : 65001 - Date: 17/08/2022 18:13:57 + Date: 18/08/2022 18:47:33 */ SET NAMES utf8mb4; @@ -40,14 +40,16 @@ CREATE TABLE `config_info` ( `c_schema` text CHARACTER SET utf8 COLLATE utf8_bin NULL, PRIMARY KEY (`id`) USING BTREE, UNIQUE INDEX `uk_configinfo_datagrouptenant`(`data_id`, `group_id`, `tenant_id`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 14 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = 'config_info' ROW_FORMAT = Dynamic; +) ENGINE = InnoDB AUTO_INCREMENT = 22 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = 'config_info' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of config_info -- ---------------------------- INSERT INTO `config_info` VALUES (9, 'zyjblogs-oauth-test.yml', 'public', 'server:\n port: 9029\nspring:\n devtools:\n add-properties: true\n application:\n name: zyjblogs-oauth\n datasource:\n driver-class-name: com.mysql.cj.jdbc.Driver\n url: jdbc:mysql://127.0.0.1:3306/zyjblogs_rbac?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&autoReconnect=true&failOverReadOnly=false&allowMultiQueries=true&serverTimezone=GMT%2B8\n username: root\n password: 123456\n\n redis:\n host: 127.0.0.1\n port: 6379\n password: \n timeout: 10000 #连接超时时间(毫秒)\n lettuce:\n pool:\n max-active: 8 # 连接池最大连接数\n max-wait: -1ms # 连接池最大阻塞等待时间(使用负值表示没有限制)\n min-idle: 0 # 连接池中的最小空闲连接\n max-idle: 8 # 连接池中的最大空闲连接\n # sentinel:\n # master: ${hatech.global.redis.sentinel.master}\n # nodes: ${hatech.global.redis.sentinel.nodes}\n # password: ${hatech.global.redis.sentinel.password}\nmybatis-plus:\n mapper-locations: classpath:mapper/**/*.xml\n global-config:\n db-config:\n #主键策略:assign_id(雪花算法)、assign_uuid(去下划线的UUID)\n id-type: assign_id\n configuration:\n # 是否开启自动驼峰命名规则映射:从数据库列名到Java属性驼峰命名的类似映射\n map-underscore-to-camel-case: true\n # 如果查询结果中包含空值的列,则 MyBatis 在映射的时候,不会映射这个字段\n call-setters-on-nulls: false\n # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用\n # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl\n log-impl: org.apache.ibatis.logging.stdout.StdOutImpl\nfeign:\n sentinel:\n enabled: true\n\nribbon:\n ReadTimeout: 6000 # 请求处理的超时时间\n ConnectTimeout: 3000 # 请求连接的超时时间\n MaxAutoRetries: 1 # 重试策略先尝试访问首选实例一次,失败后才会更换实例访问\n MaxAutoRetriesNextServer: 1 # 更换实例访问的次数:通过参数设置为2, 所以会尝试更换2次实例进行重试\n OkToRetryOnAllOperations: true # 开启对请求进行行重试\n\n\nmanagement:\n health:\n ldap:\n enabled: false\n endpoints:\n web:\n exposure:\n include: \'health\'\n endpoint:\n health:\n show-details: always', '713b49c57ee2be922797bfca5df170fb', '2022-08-17 17:35:05', '2022-08-17 17:57:11', 'nacos', '127.0.0.1', '', 'test', '', '', '', 'yaml', ''); -INSERT INTO `config_info` VALUES (10, 'zyjblogs-global-test.yml', 'global', 'none', '334c4a4c42fdb79d7ebc3e73b517e6f8', '2022-08-17 17:35:39', '2022-08-17 17:35:39', 'nacos', '127.0.0.1', '', 'test', NULL, NULL, NULL, 'text', NULL); +INSERT INTO `config_info` VALUES (10, 'zyjblogs-global-test.yml', 'global', 'zyjblogs:\n global:\n database:\n host: 127.0.0.1\n port: 3006\n username: root\n password: 123456!@#\n\n redis:\n host: 127.0.0.1\n port: 6379\n password: \n sentinel:\n master: mymaster\n nodes: 10.1.110.71:30029,10.1.110.72:30029,10.1.110.73:30029\n password: Redis_IStorM_1618\n \n sentinel:\n transport:\n port: 8179\n dashboard:\n host: 127.0.0.1\n port: 20000\n\n rabbitmq:\n host: 127.0.0.1\n port: 30110\n username: admin\n password: admin\n minio:\n accessKey: minioadmin\n endpoint: http://10.1.110.70:30120/\n secretKey: Minio_IStorM_1618\n xxl:\n job:\n admin:\n addresses: http://10.1.110.71:10090/xxl-job-admin\n accessToken: cee8d3f4791411eca519005056b38058\n executor:\n logretentiondays: 7\n ', '5971eba0ff27324509b98209371e2e1f', '2022-08-17 17:35:39', '2022-08-18 09:33:28', 'nacos', '127.0.0.1', '', 'test', '', '', '', 'yaml', ''); INSERT INTO `config_info` VALUES (12, 'zyjblogs-rbac-test.yml', 'public', 'server:\r\n port: 9039\r\nspring:\r\n devtools:\r\n add-properties: true\r\n application:\r\n name: zyjblogs-rbac\r\n datasource:\r\n driver-class-name: com.mysql.cj.jdbc.Driver\r\n url: jdbc:mysql://127.0.0.1:3306/zyjblogs_rbac?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&autoReconnect=true&failOverReadOnly=false&allowMultiQueries=true&serverTimezone=GMT%2B8\r\n username: root\r\n password: 123456\r\nmybatis-plus:\r\n mapper-locations: classpath:mapper/**/*.xml\r\n global-config:\r\n db-config:\r\n #主键策略:assign_id(雪花算法)、assign_uuid(去下划线的UUID)\r\n id-type: assign_id\r\n configuration:\r\n # 是否开启自动驼峰命名规则映射:从数据库列名到Java属性驼峰命名的类似映射\r\n map-underscore-to-camel-case: true\r\n # 如果查询结果中包含空值的列,则 MyBatis 在映射的时候,不会映射这个字段\r\n call-setters-on-nulls: false\r\n # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用\r\n # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl\r\n log-impl: org.apache.ibatis.logging.stdout.StdOutImpl\r\nfeign:\r\n sentinel:\r\n enabled: true\r\n\r\nribbon:\r\n ReadTimeout: 6000 # 请求处理的超时时间\r\n ConnectTimeout: 3000 # 请求连接的超时时间\r\n MaxAutoRetries: 1 # 重试策略先尝试访问首选实例一次,失败后才会更换实例访问\r\n MaxAutoRetriesNextServer: 1 # 更换实例访问的次数:通过参数设置为2, 所以会尝试更换2次实例进行重试\r\n OkToRetryOnAllOperations: true # 开启对请求进行行重试\r\n\r\n\r\nmanagement:\r\n health:\r\n ldap:\r\n enabled: false\r\n endpoints:\r\n web:\r\n exposure:\r\n include: \'health\'\r\n endpoint:\r\n health:\r\n show-details: always', 'bfd132739c919b446e0256345adad019', '2022-08-17 17:48:38', '2022-08-17 17:48:38', 'nacos', '127.0.0.1', '', 'test', NULL, NULL, NULL, 'yaml', NULL); +INSERT INTO `config_info` VALUES (14, 'zyjblogs-gateway-test.yml', 'public', '#通常情况下,只需要改config配置\nzyjblogs:\n config:\n server-port: 9019\n whilelist:\n allowPaths:\n - /v2/api-docs/**\n - /oauth/token\n - /oauth/check_token\n - /user/login\n\nserver:\n port: ${zyjblogs.config.server-port}\nspring:\n main:\n allow-bean-definition-overriding: true\n servlet:\n multipart:\n enabled: true\n max-file-size: 20MB\n max-request-size: 100MB\n redis:\n host: ${zyjblogs.global.redis.host}\n port: ${zyjblogs.global.redis.port}\n password: ${zyjblogs.global.redis.password}\n timeout: 10000 #连接超时时间(毫秒)\n lettuce:\n pool:\n max-active: 8 # 连接池最大连接数\n max-wait: -1ms # 连接池最大阻塞等待时间(使用负值表示没有限制)\n min-idle: 0 # 连接池中的最小空闲连接\n max-idle: 8 # 连接池中的最大空闲连接\n\n cloud:\n sentinel:\n datasource:\n ds1:\n nacos:\n username: ${spring.cloud.nacos.config.username}\n password: ${spring.cloud.nacos.config.password}\n namespace: ${spring.cloud.nacos.config.namespace}\n server-addr: ${spring.cloud.nacos.config.server-addr}\n group-id: SENTINEL_GROUP\n rule-type: flow\n data-id: ${spring.application.name}-sentinel\n data-type: json\n transport:\n port: ${zyjblogs.global.sentinel.transport.port}\n dashboard: ${zyjblogs.global.sentinel.transport.dashboard.host}:${hatech.global.sentinel.transport.dashboard.port}\n gateway:\n httpclient:\n websocket:\n #websocket最大传输长度,单位(b),默认为64kb,最大为Integer.MAX_VALUE\n max-frame-payload-length: 0x7fffffff\n discovery:\n locator:\n enabled: true\n routes:\n - id: zyjblogs-oauth\n uri: lb://zyjblogs-oauth\n predicates:\n - Path=/api/oauth/**\n filters:\n - StripPrefix=2\n - id: zyjblogs-rbac\n uri: lb://zyjblogs-rbac\n predicates:\n - Path=/api/rbac/**\n filters:\n - StripPrefix=2\n\nfeign:\n sentinel:\n enabled: true\n\nribbon:\n ReadTimeout: 90000 # 请求处理的超时时间\n ConnectTimeout: 3000 # 请求连接的超时时间\n MaxAutoRetries: 1 # 重试策略先尝试访问首选实例一次,失败后才会更换实例访问\n MaxAutoRetriesNextServer: 2 # 更换实例访问的次数:通过参数设置为2, 所以会尝试更换2次实例进行重试\n OkToRetryOnAllOperations: true # 开启对请求进行行重试\n\nmanagement:\n endpoints:\n web:\n exposure:\n include: \'health\'\n endpoint:\n health:\n show-details: always\n', 'de451d96d9134835784db63cfc88734c', '2022-08-18 09:26:44', '2022-08-18 10:22:05', 'nacos', '127.0.0.1', '', 'test', '', '', '', 'yaml', ''); +INSERT INTO `config_info` VALUES (18, 'zyjblogs-gateway-sentinel', 'DEFAULT_GROUP', '[\r\n]', 'fdaf133263369980df600fd06ce738ec', '2022-08-18 09:45:59', '2022-08-18 09:45:59', NULL, '127.0.0.1', '', 'test', NULL, NULL, NULL, 'json', NULL); -- ---------------------------- -- Table structure for config_info_aggr @@ -186,7 +188,7 @@ CREATE TABLE `his_config_info` ( INDEX `idx_gmt_create`(`gmt_create`) USING BTREE, INDEX `idx_gmt_modified`(`gmt_modified`) USING BTREE, INDEX `idx_did`(`data_id`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 18 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '多租户改造' ROW_FORMAT = Dynamic; +) ENGINE = InnoDB AUTO_INCREMENT = 26 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '多租户改造' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of his_config_info @@ -196,6 +198,14 @@ INSERT INTO `his_config_info` VALUES (0, 14, 'zyjblogs-global-test.yml', 'global INSERT INTO `his_config_info` VALUES (9, 15, 'zyjblogs-oauth-test.yml', 'public', '', 'server:\r\n port: 9029\r\nspring:\r\n application:\r\n name: zyjblogs-oauth\r\n datasource:\r\n driver-class-name: com.mysql.cj.jdbc.Driver\r\n url: jdbc:mysql://127.0.0.1:3306/zyjblogs_rbac?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&autoReconnect=true&failOverReadOnly=false&allowMultiQueries=true&serverTimezone=GMT%2B8\r\n username: root\r\n password: 123456\r\nmybatis-plus:\r\n mapper-locations: classpath:mapper/**/*.xml\r\n global-config:\r\n db-config:\r\n #主键策略:assign_id(雪花算法)、assign_uuid(去下划线的UUID)\r\n id-type: assign_id\r\n configuration:\r\n # 是否开启自动驼峰命名规则映射:从数据库列名到Java属性驼峰命名的类似映射\r\n map-underscore-to-camel-case: true\r\n # 如果查询结果中包含空值的列,则 MyBatis 在映射的时候,不会映射这个字段\r\n call-setters-on-nulls: false\r\n # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用\r\n # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl\r\n log-impl: org.apache.ibatis.logging.stdout.StdOutImpl\r\nfeign:\r\n sentinel:\r\n enabled: true\r\n\r\nribbon:\r\n ReadTimeout: 6000 # 请求处理的超时时间\r\n ConnectTimeout: 3000 # 请求连接的超时时间\r\n MaxAutoRetries: 1 # 重试策略先尝试访问首选实例一次,失败后才会更换实例访问\r\n MaxAutoRetriesNextServer: 1 # 更换实例访问的次数:通过参数设置为2, 所以会尝试更换2次实例进行重试\r\n OkToRetryOnAllOperations: true # 开启对请求进行行重试\r\n\r\n\r\nmanagement:\r\n health:\r\n ldap:\r\n enabled: false\r\n endpoints:\r\n web:\r\n exposure:\r\n include: \'health\'\r\n endpoint:\r\n health:\r\n show-details: always', '9e77325d3793a367542452cb4aa3610e', '2022-08-17 17:44:16', '2022-08-17 17:44:17', 'nacos', '127.0.0.1', 'U', 'test'); INSERT INTO `his_config_info` VALUES (0, 16, 'zyjblogs-rbac-test.yml', 'public', '', 'server:\r\n port: 9039\r\nspring:\r\n devtools:\r\n add-properties: true\r\n application:\r\n name: zyjblogs-rbac\r\n datasource:\r\n driver-class-name: com.mysql.cj.jdbc.Driver\r\n url: jdbc:mysql://127.0.0.1:3306/zyjblogs_rbac?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&autoReconnect=true&failOverReadOnly=false&allowMultiQueries=true&serverTimezone=GMT%2B8\r\n username: root\r\n password: 123456\r\nmybatis-plus:\r\n mapper-locations: classpath:mapper/**/*.xml\r\n global-config:\r\n db-config:\r\n #主键策略:assign_id(雪花算法)、assign_uuid(去下划线的UUID)\r\n id-type: assign_id\r\n configuration:\r\n # 是否开启自动驼峰命名规则映射:从数据库列名到Java属性驼峰命名的类似映射\r\n map-underscore-to-camel-case: true\r\n # 如果查询结果中包含空值的列,则 MyBatis 在映射的时候,不会映射这个字段\r\n call-setters-on-nulls: false\r\n # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用\r\n # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl\r\n log-impl: org.apache.ibatis.logging.stdout.StdOutImpl\r\nfeign:\r\n sentinel:\r\n enabled: true\r\n\r\nribbon:\r\n ReadTimeout: 6000 # 请求处理的超时时间\r\n ConnectTimeout: 3000 # 请求连接的超时时间\r\n MaxAutoRetries: 1 # 重试策略先尝试访问首选实例一次,失败后才会更换实例访问\r\n MaxAutoRetriesNextServer: 1 # 更换实例访问的次数:通过参数设置为2, 所以会尝试更换2次实例进行重试\r\n OkToRetryOnAllOperations: true # 开启对请求进行行重试\r\n\r\n\r\nmanagement:\r\n health:\r\n ldap:\r\n enabled: false\r\n endpoints:\r\n web:\r\n exposure:\r\n include: \'health\'\r\n endpoint:\r\n health:\r\n show-details: always', 'bfd132739c919b446e0256345adad019', '2022-08-17 17:48:37', '2022-08-17 17:48:38', 'nacos', '127.0.0.1', 'I', 'test'); INSERT INTO `his_config_info` VALUES (9, 17, 'zyjblogs-oauth-test.yml', 'public', '', 'server:\n port: 9029\nspring:\n devtools:\n add-properties: true\n application:\n name: zyjblogs-oauth\n datasource:\n driver-class-name: com.mysql.cj.jdbc.Driver\n url: jdbc:mysql://127.0.0.1:3306/zyjblogs_rbac?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&autoReconnect=true&failOverReadOnly=false&allowMultiQueries=true&serverTimezone=GMT%2B8\n username: root\n password: 123456\nmybatis-plus:\n mapper-locations: classpath:mapper/**/*.xml\n global-config:\n db-config:\n #主键策略:assign_id(雪花算法)、assign_uuid(去下划线的UUID)\n id-type: assign_id\n configuration:\n # 是否开启自动驼峰命名规则映射:从数据库列名到Java属性驼峰命名的类似映射\n map-underscore-to-camel-case: true\n # 如果查询结果中包含空值的列,则 MyBatis 在映射的时候,不会映射这个字段\n call-setters-on-nulls: false\n # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用\n # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl\n log-impl: org.apache.ibatis.logging.stdout.StdOutImpl\nfeign:\n sentinel:\n enabled: true\n\nribbon:\n ReadTimeout: 6000 # 请求处理的超时时间\n ConnectTimeout: 3000 # 请求连接的超时时间\n MaxAutoRetries: 1 # 重试策略先尝试访问首选实例一次,失败后才会更换实例访问\n MaxAutoRetriesNextServer: 1 # 更换实例访问的次数:通过参数设置为2, 所以会尝试更换2次实例进行重试\n OkToRetryOnAllOperations: true # 开启对请求进行行重试\n\n\nmanagement:\n health:\n ldap:\n enabled: false\n endpoints:\n web:\n exposure:\n include: \'health\'\n endpoint:\n health:\n show-details: always', '1927b9538ce0dec948d93fce91d46295', '2022-08-17 17:57:11', '2022-08-17 17:57:11', 'nacos', '127.0.0.1', 'U', 'test'); +INSERT INTO `his_config_info` VALUES (0, 18, 'zyjblogs-gateway-test.yml', 'public', '', '#通常情况下,只需要改config配置\r\nhatech:\r\n config:\r\n server-port: 10010\r\n whilelist:\r\n allowPaths:\r\n - /v2/api-docs/**\r\n - /oauth/token\r\n - /user/login\r\n - /license/import\r\n - /role/dev/all\r\n - /home/page/cluster/config\r\n - /application/backup/edit/**\r\n - /home/page/cluster/config/info\r\n - /word/socket\r\n - /application/backup/call/hook/*\r\n - /quota/pageAll\r\n - /quota/pageById\r\n - /alertManager/**\r\n - /user/list/user-group-tree\r\n - /oauth/authorize\r\n - /oauth/getToken\r\n - /oauth/getUserInfo\r\n\r\nserver:\r\n port: ${hatech.config.server-port}\r\nspring:\r\n main:\r\n allow-bean-definition-overriding: true\r\n servlet:\r\n multipart:\r\n enabled: true\r\n max-file-size: 20MB\r\n max-request-size: 100MB\r\n redis:\r\n host: ${hatech.global.redis.host}\r\n port: ${hatech.global.redis.port}\r\n password: ${hatech.global.redis.password}\r\n timeout: 10000 #连接超时时间(毫秒)\r\n lettuce:\r\n pool:\r\n max-active: 8 # 连接池最大连接数\r\n max-wait: -1ms # 连接池最大阻塞等待时间(使用负值表示没有限制)\r\n min-idle: 0 # 连接池中的最小空闲连接\r\n max-idle: 8 # 连接池中的最大空闲连接\r\n sentinel:\r\n master: ${hatech.global.redis.sentinel.master}\r\n nodes: ${hatech.global.redis.sentinel.nodes}\r\n password: ${hatech.global.redis.sentinel.password}\r\n cloud:\r\n alibaba:\r\n seata:\r\n # 配置分布式事务的分组名称\r\n tx-service-group: hatech-seata-tx-service-group\r\n sentinel:\r\n datasource:\r\n ds1:\r\n nacos:\r\n username: ${spring.cloud.nacos.config.username}\r\n password: ${spring.cloud.nacos.config.password}\r\n namespace: ${spring.cloud.nacos.config.namespace}\r\n server-addr: ${spring.cloud.nacos.config.server-addr}\r\n group-id: SENTINEL_GROUP\r\n rule-type: flow\r\n data-id: ${spring.application.name}-sentinel\r\n data-type: json\r\n transport:\r\n port: ${hatech.global.sentinel.transport.port}\r\n dashboard: ${hatech.global.sentinel.transport.dashboard.host}:${hatech.global.sentinel.transport.dashboard.port}\r\n gateway:\r\n httpclient:\r\n websocket:\r\n #websocket最大传输长度,单位(b),默认为64kb,最大为Integer.MAX_VALUE\r\n max-frame-payload-length: 0x7fffffff\r\n discovery:\r\n locator:\r\n enabled: false\r\n routes:\r\n - id: zyjblogs-oauth\r\n uri: lb://zyjblogs-oauth\r\n predicates:\r\n - Path=/api/oauth/**\r\n filters:\r\n - StripPrefix=2\r\n - id: zyjblogs-rbac\r\n uri: lb://zyjblogs-rbac\r\n predicates:\r\n - Path=/api/rbac/**\r\n filters:\r\n - StripPrefix=2\r\n\r\nfeign:\r\n sentinel:\r\n enabled: true\r\n\r\nribbon:\r\n ReadTimeout: 90000 # 请求处理的超时时间\r\n ConnectTimeout: 3000 # 请求连接的超时时间\r\n MaxAutoRetries: 1 # 重试策略先尝试访问首选实例一次,失败后才会更换实例访问\r\n MaxAutoRetriesNextServer: 2 # 更换实例访问的次数:通过参数设置为2, 所以会尝试更换2次实例进行重试\r\n OkToRetryOnAllOperations: true # 开启对请求进行行重试\r\n\r\nmanagement:\r\n endpoints:\r\n web:\r\n exposure:\r\n include: \'health\'\r\n endpoint:\r\n health:\r\n show-details: always\r\n', '8e07052c2a26fcbc9f96a56babbb3daa', '2022-08-18 09:26:43', '2022-08-18 09:26:44', NULL, '127.0.0.1', 'I', 'test'); +INSERT INTO `his_config_info` VALUES (14, 19, 'zyjblogs-gateway-test.yml', 'public', '', '#通常情况下,只需要改config配置\r\nhatech:\r\n config:\r\n server-port: 10010\r\n whilelist:\r\n allowPaths:\r\n - /v2/api-docs/**\r\n - /oauth/token\r\n - /user/login\r\n - /license/import\r\n - /role/dev/all\r\n - /home/page/cluster/config\r\n - /application/backup/edit/**\r\n - /home/page/cluster/config/info\r\n - /word/socket\r\n - /application/backup/call/hook/*\r\n - /quota/pageAll\r\n - /quota/pageById\r\n - /alertManager/**\r\n - /user/list/user-group-tree\r\n - /oauth/authorize\r\n - /oauth/getToken\r\n - /oauth/getUserInfo\r\n\r\nserver:\r\n port: ${hatech.config.server-port}\r\nspring:\r\n main:\r\n allow-bean-definition-overriding: true\r\n servlet:\r\n multipart:\r\n enabled: true\r\n max-file-size: 20MB\r\n max-request-size: 100MB\r\n redis:\r\n host: ${hatech.global.redis.host}\r\n port: ${hatech.global.redis.port}\r\n password: ${hatech.global.redis.password}\r\n timeout: 10000 #连接超时时间(毫秒)\r\n lettuce:\r\n pool:\r\n max-active: 8 # 连接池最大连接数\r\n max-wait: -1ms # 连接池最大阻塞等待时间(使用负值表示没有限制)\r\n min-idle: 0 # 连接池中的最小空闲连接\r\n max-idle: 8 # 连接池中的最大空闲连接\r\n sentinel:\r\n master: ${hatech.global.redis.sentinel.master}\r\n nodes: ${hatech.global.redis.sentinel.nodes}\r\n password: ${hatech.global.redis.sentinel.password}\r\n cloud:\r\n alibaba:\r\n seata:\r\n # 配置分布式事务的分组名称\r\n tx-service-group: hatech-seata-tx-service-group\r\n sentinel:\r\n datasource:\r\n ds1:\r\n nacos:\r\n username: ${spring.cloud.nacos.config.username}\r\n password: ${spring.cloud.nacos.config.password}\r\n namespace: ${spring.cloud.nacos.config.namespace}\r\n server-addr: ${spring.cloud.nacos.config.server-addr}\r\n group-id: SENTINEL_GROUP\r\n rule-type: flow\r\n data-id: ${spring.application.name}-sentinel\r\n data-type: json\r\n transport:\r\n port: ${hatech.global.sentinel.transport.port}\r\n dashboard: ${hatech.global.sentinel.transport.dashboard.host}:${hatech.global.sentinel.transport.dashboard.port}\r\n gateway:\r\n httpclient:\r\n websocket:\r\n #websocket最大传输长度,单位(b),默认为64kb,最大为Integer.MAX_VALUE\r\n max-frame-payload-length: 0x7fffffff\r\n discovery:\r\n locator:\r\n enabled: false\r\n routes:\r\n - id: zyjblogs-oauth\r\n uri: lb://zyjblogs-oauth\r\n predicates:\r\n - Path=/api/oauth/**\r\n filters:\r\n - StripPrefix=2\r\n - id: zyjblogs-rbac\r\n uri: lb://zyjblogs-rbac\r\n predicates:\r\n - Path=/api/rbac/**\r\n filters:\r\n - StripPrefix=2\r\n\r\nfeign:\r\n sentinel:\r\n enabled: true\r\n\r\nribbon:\r\n ReadTimeout: 90000 # 请求处理的超时时间\r\n ConnectTimeout: 3000 # 请求连接的超时时间\r\n MaxAutoRetries: 1 # 重试策略先尝试访问首选实例一次,失败后才会更换实例访问\r\n MaxAutoRetriesNextServer: 2 # 更换实例访问的次数:通过参数设置为2, 所以会尝试更换2次实例进行重试\r\n OkToRetryOnAllOperations: true # 开启对请求进行行重试\r\n\r\nmanagement:\r\n endpoints:\r\n web:\r\n exposure:\r\n include: \'health\'\r\n endpoint:\r\n health:\r\n show-details: always\r\n', '8e07052c2a26fcbc9f96a56babbb3daa', '2022-08-18 09:32:11', '2022-08-18 09:32:11', 'nacos', '127.0.0.1', 'U', 'test'); +INSERT INTO `his_config_info` VALUES (10, 20, 'zyjblogs-global-test.yml', 'global', '', 'none', '334c4a4c42fdb79d7ebc3e73b517e6f8', '2022-08-18 09:33:28', '2022-08-18 09:33:28', 'nacos', '127.0.0.1', 'U', 'test'); +INSERT INTO `his_config_info` VALUES (14, 21, 'zyjblogs-gateway-test.yml', 'public', '', '#通常情况下,只需要改config配置\nzyjblogs:\n config:\n server-port: 9019\n whilelist:\n allowPaths:\n - /v2/api-docs/**\n - /oauth/token\n - /oauth/check_token\n - /user/login\n\nserver:\n port: ${zyjblogs.config.server-port}\nspring:\n main:\n allow-bean-definition-overriding: true\n servlet:\n multipart:\n enabled: true\n max-file-size: 20MB\n max-request-size: 100MB\n redis:\n host: ${hatech.global.redis.host}\n port: ${hatech.global.redis.port}\n password: ${hatech.global.redis.password}\n timeout: 10000 #连接超时时间(毫秒)\n lettuce:\n pool:\n max-active: 8 # 连接池最大连接数\n max-wait: -1ms # 连接池最大阻塞等待时间(使用负值表示没有限制)\n min-idle: 0 # 连接池中的最小空闲连接\n max-idle: 8 # 连接池中的最大空闲连接\n\n cloud:\n sentinel:\n datasource:\n ds1:\n nacos:\n username: ${spring.cloud.nacos.config.username}\n password: ${spring.cloud.nacos.config.password}\n namespace: ${spring.cloud.nacos.config.namespace}\n server-addr: ${spring.cloud.nacos.config.server-addr}\n group-id: SENTINEL_GROUP\n rule-type: flow\n data-id: ${spring.application.name}-sentinel\n data-type: json\n transport:\n port: ${zyjblogs.global.sentinel.transport.port}\n dashboard: ${zyjblogs.global.sentinel.transport.dashboard.host}:${hatech.global.sentinel.transport.dashboard.port}\n gateway:\n httpclient:\n websocket:\n #websocket最大传输长度,单位(b),默认为64kb,最大为Integer.MAX_VALUE\n max-frame-payload-length: 0x7fffffff\n discovery:\n locator:\n enabled: false\n routes:\n - id: zyjblogs-oauth\n uri: lb://zyjblogs-oauth\n predicates:\n - Path=/api/oauth/**\n filters:\n - StripPrefix=2\n - id: zyjblogs-rbac\n uri: lb://zyjblogs-rbac\n predicates:\n - Path=/api/rbac/**\n filters:\n - StripPrefix=2\n\nfeign:\n sentinel:\n enabled: true\n\nribbon:\n ReadTimeout: 90000 # 请求处理的超时时间\n ConnectTimeout: 3000 # 请求连接的超时时间\n MaxAutoRetries: 1 # 重试策略先尝试访问首选实例一次,失败后才会更换实例访问\n MaxAutoRetriesNextServer: 2 # 更换实例访问的次数:通过参数设置为2, 所以会尝试更换2次实例进行重试\n OkToRetryOnAllOperations: true # 开启对请求进行行重试\n\nmanagement:\n endpoints:\n web:\n exposure:\n include: \'health\'\n endpoint:\n health:\n show-details: always\n', 'ccf648c4bc8ff739feca11d0e2fa1f3b', '2022-08-18 09:43:28', '2022-08-18 09:43:29', 'nacos', '127.0.0.1', 'U', 'test'); +INSERT INTO `his_config_info` VALUES (0, 22, 'zyjblogs-gateway-sentinel', 'DEFAULT_GROUP', '', '[\r\n]', 'fdaf133263369980df600fd06ce738ec', '2022-08-18 09:45:59', '2022-08-18 09:45:59', NULL, '127.0.0.1', 'I', 'test'); +INSERT INTO `his_config_info` VALUES (14, 23, 'zyjblogs-gateway-test.yml', 'public', '', '#通常情况下,只需要改config配置\nzyjblogs:\n config:\n server-port: 9019\n whilelist:\n allowPaths:\n - /v2/api-docs/**\n - /oauth/token\n - /oauth/check_token\n - /user/login\n\nserver:\n port: ${zyjblogs.config.server-port}\nspring:\n main:\n allow-bean-definition-overriding: true\n servlet:\n multipart:\n enabled: true\n max-file-size: 20MB\n max-request-size: 100MB\n redis:\n host: ${zyjbblogs.global.redis.host}\n port: ${zyjbblogs.global.redis.port}\n password: ${zyjbblogs.global.redis.password}\n timeout: 10000 #连接超时时间(毫秒)\n lettuce:\n pool:\n max-active: 8 # 连接池最大连接数\n max-wait: -1ms # 连接池最大阻塞等待时间(使用负值表示没有限制)\n min-idle: 0 # 连接池中的最小空闲连接\n max-idle: 8 # 连接池中的最大空闲连接\n\n cloud:\n sentinel:\n datasource:\n ds1:\n nacos:\n username: ${spring.cloud.nacos.config.username}\n password: ${spring.cloud.nacos.config.password}\n namespace: ${spring.cloud.nacos.config.namespace}\n server-addr: ${spring.cloud.nacos.config.server-addr}\n group-id: SENTINEL_GROUP\n rule-type: flow\n data-id: ${spring.application.name}-sentinel\n data-type: json\n transport:\n port: ${zyjblogs.global.sentinel.transport.port}\n dashboard: ${zyjblogs.global.sentinel.transport.dashboard.host}:${hatech.global.sentinel.transport.dashboard.port}\n gateway:\n httpclient:\n websocket:\n #websocket最大传输长度,单位(b),默认为64kb,最大为Integer.MAX_VALUE\n max-frame-payload-length: 0x7fffffff\n discovery:\n locator:\n enabled: false\n routes:\n - id: zyjblogs-oauth\n uri: lb://zyjblogs-oauth\n predicates:\n - Path=/api/oauth/**\n filters:\n - StripPrefix=2\n - id: zyjblogs-rbac\n uri: lb://zyjblogs-rbac\n predicates:\n - Path=/api/rbac/**\n filters:\n - StripPrefix=2\n\nfeign:\n sentinel:\n enabled: true\n\nribbon:\n ReadTimeout: 90000 # 请求处理的超时时间\n ConnectTimeout: 3000 # 请求连接的超时时间\n MaxAutoRetries: 1 # 重试策略先尝试访问首选实例一次,失败后才会更换实例访问\n MaxAutoRetriesNextServer: 2 # 更换实例访问的次数:通过参数设置为2, 所以会尝试更换2次实例进行重试\n OkToRetryOnAllOperations: true # 开启对请求进行行重试\n\nmanagement:\n endpoints:\n web:\n exposure:\n include: \'health\'\n endpoint:\n health:\n show-details: always\n', 'a2e43ef4a61c33f9c5f2493c8548ae4e', '2022-08-18 09:49:15', '2022-08-18 09:49:15', 'nacos', '127.0.0.1', 'U', 'test'); +INSERT INTO `his_config_info` VALUES (14, 24, 'zyjblogs-gateway-test.yml', 'public', '', '#通常情况下,只需要改config配置\nzyjblogs:\n config:\n server-port: 9019\n whilelist:\n allowPaths:\n - /v2/api-docs/**\n - /oauth/token\n - /oauth/check_token\n - /user/login\n\nserver:\n port: ${zyjblogs.config.server-port}\nspring:\n main:\n allow-bean-definition-overriding: true\n servlet:\n multipart:\n enabled: true\n max-file-size: 20MB\n max-request-size: 100MB\n redis:\n host: ${zyjblogs.global.redis.host}\n port: ${zyjblogs.global.redis.port}\n password: ${zyjblogs.global.redis.password}\n timeout: 10000 #连接超时时间(毫秒)\n lettuce:\n pool:\n max-active: 8 # 连接池最大连接数\n max-wait: -1ms # 连接池最大阻塞等待时间(使用负值表示没有限制)\n min-idle: 0 # 连接池中的最小空闲连接\n max-idle: 8 # 连接池中的最大空闲连接\n\n cloud:\n sentinel:\n datasource:\n ds1:\n nacos:\n username: ${spring.cloud.nacos.config.username}\n password: ${spring.cloud.nacos.config.password}\n namespace: ${spring.cloud.nacos.config.namespace}\n server-addr: ${spring.cloud.nacos.config.server-addr}\n group-id: SENTINEL_GROUP\n rule-type: flow\n data-id: ${spring.application.name}-sentinel\n data-type: json\n transport:\n port: ${zyjblogs.global.sentinel.transport.port}\n dashboard: ${zyjblogs.global.sentinel.transport.dashboard.host}:${hatech.global.sentinel.transport.dashboard.port}\n gateway:\n httpclient:\n websocket:\n #websocket最大传输长度,单位(b),默认为64kb,最大为Integer.MAX_VALUE\n max-frame-payload-length: 0x7fffffff\n discovery:\n locator:\n enabled: false\n routes:\n - id: zyjblogs-oauth\n uri: lb://zyjblogs-oauth\n predicates:\n - Path=/api/oauth/**\n filters:\n - StripPrefix=2\n - id: zyjblogs-rbac\n uri: lb://zyjblogs-rbac\n predicates:\n - Path=/api/rbac/**\n filters:\n - StripPrefix=2\n\nfeign:\n sentinel:\n enabled: true\n\nribbon:\n ReadTimeout: 90000 # 请求处理的超时时间\n ConnectTimeout: 3000 # 请求连接的超时时间\n MaxAutoRetries: 1 # 重试策略先尝试访问首选实例一次,失败后才会更换实例访问\n MaxAutoRetriesNextServer: 2 # 更换实例访问的次数:通过参数设置为2, 所以会尝试更换2次实例进行重试\n OkToRetryOnAllOperations: true # 开启对请求进行行重试\n\nmanagement:\n endpoints:\n web:\n exposure:\n include: \'health\'\n endpoint:\n health:\n show-details: always\n', 'e4023728583537e3de832f65f264503a', '2022-08-18 10:14:00', '2022-08-18 10:14:00', 'nacos', '127.0.0.1', 'U', 'test'); +INSERT INTO `his_config_info` VALUES (14, 25, 'zyjblogs-gateway-test.yml', 'public', '', '#通常情况下,只需要改config配置\nzyjblogs:\n config:\n server-port: 9019\n whilelist:\n allowPaths:\n - /v2/api-docs/**\n - /oauth/token\n - /oauth/check_token\n - /user/login\n\nserver:\n port: ${zyjblogs.config.server-port}\nspring:\n main:\n allow-bean-definition-overriding: true\n servlet:\n multipart:\n enabled: true\n max-file-size: 20MB\n max-request-size: 100MB\n redis:\n host: ${zyjblogs.global.redis.host}\n port: ${zyjblogs.global.redis.port}\n password: ${zyjblogs.global.redis.password}\n timeout: 10000 #连接超时时间(毫秒)\n lettuce:\n pool:\n max-active: 8 # 连接池最大连接数\n max-wait: -1ms # 连接池最大阻塞等待时间(使用负值表示没有限制)\n min-idle: 0 # 连接池中的最小空闲连接\n max-idle: 8 # 连接池中的最大空闲连接\n\n cloud:\n sentinel:\n datasource:\n ds1:\n nacos:\n username: ${spring.cloud.nacos.config.username}\n password: ${spring.cloud.nacos.config.password}\n namespace: ${spring.cloud.nacos.config.namespace}\n server-addr: ${spring.cloud.nacos.config.server-addr}\n group-id: SENTINEL_GROUP\n rule-type: flow\n data-id: ${spring.application.name}-sentinel\n data-type: json\n transport:\n port: ${zyjblogs.global.sentinel.transport.port}\n dashboard: ${zyjblogs.global.sentinel.transport.dashboard.host}:${hatech.global.sentinel.transport.dashboard.port}\n gateway:\n httpclient:\n websocket:\n #websocket最大传输长度,单位(b),默认为64kb,最大为Integer.MAX_VALUE\n max-frame-payload-length: 0x7fffffff\n discovery:\n locator:\n enabled: true\n routes:\n - id: zyjblogs-oauth\n uri: lb://zyjblogs-oauth\n predicates:\n - Path=/api/oauth/**\n filters:\n - StripPrefix=2\n - id: zyjblogs-rbac\n uri: lb://zyjblogs-rbac\n predicates:\n - Path=/api/rbac/**\n filters:\n - StripPrefix=2\n\nfeign:\n sentinel:\n enabled: true\n\nribbon:\n ReadTimeout: 90000 # 请求处理的超时时间\n ConnectTimeout: 3000 # 请求连接的超时时间\n MaxAutoRetries: 1 # 重试策略先尝试访问首选实例一次,失败后才会更换实例访问\n MaxAutoRetriesNextServer: 2 # 更换实例访问的次数:通过参数设置为2, 所以会尝试更换2次实例进行重试\n OkToRetryOnAllOperations: true # 开启对请求进行行重试\n\nmanagement:\n endpoints:\n web:\n exposure:\n include: \'health\'\n endpoint:\n health:\n show-details: always\n', 'de451d96d9134835784db63cfc88734c', '2022-08-18 10:22:04', '2022-08-18 10:22:05', 'nacos', '127.0.0.1', 'U', 'test'); -- ---------------------------- -- Table structure for permissions diff --git a/db/zyjblogs_rbac.sql b/db/zyjblogs_rbac.sql index 5b534b6..a7c0a28 100644 --- a/db/zyjblogs_rbac.sql +++ b/db/zyjblogs_rbac.sql @@ -11,104 +11,128 @@ Target Server Version : 50732 File Encoding : 65001 - Date: 17/08/2022 18:14:29 + Date: 18/08/2022 18:47:42 */ SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; --- --- Oauth sql -- MYSQL --- -Drop table if exists oauth_client_details; -create table oauth_client_details ( - client_id VARCHAR(255) PRIMARY KEY, - resource_ids VARCHAR(255), - client_secret VARCHAR(255), - scope VARCHAR(255), - authorized_grant_types VARCHAR(255), - web_server_redirect_uri VARCHAR(255), - authorities VARCHAR(255), - access_token_validity INTEGER, - refresh_token_validity INTEGER, - additional_information TEXT, - create_time timestamp default now(), - archived tinyint(1) default '0', - trusted tinyint(1) default '0', - autoapprove VARCHAR (255) default 'false' -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- ---------------------------- +-- Table structure for oauth_access_token +-- ---------------------------- +DROP TABLE IF EXISTS `oauth_access_token`; +CREATE TABLE `oauth_access_token` ( + `create_time` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0), + `token_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + `token` blob NULL, + `authentication_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + `user_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + `client_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + `authentication` blob NULL, + `refresh_token` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + UNIQUE INDEX `authentication_id`(`authentication_id`) USING BTREE, + INDEX `token_id_index`(`token_id`) USING BTREE, + INDEX `authentication_id_index`(`authentication_id`) USING BTREE, + INDEX `user_name_index`(`user_name`) USING BTREE, + INDEX `client_id_index`(`client_id`) USING BTREE, + INDEX `refresh_token_index`(`refresh_token`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; +-- ---------------------------- +-- Records of oauth_access_token +-- ---------------------------- -Drop table if exists oauth_access_token; -create table oauth_access_token ( - create_time timestamp default now(), - token_id VARCHAR(255), - token BLOB, - authentication_id VARCHAR(255) UNIQUE, - user_name VARCHAR(255), - client_id VARCHAR(255), - authentication BLOB, - refresh_token VARCHAR(255) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- ---------------------------- +-- Table structure for oauth_client_details +-- ---------------------------- +DROP TABLE IF EXISTS `oauth_client_details`; +CREATE TABLE `oauth_client_details` ( + `client_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, + `resource_ids` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + `client_secret` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + `scope` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + `authorized_grant_types` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + `web_server_redirect_uri` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + `authorities` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + `access_token_validity` int(11) NULL DEFAULT NULL, + `refresh_token_validity` int(11) NULL DEFAULT NULL, + `additional_information` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL, + `create_time` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0), + `archived` tinyint(1) NULL DEFAULT 0, + `trusted` tinyint(1) NULL DEFAULT 0, + `autoapprove` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT 'false', + PRIMARY KEY (`client_id`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; +-- ---------------------------- +-- Records of oauth_client_details +-- ---------------------------- +INSERT INTO `oauth_client_details` VALUES ('zyjblogs-gateway', 'zyjblogs-gateway', '$2a$10$Wk2w4OX5DpFgG3rBuhPnnulCSOIuU3TZhpWjaOq39LZnL.p0LJila', 'all', 'authorization_code,password,client_credentials,implicit,refresh_token', 'http://localhost:9019/', NULL, NULL, NULL, NULL, '2022-08-18 14:13:53', 0, 0, 'false'); +INSERT INTO `oauth_client_details` VALUES ('zyjblogs-oauth', 'zyjblogs-oauth', '$2a$10$Wk2w4OX5DpFgG3rBuhPnnulCSOIuU3TZhpWjaOq39LZnL.p0LJila', 'all', 'authorization_code,password,client_credentials,implicit,refresh_token', 'http://localhost:9019/', NULL, NULL, NULL, NULL, '2022-08-18 14:14:32', 0, 0, 'false'); +INSERT INTO `oauth_client_details` VALUES ('zyjblogs-rbac', 'zyjblogs-rbac', '$2a$10$Wk2w4OX5DpFgG3rBuhPnnulCSOIuU3TZhpWjaOq39LZnL.p0LJila', 'all', 'authorization_code,password,client_credentials,implicit,refresh_token', 'http://localhost:9029/', NULL, NULL, NULL, NULL, '2022-08-18 08:34:24', 0, 0, 'false'); -Drop table if exists oauth_refresh_token; -create table oauth_refresh_token ( - create_time timestamp default now(), - token_id VARCHAR(255), - token BLOB, - authentication BLOB -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- ---------------------------- +-- Table structure for oauth_code +-- ---------------------------- +DROP TABLE IF EXISTS `oauth_code`; +CREATE TABLE `oauth_code` ( + `create_time` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0), + `code` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + `authentication` blob NULL, + INDEX `code_index`(`code`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; +-- ---------------------------- +-- Records of oauth_code +-- ---------------------------- +INSERT INTO `oauth_code` VALUES ('2022-08-18 09:01:55', 'AeocBw', 0xACED0005737200416F72672E737072696E676672616D65776F726B2E73656375726974792E6F61757468322E70726F76696465722E4F417574683241757468656E7469636174696F6EBD400B02166252130200024C000D73746F7265645265717565737474003C4C6F72672F737072696E676672616D65776F726B2F73656375726974792F6F61757468322F70726F76696465722F4F4175746832526571756573743B4C00127573657241757468656E7469636174696F6E7400324C6F72672F737072696E676672616D65776F726B2F73656375726974792F636F72652F41757468656E7469636174696F6E3B787200476F72672E737072696E676672616D65776F726B2E73656375726974792E61757468656E7469636174696F6E2E416273747261637441757468656E7469636174696F6E546F6B656ED3AA287E6E47640E0200035A000D61757468656E746963617465644C000B617574686F7269746965737400164C6A6176612F7574696C2F436F6C6C656374696F6E3B4C000764657461696C737400124C6A6176612F6C616E672F4F626A6563743B787000737200266A6176612E7574696C2E436F6C6C656374696F6E7324556E6D6F6469666961626C654C697374FC0F2531B5EC8E100200014C00046C6973747400104C6A6176612F7574696C2F4C6973743B7872002C6A6176612E7574696C2E436F6C6C656374696F6E7324556E6D6F6469666961626C65436F6C6C656374696F6E19420080CB5EF71E0200014C00016371007E00047870737200136A6176612E7574696C2E41727261794C6973747881D21D99C7619D03000149000473697A657870000000007704000000007871007E000C707372003A6F72672E737072696E676672616D65776F726B2E73656375726974792E6F61757468322E70726F76696465722E4F41757468325265717565737400000000000000010200075A0008617070726F7665644C000B617574686F72697469657371007E00044C000A657874656E73696F6E7374000F4C6A6176612F7574696C2F4D61703B4C000B72656469726563745572697400124C6A6176612F6C616E672F537472696E673B4C00077265667265736874003B4C6F72672F737072696E676672616D65776F726B2F73656375726974792F6F61757468322F70726F76696465722F546F6B656E526571756573743B4C000B7265736F7572636549647374000F4C6A6176612F7574696C2F5365743B4C000D726573706F6E7365547970657371007E0011787200386F72672E737072696E676672616D65776F726B2E73656375726974792E6F61757468322E70726F76696465722E426173655265717565737436287A3EA37169BD0200034C0008636C69656E74496471007E000F4C001172657175657374506172616D657465727371007E000E4C000573636F706571007E0011787074000D7A796A626C6F67732D72626163737200256A6176612E7574696C2E436F6C6C656374696F6E7324556E6D6F6469666961626C654D6170F1A5A8FE74F507420200014C00016D71007E000E7870737200116A6176612E7574696C2E486173684D61700507DAC1C31660D103000246000A6C6F6164466163746F724900097468726573686F6C6478703F400000000000067708000000080000000474000D726573706F6E73655F74797065740004636F6465740009636C69656E745F696471007E001474000C72656469726563745F75726C74001568747470733A2F2F7777772E62616964752E636F6D74000573636F7065740003616C6C78737200256A6176612E7574696C2E436F6C6C656374696F6E7324556E6D6F6469666961626C65536574801D92D18F9B80550200007871007E0009737200176A6176612E7574696C2E4C696E6B656448617368536574D86CD75A95DD2A1E020000787200116A6176612E7574696C2E48617368536574BA44859596B8B7340300007870770C000000103F4000000000000171007E001F78017371007E0023770C000000103F40000000000000787371007E00173F400000000000007708000000100000000078740016687474703A2F2F6C6F63616C686F73743A393032392F707371007E0023770C000000103F4000000000000174000D7A796A626C6F67732D72626163787371007E0023770C000000103F4000000000000171007E001A787372004F6F72672E737072696E676672616D65776F726B2E73656375726974792E61757468656E7469636174696F6E2E557365726E616D6550617373776F726441757468656E7469636174696F6E546F6B656E00000000000002120200024C000B63726564656E7469616C7371007E00054C00097072696E636970616C71007E00057871007E0003017372001F6A6176612E7574696C2E436F6C6C656374696F6E7324456D7074794C6973747AB817B43CA79EDE0200007870737200486F72672E737072696E676672616D65776F726B2E73656375726974792E7765622E61757468656E7469636174696F6E2E57656241757468656E7469636174696F6E44657461696C7300000000000002120200024C000D72656D6F74654164647265737371007E000F4C000973657373696F6E496471007E000F78707400093132372E302E302E3174002038373032444535373930443133444133363839453433354436434139444143367073720031636E2E7A796A626C6F67732E6F617574682E7365727665722E757365722E706F2E4F617574685573657244657461696C739ABCC249D9EA599302000E5A00116163636F756E744E6F6E457870697265645A00106163636F756E744E6F6E4C6F636B65645A001563726564656E7469616C734E6F6E457870697265645A0007656E61626C65644C000B617574686F72697469657371007E00044C000764656C657465647400134C6A6176612F6C616E672F496E74656765723B4C0005656D61696C71007E000F4C0002696471007E000F4C000C696E7669746555736572496471007E000F4C00046E616D6571007E000F4C000870617373776F726471007E000F4C000570686F6E6571007E00344C000673746174757371007E00344C0008757365726E616D6571007E000F78700101010170737200116A6176612E6C616E672E496E746567657212E2A0A4F781873802000149000576616C7565787200106A6176612E6C616E672E4E756D62657286AC951D0B94E08B02000078700000000070740001317074000561646D696E74003C2432612431302434446C66765A7271377A674B7A6B624B79672E47484F36794864476E6F7A6361663342354A53414330664E42346B3147684D6B36797071007E003874000561646D696E); -Drop table if exists oauth_code; -create table oauth_code ( - create_time timestamp default now(), - code VARCHAR(255), - authentication BLOB -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- ---------------------------- +-- Table structure for oauth_refresh_token +-- ---------------------------- +DROP TABLE IF EXISTS `oauth_refresh_token`; +CREATE TABLE `oauth_refresh_token` ( + `create_time` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0), + `token_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + `token` blob NULL, + `authentication` blob NULL, + INDEX `token_id_index`(`token_id`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; +-- ---------------------------- +-- Records of oauth_refresh_token +-- ---------------------------- - --- Add indexes -create index token_id_index on oauth_access_token (token_id); -create index authentication_id_index on oauth_access_token (authentication_id); -create index user_name_index on oauth_access_token (user_name); -create index client_id_index on oauth_access_token (client_id); -create index refresh_token_index on oauth_access_token (refresh_token); - -create index token_id_index on oauth_refresh_token (token_id); - -create index code_index on oauth_code (code); - - -INSERT INTO zyjblogs_rbac.oauth_client_details -(client_id, resource_ids, client_secret, `scope`, authorized_grant_types, web_server_redirect_uri, authorities, access_token_validity, refresh_token_validity, additional_information, autoapprove, trusted, archived) -VALUES('zyjblogs-rbac', 'zyjblogs-rbac', '$2a$10$Wk2w4OX5DpFgG3rBuhPnnulCSOIuU3TZhpWjaOq39LZnL.p0LJila', 'all', 'authorization_code,password,client_credentials,implicit,refresh_token', NULL, NULL, NULL, NULL, NULL, 'false', NULL, NULL); - --- zyjblogs_rbac.`user` definition +-- ---------------------------- +-- Table structure for user +-- ---------------------------- DROP TABLE IF EXISTS `user`; -CREATE TABLE `user` ( - `id` varchar(64) CHARACTER SET utf8mb3 COLLATE utf8_general_ci NOT NULL COMMENT '用户id', - `username` varchar(64) CHARACTER SET utf8mb3 COLLATE utf8_general_ci NOT NULL COMMENT '用户名', - `name` varchar(64) CHARACTER SET utf8mb3 COLLATE utf8_general_ci DEFAULT NULL COMMENT '昵称', - `age` int DEFAULT NULL COMMENT '用户年龄', - `avatar` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8_general_ci DEFAULT NULL COMMENT '头像', - `password` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8_general_ci DEFAULT NULL COMMENT '用户密码', - `phone` int DEFAULT NULL COMMENT '用户密码', - `email` varchar(64) CHARACTER SET utf8mb3 COLLATE utf8_general_ci DEFAULT NULL COMMENT '邮箱', - `invite_user_id` varchar(64) CHARACTER SET utf8mb3 COLLATE utf8_general_ci DEFAULT NULL COMMENT '邀请者id', - `status` int DEFAULT NULL COMMENT '用户状态 1启用 0注销', - `follow_num` int DEFAULT NULL COMMENT '关注数量', - `fans_num` int DEFAULT NULL COMMENT '粉丝数量', - `deleted` tinyint DEFAULT '0', - `description` varchar(600) CHARACTER SET utf8mb3 COLLATE utf8_general_ci DEFAULT NULL COMMENT '用户介绍', - `create_user_id` varchar(64) CHARACTER SET utf8mb3 COLLATE utf8_general_ci DEFAULT NULL COMMENT '创建用户id', - `create_time` datetime DEFAULT NULL COMMENT '创建时间', - `update_user_id` varchar(64) CHARACTER SET utf8mb3 COLLATE utf8_general_ci DEFAULT NULL COMMENT '更新用户id', - `update_time` datetime DEFAULT NULL COMMENT '更新时间', - PRIMARY KEY (`id`) USING BTREE, - UNIQUE KEY `username` (`username`) USING BTREE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC; +CREATE TABLE `user` ( + `id` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用户id', + `username` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用户名', + `name` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '昵称', + `age` int(11) NULL DEFAULT NULL COMMENT '用户年龄', + `avatar` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '头像', + `password` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用户密码', + `phone` int(11) NULL DEFAULT NULL COMMENT '用户密码', + `email` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '邮箱', + `invite_user_id` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '邀请者id', + `status` int(11) NULL DEFAULT NULL COMMENT '用户状态 1启用 0注销', + `follow_num` int(11) NULL DEFAULT NULL COMMENT '关注数量', + `fans_num` int(11) NULL DEFAULT NULL COMMENT '粉丝数量', + `deleted` tinyint(4) NULL DEFAULT 0, + `description` varchar(600) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用户介绍', + `create_user_id` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '创建用户id', + `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', + `update_user_id` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '更新用户id', + `update_time` datetime(0) NULL DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE, + UNIQUE INDEX `username`(`username`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC; + +-- ---------------------------- +-- Records of user +-- ---------------------------- +INSERT INTO `user` VALUES ('1', 'admin', 'admin', 1, NULL, '$2a$10$4DlfvZrq7zgKzkbKyg.GHO6yHdGnozcaf3B5JSAC0fNB4k1GhMk6y', NULL, NULL, NULL, 0, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL); SET FOREIGN_KEY_CHECKS = 1; diff --git a/pom.xml b/pom.xml index 7d2ddbf..e887f6a 100644 --- a/pom.xml +++ b/pom.xml @@ -17,16 +17,19 @@ zyjblogs-oauth zyjblogs-rbac zyjblogs-gateway + zyjblogs-common-spring-boot-starter + 1.0-SNAPSHOT 11 11 Hoxton.SR12 1.18.24 2.13.3 - 0.11.1 + 0.9.1 + 0.11.1 4.5.0 0.3.1 11.8 @@ -37,6 +40,23 @@ 8.0.21 2.2.6.RELEASE + 2.12.2 + + 1.5.4 + + 1.5.24 + 3.0.3 + + 2.2.11 + + 2.3.0 + + 1.18.24 + 3.12.0 + 4.4 + 2.11.0 + 1.1.0 + 2.13.3 @@ -74,17 +94,22 @@ io.jsonwebtoken jjwt-api - ${jjwt.version} + ${jwt.version} io.jsonwebtoken jjwt-impl + ${jwt.version} + + + io.jsonwebtoken + jjwt ${jjwt.version} io.jsonwebtoken jjwt-jackson - ${jjwt.version} + ${jwt.version} com.aliyun @@ -106,6 +131,11 @@ nacos-client ${nacos-client.version} + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${jackson-datatype-jsr310.version} + com.alibaba @@ -122,7 +152,56 @@ commons-pool2 2.7.0 - + + com.alibaba + transmittable-thread-local + ${com.alibaba.transmittable.version} + + + ma.glasnost.orika + orika-core + ${orika-core.version} + + + io.swagger + swagger-annotations + ${swagger-annotations.verion} + + + com.github.xiaoymin + knife4j-spring-boot-starter + ${knife4j-spring-boot-starter.version} + + + com.alibaba + easyexcel + ${easyexcel.version} + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + org.apache.commons + commons-collections4 + ${commons-collections4.version} + + + commons-io + commons-io + ${commons-io.version} + + + org.apache.commons + commons-crypto + ${commons-crypto.version} + + + ma.glasnost.orika + orika-core + ${orika-core.version} + @@ -130,6 +209,7 @@ + @@ -137,10 +217,10 @@ - - org.springframework.boot - spring-boot-devtools - + + + + org.projectlombok lombok diff --git a/zyjblogs-common-spring-boot-starter/pom.xml b/zyjblogs-common-spring-boot-starter/pom.xml new file mode 100644 index 0000000..b5a819f --- /dev/null +++ b/zyjblogs-common-spring-boot-starter/pom.xml @@ -0,0 +1,78 @@ + + + + zyjblogs-parent + cn.zyjblogs + 1.0-SNAPSHOT + + 4.0.0 + cn.zyjblogs.starter + zyjblogs-common-spring-boot-starter + ${zyjblogs.version} + + 11 + 11 + + + + + org.springframework.boot + spring-boot-starter-validation + + + io.swagger + swagger-annotations + + + com.alibaba + transmittable-thread-local + + + + org.projectlombok + lombok + + + org.apache.commons + commons-lang3 + + + org.apache.commons + commons-collections4 + + + commons-io + commons-io + + + org.apache.commons + commons-crypto + + + ma.glasnost.orika + orika-core + + + com.alibaba + easyexcel + + + io.jsonwebtoken + jjwt + + + javax.xml.bind + jaxb-api + + + + + + org.apache.maven.plugins + maven-source-plugin + + + + \ No newline at end of file diff --git a/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/entity/constant/CommonConstant.java b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/entity/constant/CommonConstant.java new file mode 100644 index 0000000..40096f6 --- /dev/null +++ b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/entity/constant/CommonConstant.java @@ -0,0 +1,21 @@ +package cn.zyjblogs.common.entity.constant; + +public class CommonConstant { + public static final Integer IS_DELETED = 1; + public static final Integer NO_DELETED = 0 ; + public static final int YES = 1; + public static final int NO = 0; + public static final String NO_STR = "0"; + public static final int VERSION_START_VALUE = 1; + public static final String TENANT_ID = "tenant_id"; + public static final String EMPTY_STR = ""; + public static final int DEFAULT_PAGE = 1; + public static final int DEFAULT_LIMIT = 10; + public static final String DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss"; + public static final String TRACE_ID_HEADER = "x-traceId-header"; + public static final String LOG_TRACE_ID = "traceId"; + public static final String INIT_TENANT_FANOUT_EXCHANGE = "init.tenant.fanout.exchange"; + + private CommonConstant() { + } +} \ No newline at end of file diff --git a/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/entity/constant/HttpHeaderConstant.java b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/entity/constant/HttpHeaderConstant.java new file mode 100644 index 0000000..8a81afe --- /dev/null +++ b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/entity/constant/HttpHeaderConstant.java @@ -0,0 +1,14 @@ +package cn.zyjblogs.common.entity.constant; + +public class HttpHeaderConstant { + public static final String AUTHORIZATION = "Authorization"; + public static final String AUTHORIZATION_TYPE = "Bearer"; + public static final String LANGUAGE = "istorm-language"; + public static final String REQUEST_FROM_GATEWAY_KEY = "request-from-istorm-gateway"; + public static final String REQUEST_FROM_GATEWAY_VALUE = "yes"; + public static final String REQUEST_FROM_FEIGN_KEY = "request-from-istorm-feign"; + public static final String REQUEST_FROM_FEIGN_VALUE = "yes"; + + private HttpHeaderConstant() { + } +} diff --git a/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/entity/constant/LengthConstant.java b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/entity/constant/LengthConstant.java new file mode 100644 index 0000000..274fabb --- /dev/null +++ b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/entity/constant/LengthConstant.java @@ -0,0 +1,13 @@ +package cn.zyjblogs.common.entity.constant; + +public class LengthConstant { + public static final int ID_SIZE = 32; + public static final int MIN_SIZE = 1; + public static final int SHORT_SIZE = 16; + public static final int NORMAL_SIZE = 100; + public static final int LONG_SIZE = 500; + public static final int MOBILE_PHONE_SIZE = 11; + + public LengthConstant() { + } +} diff --git a/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/entity/constant/RegexConstant.java b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/entity/constant/RegexConstant.java new file mode 100644 index 0000000..0018462 --- /dev/null +++ b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/entity/constant/RegexConstant.java @@ -0,0 +1,11 @@ +package cn.zyjblogs.common.entity.constant; + +public class RegexConstant { + public static final String MOBILE_PHONE_PATTERN = "[\\s]?|^1[3456789]\\d{9}$"; + public static final String IS_ENABLED_PATTERN = "^(0|1)$"; + public static final String INVALID_CHAR = "[a-zA-Z0-9\\-_\\u4e00-\\u9fa5\\s]+"; + public static final String EMAIL = "^(\\w-*\\.*)+@(\\w-?)+(\\.\\w{2,})+$"; + + public RegexConstant() { + } +} diff --git a/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/entity/context/BaseContextHandler.java b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/entity/context/BaseContextHandler.java new file mode 100644 index 0000000..6f7b9cb --- /dev/null +++ b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/entity/context/BaseContextHandler.java @@ -0,0 +1,58 @@ +package cn.zyjblogs.common.entity.context; + +import cn.zyjblogs.common.entity.dto.ContextDto; +import cn.zyjblogs.common.utils.bean.BeanUtils; +import com.alibaba.ttl.TransmittableThreadLocal; + +import java.util.Locale; + +public class BaseContextHandler { + private static final ThreadLocal CONTEXT = new TransmittableThreadLocal() { + public ContextDto initialValue() { + return ContextDto.builder().build(); + } + }; + + public BaseContextHandler() { + } + + public static ContextDto get() { + return (ContextDto)CONTEXT.get(); + } + + public static void set(ContextDto ContextDto) { + CONTEXT.set(ContextDto); + } + + public static String getUserId() { + return ((ContextDto)CONTEXT.get()).getUserId(); + } + + public static String getUsername() { + return ((ContextDto)CONTEXT.get()).getUsername(); + } + + public static Integer getSource() { + return ((ContextDto)CONTEXT.get()).getSource(); + } + + public static String getTenantId() { + return ((ContextDto)CONTEXT.get()).getTenantId(); + } + + public static String getToken() { + return ((ContextDto)CONTEXT.get()).getToken(); + } + + public static ContextDto getDataReplication() { + return (ContextDto) BeanUtils.map((ContextDto)CONTEXT.get(), ContextDto.class); + } + + public static Locale getLanguage() { + return ((ContextDto)CONTEXT.get()).getLanguage(); + } + + public static void clear() { + CONTEXT.remove(); + } +} diff --git a/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/entity/dto/ContextDto.java b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/entity/dto/ContextDto.java new file mode 100644 index 0000000..43b0ffc --- /dev/null +++ b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/entity/dto/ContextDto.java @@ -0,0 +1,21 @@ +package cn.zyjblogs.common.entity.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Locale; +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class ContextDto { + private String tenantId; + private String userId; + private String username; + private Integer source; + private Integer isTenantCreator; + private String token; + private Locale language; +} \ No newline at end of file diff --git a/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/entity/response/ResponseObject.java b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/entity/response/ResponseObject.java new file mode 100644 index 0000000..fe99553 --- /dev/null +++ b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/entity/response/ResponseObject.java @@ -0,0 +1,50 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package cn.zyjblogs.common.entity.response; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@ApiModel( + description = "状态返回信息" +) +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class ResponseObject { + @ApiModelProperty( + value = "响应结果编码", + example = "200" + ) + private int code; + @ApiModelProperty( + value = "错误码", + example = "user_not_exists" + ) + private String errorCode; + @ApiModelProperty( + value = "响应结果信息", + example = "请求成功" + ) + private String msg; + @ApiModelProperty( + value = "统计列表总数(如果列表存在)", + example = "10" + ) + private long count; + @ApiModelProperty("响应结果数据") + private T data; + @ApiModelProperty( + value = "当前时间戳", + example = "1630051102895" + ) + private long timestamp; +} diff --git a/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/entity/response/ResponseResult.java b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/entity/response/ResponseResult.java new file mode 100644 index 0000000..4103e27 --- /dev/null +++ b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/entity/response/ResponseResult.java @@ -0,0 +1,44 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package cn.zyjblogs.common.entity.response; + +public class ResponseResult { + private static final int ZERO_DATA_TOTAL = 0; + private static final int ONE_DATA_TOTAL = 1; + + private ResponseResult() { + } + + public static ResponseObject success() { + return success(0L, (Object)null); + } + + public static ResponseObject success(T data) { + return success(1L, data); + } + + public static ResponseObject success(long total, T data) { + return ResponseObject.builder().code(ResponseStatus.OK.value()).msg(ResponseStatus.OK.getReasonPhrase()).count(total).data(data).timestamp(System.currentTimeMillis()).build(); + } + public static ResponseObject error(ResponseStatus responseCode, String errorMsg) { + return error(responseCode, responseCode.getReasonPhrase(), errorMsg, 0L, null); + } + public static ResponseObject error(ResponseStatus responseCode, String errorCode, String errorMsg) { + return error(responseCode, errorCode, errorMsg, 0L, null); + } + + public static ResponseObject error(ResponseStatus responseCode, String errorCode, String errorMsg, T data) { + return error(responseCode, errorCode, errorMsg, 1L, data); + } + + public static ResponseObject error(ResponseStatus responseCode, String errorCode, String errorMsg, long total, T data) { + if (responseCode.value() == ResponseStatus.OK.value()) { + throw new IllegalArgumentException("ResponseResult.error方法中的responseCode参数不能是ResponseCode.REQUEST_SUCCESS"); + } else { + return ResponseObject.builder().code(responseCode.value()).errorCode(errorCode).msg(errorMsg == null ? responseCode.getReasonPhrase() : errorMsg).count(total).data(data).timestamp(System.currentTimeMillis()).build(); + } + } +} diff --git a/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/entity/response/ResponseStatus.java b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/entity/response/ResponseStatus.java new file mode 100644 index 0000000..34cd899 --- /dev/null +++ b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/entity/response/ResponseStatus.java @@ -0,0 +1,204 @@ +package cn.zyjblogs.common.entity.response; + +public enum ResponseStatus { + CONTINUE(100, "Continue"), + SWITCHING_PROTOCOLS(101, "Switching Protocols"), + PROCESSING(102, "Processing"), + CHECKPOINT(103, "Checkpoint"), + OK(200, "OK"), + CREATED(201, "Created"), + ACCEPTED(202, "Accepted"), + NON_AUTHORITATIVE_INFORMATION(203, "Non-Authoritative Information"), + NO_CONTENT(204, "No Content"), + RESET_CONTENT(205, "Reset Content"), + PARTIAL_CONTENT(206, "Partial Content"), + MULTI_STATUS(207, "Multi-Status"), + ALREADY_REPORTED(208, "Already Reported"), + IM_USED(226, "IM Used"), + MULTIPLE_CHOICES(300, "Multiple Choices"), + MOVED_PERMANENTLY(301, "Moved Permanently"), + FOUND(302, "Found"), + /** @deprecated */ + @Deprecated + MOVED_TEMPORARILY(302, "Moved Temporarily"), + SEE_OTHER(303, "See Other"), + NOT_MODIFIED(304, "Not Modified"), + /** @deprecated */ + @Deprecated + USE_PROXY(305, "Use Proxy"), + TEMPORARY_REDIRECT(307, "Temporary Redirect"), + PERMANENT_REDIRECT(308, "Permanent Redirect"), + BAD_REQUEST(400, "Bad Request"), + UNAUTHORIZED(401, "Unauthorized"), + PAYMENT_REQUIRED(402, "Payment Required"), + FORBIDDEN(403, "Forbidden"), + NOT_FOUND(404, "Not Found"), + METHOD_NOT_ALLOWED(405, "Method Not Allowed"), + NOT_ACCEPTABLE(406, "Not Acceptable"), + PROXY_AUTHENTICATION_REQUIRED(407, "Proxy Authentication Required"), + REQUEST_TIMEOUT(408, "Request Timeout"), + CONFLICT(409, "Conflict"), + GONE(410, "Gone"), + LENGTH_REQUIRED(411, "Length Required"), + PRECONDITION_FAILED(412, "Precondition Failed"), + PAYLOAD_TOO_LARGE(413, "Payload Too Large"), + /** @deprecated */ + @Deprecated + REQUEST_ENTITY_TOO_LARGE(413, "Request Entity Too Large"), + URI_TOO_LONG(414, "URI Too Long"), + /** @deprecated */ + @Deprecated + REQUEST_URI_TOO_LONG(414, "Request-URI Too Long"), + UNSUPPORTED_MEDIA_TYPE(415, "Unsupported Media Type"), + REQUESTED_RANGE_NOT_SATISFIABLE(416, "Requested range not satisfiable"), + EXPECTATION_FAILED(417, "Expectation Failed"), + I_AM_A_TEAPOT(418, "I'm a teapot"), + /** @deprecated */ + @Deprecated + INSUFFICIENT_SPACE_ON_RESOURCE(419, "Insufficient Space On Resource"), + /** @deprecated */ + @Deprecated + METHOD_FAILURE(420, "Method Failure"), + /** @deprecated */ + @Deprecated + DESTINATION_LOCKED(421, "Destination Locked"), + UNPROCESSABLE_ENTITY(422, "Unprocessable Entity"), + LOCKED(423, "Locked"), + FAILED_DEPENDENCY(424, "Failed Dependency"), + TOO_EARLY(425, "Too Early"), + UPGRADE_REQUIRED(426, "Upgrade Required"), + PRECONDITION_REQUIRED(428, "Precondition Required"), + TOO_MANY_REQUESTS(429, "Too Many Requests"), + REQUEST_HEADER_FIELDS_TOO_LARGE(431, "Request Header Fields Too Large"), + UNAVAILABLE_FOR_LEGAL_REASONS(451, "Unavailable For Legal Reasons"), + INTERNAL_SERVER_ERROR(500, "Internal Server Error"), + NOT_IMPLEMENTED(501, "Not Implemented"), + BAD_GATEWAY(502, "Bad Gateway"), + SERVICE_UNAVAILABLE(503, "Service Unavailable"), + GATEWAY_TIMEOUT(504, "Gateway Timeout"), + HTTP_VERSION_NOT_SUPPORTED(505, "HTTP Version not supported"), + VARIANT_ALSO_NEGOTIATES(506, "Variant Also Negotiates"), + INSUFFICIENT_STORAGE(507, "Insufficient Storage"), + LOOP_DETECTED(508, "Loop Detected"), + BANDWIDTH_LIMIT_EXCEEDED(509, "Bandwidth Limit Exceeded"), + NOT_EXTENDED(510, "Not Extended"), + NETWORK_AUTHENTICATION_REQUIRED(511, "Network Authentication Required"); + + private final int value; + private final String reasonPhrase; + + private ResponseStatus(int value, String reasonPhrase) { + this.value = value; + this.reasonPhrase = reasonPhrase; + } + + public int value() { + return this.value; + } + + public String getReasonPhrase() { + return this.reasonPhrase; + } + + public Series series() { + return ResponseStatus.Series.valueOf(this); + } + + public boolean is1xxInformational() { + return this.series() == ResponseStatus.Series.INFORMATIONAL; + } + + public boolean is2xxSuccessful() { + return this.series() == ResponseStatus.Series.SUCCESSFUL; + } + + public boolean is3xxRedirection() { + return this.series() == ResponseStatus.Series.REDIRECTION; + } + + public boolean is4xxClientError() { + return this.series() == ResponseStatus.Series.CLIENT_ERROR; + } + + public boolean is5xxServerError() { + return this.series() == ResponseStatus.Series.SERVER_ERROR; + } + + public boolean isError() { + return this.is4xxClientError() || this.is5xxServerError(); + } + + public String toString() { + return this.value + " " + this.name(); + } + + public static ResponseStatus valueOf(int statusCode) { + ResponseStatus status = resolve(statusCode); + if (status == null) { + throw new IllegalArgumentException("No matching constant for [" + statusCode + "]"); + } else { + return status; + } + } + + + public static ResponseStatus resolve(int statusCode) { + ResponseStatus[] var1 = values(); + int var2 = var1.length; + + for(int var3 = 0; var3 < var2; ++var3) { + ResponseStatus status = var1[var3]; + if (status.value == statusCode) { + return status; + } + } + + return null; + } + + public static enum Series { + INFORMATIONAL(1), + SUCCESSFUL(2), + REDIRECTION(3), + CLIENT_ERROR(4), + SERVER_ERROR(5); + + private final int value; + + private Series(int value) { + this.value = value; + } + + public int value() { + return this.value; + } + + public static Series valueOf(ResponseStatus status) { + return valueOf(status.value); + } + + public static Series valueOf(int statusCode) { + Series series = resolve(statusCode); + if (series == null) { + throw new IllegalArgumentException("No matching constant for [" + statusCode + "]"); + } else { + return series; + } + } + + public static Series resolve(int statusCode) { + int seriesCode = statusCode / 100; + Series[] var2 = values(); + int var3 = var2.length; + + for(int var4 = 0; var4 < var3; ++var4) { + Series series = var2[var4]; + if (series.value == seriesCode) { + return series; + } + } + + return null; + } + } +} diff --git a/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/exception/AbstractFrameworkException.java b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/exception/AbstractFrameworkException.java new file mode 100644 index 0000000..5c920ac --- /dev/null +++ b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/exception/AbstractFrameworkException.java @@ -0,0 +1,11 @@ +package cn.zyjblogs.common.exception; + +public abstract class AbstractFrameworkException extends RuntimeException { + public AbstractFrameworkException(String message) { + super(message); + } + + public AbstractFrameworkException(String message, Throwable cause) { + super(message, cause); + } +} \ No newline at end of file diff --git a/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/utils/bean/BeanUtils.java b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/utils/bean/BeanUtils.java new file mode 100644 index 0000000..7d30109 --- /dev/null +++ b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/utils/bean/BeanUtils.java @@ -0,0 +1,171 @@ +package cn.zyjblogs.common.utils.bean; + +import cn.zyjblogs.common.utils.jackson.JacksonHolder; +import cn.zyjblogs.common.utils.jackson.exception.JsonConvertException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.time.LocalDateTime; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; +import ma.glasnost.orika.DefaultFieldMapper; +import ma.glasnost.orika.MapperFacade; +import ma.glasnost.orika.MapperFactory; +import ma.glasnost.orika.impl.DefaultMapperFactory; +import ma.glasnost.orika.metadata.ClassMapBuilder; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class BeanUtils { + private static final Logger log = LoggerFactory.getLogger(BeanUtils.class); + private static final MapperFacade DEFAULT_MAPPER_FACADE = (new DefaultMapperFactory.Builder()).build().getMapperFacade(); + private static final Map MYSQL_ESCAPE_MAP = new LinkedHashMap<>(); + + private BeanUtils() { + } + + public static Map beanToMap(Object bean) { + Map result = new HashMap(); + DEFAULT_MAPPER_FACADE.map(bean, result); + return result; + } + + public static T map(S sourceBean, Class targetClass) { + return DEFAULT_MAPPER_FACADE.map(sourceBean, targetClass); + } + + public static T map(S sourceBean, Class targetClass, Map customPropertyMap) { + MapperFacade mapperFacade = getMapperFacadeForCustomPropertyMap(sourceBean.getClass(), targetClass, customPropertyMap); + return mapperFacade.map(sourceBean, targetClass); + } + + public static T map(S sourceBean, T targetBean) { + DEFAULT_MAPPER_FACADE.map(sourceBean, targetBean); + return targetBean; + } + + public static T map(S sourceBean, T targetBean, Map customPropertyMap) { + MapperFacade mapperFacade = getMapperFacadeForCustomPropertyMap(sourceBean.getClass(), targetBean.getClass(), customPropertyMap); + mapperFacade.map(sourceBean, targetBean); + return targetBean; + } + + public static List map(Iterable sourceData, Class targetClass) { + return DEFAULT_MAPPER_FACADE.mapAsList(sourceData, targetClass); + } + + public static T mapByJackson(Object content, TypeReference valueTypeRef) { + if (!Objects.isNull(content) && !StringUtils.isBlank(content.toString())) { + try { + T result = JacksonHolder.MAPPER.readValue(JacksonHolder.MAPPER.writeValueAsString(content), valueTypeRef); + return result; + } catch (JsonProcessingException var4) { + log.error("json转换异常:", var4); + throw new JsonConvertException("json转换异常", var4); + } + } else { + return null; + } + } + + public static T handlePropertyForLikeQuery(T bean, Set ignoreProperty) { + if (bean != null) { + Class clazz = bean.getClass(); + Field[] fields = clazz.getDeclaredFields(); + Field[] var4 = fields; + int var5 = fields.length; + + for (int var6 = 0; var6 < var5; ++var6) { + Field field = var4[var6]; + String fieldName = field.getName(); + if ((ignoreProperty == null || !ignoreProperty.contains(fieldName)) && String.class == field.getType()) { + String originalValue = (String) getFieldValue(bean, field.getName(), String.class); + String newValue = escapeFieldValue(originalValue); + setFieldValue(bean, fieldName, newValue); + } + } + } + + return bean; + } + + public static Map reverseMap(Map map) { + return (Map) (map != null && map.size() != 0 ? (Map) map.entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey, (key1, key2) -> { + return key2; + })) : new HashMap(0)); + } + + private static T getFieldValue(Object bean, String fieldName, Class clazz) { + Method method = null; + + try { + method = bean.getClass().getMethod("get" + getFieldBaseMethodName(fieldName)); + return (T) method.invoke(bean); + } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException var5) { + throw new JsonConvertException("bean转义时,获取属性值出现异常", var5); + } + } + + public static T handlePropertyForLikeQuery(T bean) { + return (T) handlePropertyForLikeQuery(bean, null); + } + + private static void setFieldValue(Object bean, String fieldName, Object fieldValue) { + Class clazz = bean.getClass(); + + try { + Field field = clazz.getDeclaredField(fieldName); + field.setAccessible(true); + field.set(bean, fieldValue); + } catch (IllegalAccessException | NoSuchFieldException var6) { + throw new JsonConvertException("bean转义时,设置属性值出现异常", var6); + } + } + + private static String getFieldBaseMethodName(String fieldName) { + byte[] items = fieldName.getBytes(); + items[0] = (byte) ((char) items[0] - 97 + 65); + return new String(items); + } + + private static String escapeFieldValue(String originalFieldValue) { + if (originalFieldValue != null && !"".equals(originalFieldValue)) { + String oldChar; + String newChar; + for (Iterator var1 = MYSQL_ESCAPE_MAP.entrySet().iterator(); var1.hasNext(); originalFieldValue = originalFieldValue.replace(oldChar, newChar)) { + Map.Entry escapeEntry = (Map.Entry) var1.next(); + oldChar = (String) escapeEntry.getKey(); + newChar = (String) escapeEntry.getValue(); + } + + return originalFieldValue; + } else { + return null; + } + } + + public static MapperFacade getMapperFacadeForCustomPropertyMap(Class sourceClass, Class targetClass, Map customPropertyMap) { + MapperFactory mapperFactory = (new DefaultMapperFactory.Builder()).build(); + ClassMapBuilder classMapBuilder = mapperFactory.classMap(sourceClass, targetClass); + Objects.requireNonNull(classMapBuilder); + customPropertyMap.forEach(classMapBuilder::field); + classMapBuilder.byDefault(new DefaultFieldMapper[0]).register(); + return mapperFactory.getMapperFacade(); + } + + static { + MYSQL_ESCAPE_MAP.put("\\", "\\\\"); + MYSQL_ESCAPE_MAP.put("%", "\\%"); + MYSQL_ESCAPE_MAP.put("'", "\\'"); + MYSQL_ESCAPE_MAP.put("_", "\\_"); + } +} \ No newline at end of file diff --git a/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/utils/jackson/JacksonHolder.java b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/utils/jackson/JacksonHolder.java new file mode 100644 index 0000000..b167280 --- /dev/null +++ b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/utils/jackson/JacksonHolder.java @@ -0,0 +1,17 @@ +package cn.zyjblogs.common.utils.jackson; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; + +public final class JacksonHolder { + public static final ObjectMapper MAPPER = new ObjectMapper(); + + private JacksonHolder() { + } + + static { + MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL); + MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + } +} \ No newline at end of file diff --git a/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/utils/jackson/JsonUtils.java b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/utils/jackson/JsonUtils.java new file mode 100644 index 0000000..2fe7d8f --- /dev/null +++ b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/utils/jackson/JsonUtils.java @@ -0,0 +1,45 @@ +package cn.zyjblogs.common.utils.jackson; + + +import cn.zyjblogs.common.utils.jackson.exception.JsonConvertException; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class JsonUtils { + public static final ObjectMapper MAPPER = new ObjectMapper(); + + private JsonUtils() { + } + + public static T readValue(String content, TypeReference valueTypeRef) { + try { + return MAPPER.readValue(content, valueTypeRef); + } catch (JsonProcessingException var3) { + throw new JsonConvertException("json字符串转对象出现异常", var3); + } + } + + public static T readValue(String content, Class valueType) { + try { + return MAPPER.readValue(content, valueType); + } catch (JsonProcessingException var3) { + throw new JsonConvertException("json字符串转对象出现异常", var3); + } + } + + public static String writeValueAsString(Object value) { + try { + return MAPPER.writeValueAsString(value); + } catch (JsonProcessingException var2) { + throw new JsonConvertException("对象转json字符串出现异常", var2); + } + } + + static { + MAPPER.setSerializationInclusion(Include.NON_NULL); + MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + } +} \ No newline at end of file diff --git a/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/utils/jackson/exception/JsonConvertException.java b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/utils/jackson/exception/JsonConvertException.java new file mode 100644 index 0000000..69df809 --- /dev/null +++ b/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/common/utils/jackson/exception/JsonConvertException.java @@ -0,0 +1,13 @@ +package cn.zyjblogs.common.utils.jackson.exception; + +import cn.zyjblogs.common.exception.AbstractFrameworkException; + +public class JsonConvertException extends AbstractFrameworkException { + public JsonConvertException(String msg) { + super(msg); + } + + public JsonConvertException(String msg, Throwable cause) { + super(msg, cause); + } +} diff --git a/zyjblogs-common-spring-boot-starter/src/main/resources/META-INF/MANIFEST.MF b/zyjblogs-common-spring-boot-starter/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..966deb6 --- /dev/null +++ b/zyjblogs-common-spring-boot-starter/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +Archiver-Version: Plexus Archiver +Created-By: Apache Maven 3.6.3 +Built-By: mitom +Build-Jdk: 11 diff --git a/zyjblogs-common-spring-boot-starter/src/main/resources/META-INF/maven.cn.zyjblogs.starter.zyjblogs-common-spring-boot-starter/pom.properties b/zyjblogs-common-spring-boot-starter/src/main/resources/META-INF/maven.cn.zyjblogs.starter.zyjblogs-common-spring-boot-starter/pom.properties new file mode 100644 index 0000000..a00cb92 --- /dev/null +++ b/zyjblogs-common-spring-boot-starter/src/main/resources/META-INF/maven.cn.zyjblogs.starter.zyjblogs-common-spring-boot-starter/pom.properties @@ -0,0 +1,5 @@ +#Generated by Maven +#Mon Jul 25 15:29:06 CST 2022 +groupId=cn.zyjblogs.starter +artifactId=zyjblogs-common-spring-boot-starter +version=1.0-SNAPSHOT diff --git a/zyjblogs-common-spring-boot-starter/src/main/resources/META-INF/maven.cn.zyjblogs.starter.zyjblogs-common-spring-boot-starter/pom.xml b/zyjblogs-common-spring-boot-starter/src/main/resources/META-INF/maven.cn.zyjblogs.starter.zyjblogs-common-spring-boot-starter/pom.xml new file mode 100644 index 0000000..544435f --- /dev/null +++ b/zyjblogs-common-spring-boot-starter/src/main/resources/META-INF/maven.cn.zyjblogs.starter.zyjblogs-common-spring-boot-starter/pom.xml @@ -0,0 +1,82 @@ + + + + zyjblogs-parent + cn.zyjblogs + 1.0-SNAPSHOT + + 4.0.0 + cn.zyjblogs.starter + zyjblogs-common-spring-boot-starter + ${zyjblogs.version} + + 11 + 11 + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-validation + + + io.swagger + swagger-annotations + + + com.alibaba + transmittable-thread-local + + + + org.projectlombok + lombok + + + org.apache.commons + commons-lang3 + + + org.apache.commons + commons-collections4 + + + commons-io + commons-io + + + org.apache.commons + commons-crypto + + + ma.glasnost.orika + orika-core + + + com.alibaba + easyexcel + + + io.jsonwebtoken + jjwt + + + javax.xml.bind + jaxb-api + + + + + + org.apache.maven.plugins + maven-source-plugin + + + + \ No newline at end of file diff --git a/zyjblogs-common-spring-boot-starter/src/main/resources/META-INF/spring.factories b/zyjblogs-common-spring-boot-starter/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..e69de29 diff --git a/zyjblogs-gateway/pom.xml b/zyjblogs-gateway/pom.xml index d84cb4d..67d6a1a 100644 --- a/zyjblogs-gateway/pom.xml +++ b/zyjblogs-gateway/pom.xml @@ -9,11 +9,91 @@ 4.0.0 + cn.zyjblogs.pubilc zyjblogs-gateway + ${zyjblogs.version} 11 11 + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-sentinel + + + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.springframework.boot + spring-boot-starter-data-redis-reactive + + + + org.apache.commons + commons-pool2 + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + checker-qual + org.checkerframework + + + error_prone_annotations + com.google.errorprone + + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + org.springframework.boot + spring-boot-starter-test + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + org.springframework.cloud + spring-cloud-starter-gateway + + + + com.alibaba.csp + sentinel-datasource-nacos + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + + + + + + + org.springframework.cloud + spring-cloud-starter-oauth2 + + + cn.zyjblogs.starter + zyjblogs-common-spring-boot-starter + ${zyjblogs.version} + + \ No newline at end of file diff --git a/zyjblogs-gateway/src/main/java/cn/zyjblogs/gateway/GatewayApplication.java b/zyjblogs-gateway/src/main/java/cn/zyjblogs/gateway/GatewayApplication.java new file mode 100644 index 0000000..ee4645f --- /dev/null +++ b/zyjblogs-gateway/src/main/java/cn/zyjblogs/gateway/GatewayApplication.java @@ -0,0 +1,25 @@ +package cn.zyjblogs.gateway; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.scheduling.annotation.EnableAsync; + +/** + * Copyright (C), 2021, 北京同创永益科技发展有限公司 + * + * @author zhuyijun + * @version 3.0.0 + * @description + * @date 2022/8/18 9:28 + */ +@EnableAsync +@EnableFeignClients +@EnableDiscoveryClient +@SpringBootApplication +public class GatewayApplication { + public static void main(String[] args) { + SpringApplication.run(GatewayApplication.class, args); + } +} diff --git a/zyjblogs-gateway/src/main/java/cn/zyjblogs/gateway/filter/AuthFilter.java b/zyjblogs-gateway/src/main/java/cn/zyjblogs/gateway/filter/AuthFilter.java new file mode 100644 index 0000000..3d02159 --- /dev/null +++ b/zyjblogs-gateway/src/main/java/cn/zyjblogs/gateway/filter/AuthFilter.java @@ -0,0 +1,147 @@ +package cn.zyjblogs.gateway.filter; + +import cn.zyjblogs.common.entity.constant.HttpHeaderConstant; +import cn.zyjblogs.common.entity.response.ResponseObject; +import cn.zyjblogs.common.entity.response.ResponseResult; +import cn.zyjblogs.common.entity.response.ResponseStatus; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.cloud.gateway.filter.GatewayFilterChain; +import org.springframework.cloud.gateway.filter.GlobalFilter; +import org.springframework.cloud.gateway.route.Route; +import org.springframework.cloud.gateway.support.ServerWebExchangeUtils; +import org.springframework.core.io.buffer.DataBuffer; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.server.reactive.ServerHttpRequest; +import org.springframework.http.server.reactive.ServerHttpResponse; +import org.springframework.stereotype.Component; +import org.springframework.util.AntPathMatcher; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Mono; + +import java.util.List; + +/** + * Copyright (C), 2021, 北京同创永益科技发展有限公司 + * + * @author tanyuanzhi + * @version 3.0.0 + * description token校验过滤器,要在WebsocketRoutingFilter过滤器之后huo + * @date 2021/11/1 16:22 + */ +@Component +@Slf4j +@EnableConfigurationProperties(WhiteListProperties.class) +@RequiredArgsConstructor +public class AuthFilter implements GlobalFilter { + private final WhiteListProperties whiteListProperties; + private AntPathMatcher antPathMatcher = new AntPathMatcher(); + + + @Override + public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { + //添加网关标记 + ServerHttpRequest serverHttpRequest = exchange.getRequest().mutate() + .headers(h -> h.add(HttpHeaderConstant.REQUEST_FROM_GATEWAY_KEY, HttpHeaderConstant.REQUEST_FROM_GATEWAY_VALUE)) + .build(); + ServerWebExchange build = exchange.mutate().request(serverHttpRequest).build(); + ServerHttpRequest request = build.getRequest(); + ServerHttpResponse response = build.getResponse(); + String token = request.getHeaders().getFirst(HttpHeaders.AUTHORIZATION); + log.debug("token:{}", token); + String path = request.getURI().getPath(); + String methodType = request.getMethodValue().toLowerCase(); + Route route = (Route) exchange.getAttributes().get(ServerWebExchangeUtils.GATEWAY_ROUTE_ATTR); + String routeId = route.getId(); + //白名单请求直接放行 + if (isWhileList(path)) { + return chain.filter(exchange); + } + if (isExpired(token)) { + log.info("token过期"); + return getErrorMono(response, ResponseStatus.UNAUTHORIZED, "invalid_token"); + } + if ("/user/login".equals(path)) { + return chain.filter(exchange); + } +// if (!TokenUtil.checkToken(token)) { +// return getErrorMono(response, ResponseStatus.UNAUTHORIZED, "invalid_token"); +// } + /*boolean hasPermission = hasPermission(routeId, methodType, path); + if (!hasPermission) { + log.warn("无权限访问,path:{}", path); + return getErrorMono(response, ResponseCode.FORBIDDEN, "no_access"); + }*/ + return chain.filter(build); + } + + /** + * token是否过期 + * + * @param token token + * @return 过期true + * @author tanyuanzhi + * @date 2021/11/15 19:17 + */ + private boolean isExpired(String token) { + if (StringUtils.isEmpty(token)) { + return false; + } + if (!token.startsWith(HttpHeaderConstant.AUTHORIZATION_TYPE)) { + return false; + } + String jwt = token.replace(HttpHeaderConstant.AUTHORIZATION_TYPE + " ", ""); + return true; + } + + /** + * 是否是白名单 + * + * @param path 当前路径 + * @return 是否是白名单中的地址 + * @author tanyuanzhi + * @date 2021/11/2 9:15 + */ + + private boolean isWhileList(String path) { + List allowPaths = whiteListProperties.getAllowPaths(); + if (CollectionUtils.isEmpty(allowPaths)) { + return false; + } + return allowPaths.stream().anyMatch(allowPath -> antPathMatcher.match(allowPath, path)); + + } + + + + /** + * 验证不通过时的返回 + * + * @param response 响应 + * @param responseCode 响应码 + * @return reactor.core.publisher.Mono + * @date 2021/11/1 17:10 + */ + private Mono getErrorMono(ServerHttpResponse response, ResponseStatus responseCode, String msg) { + response.getHeaders().setContentType(MediaType.APPLICATION_JSON); + response.setStatusCode(HttpStatus.OK); + ResponseObject responseObject = ResponseResult.error(responseCode, msg); + ObjectMapper mapper = new ObjectMapper(); + byte[] bytes = new byte[0]; + try { + bytes = mapper.writeValueAsBytes(responseObject); + } catch (JsonProcessingException e) { + log.error("转换错误"); + } + DataBuffer wrap = response.bufferFactory().wrap(bytes); + return response.writeWith(Mono.just(wrap)); + + } +} diff --git a/zyjblogs-gateway/src/main/java/cn/zyjblogs/gateway/filter/WhiteListProperties.java b/zyjblogs-gateway/src/main/java/cn/zyjblogs/gateway/filter/WhiteListProperties.java new file mode 100644 index 0000000..6e2b86b --- /dev/null +++ b/zyjblogs-gateway/src/main/java/cn/zyjblogs/gateway/filter/WhiteListProperties.java @@ -0,0 +1,16 @@ +package cn.zyjblogs.gateway.filter; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; + +import java.util.List; + +/** + * 白名单 + */ +@Data +@ConfigurationProperties(prefix = "zyjblogs.whilelist") +public class WhiteListProperties { + + private List allowPaths; +} diff --git a/zyjblogs-gateway/src/main/resources/bootstrap-test.yml b/zyjblogs-gateway/src/main/resources/bootstrap-test.yml new file mode 100644 index 0000000..bb3759c --- /dev/null +++ b/zyjblogs-gateway/src/main/resources/bootstrap-test.yml @@ -0,0 +1,8 @@ +zyjblogs: + config: + nacos: + host: ${HATECH_CONFIG_NACOS_HOST:127.0.0.1} + port: ${HATECH_CONFIG_NACOS_PORT:8848} + username: ${HATECH_CONFIG_NACOS_USERNAME:nacos} + password: ${HATECH_CONFIG_NACOS_PASSWORD:nacos} + diff --git a/zyjblogs-gateway/src/main/resources/bootstrap.yml b/zyjblogs-gateway/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..e015d04 --- /dev/null +++ b/zyjblogs-gateway/src/main/resources/bootstrap.yml @@ -0,0 +1,28 @@ +spring: + profiles: + active: test + +--- +spring: + application: + name: zyjblogs-gateway + cloud: + nacos: + config: + server-addr: ${zyjblogs.config.nacos.host}:${zyjblogs.config.nacos.port} + username: ${zyjblogs.config.nacos.username} + password: ${zyjblogs.config.nacos.password} + namespace: ${spring.profiles.active} + group: public + file-extension: yml + shared-configs[0]: + data-id: zyjblogs-global-${spring.profiles.active}.yml + group: global + discovery: + server-addr: ${spring.cloud.nacos.config.server-addr} + username: ${spring.cloud.nacos.config.username} + password: ${spring.cloud.nacos.config.password} + namespace: ${spring.cloud.nacos.config.namespace} + group: public +logging: + config: classpath:logback-spring.xml \ No newline at end of file diff --git a/zyjblogs-gateway/src/main/resources/logback-spring.xml b/zyjblogs-gateway/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..51f3170 --- /dev/null +++ b/zyjblogs-gateway/src/main/resources/logback-spring.xml @@ -0,0 +1,198 @@ + + + + + + + + + + + + + + + + + + + + + + info + + + ${CONSOLE_LOG_PATTERN} + UTF-8 + + + + + + + ${logger.path}/log_debug.log + + + [%d{yyyy-MM-dd HH:mm:ss.SSS}] [%thread] [%X{traceId}] %-5level %logger{50} - %msg%n + UTF-8 + + + + + ${logger.path}/debug/log-debug-%d{yyyy-MM-dd}.%i.log + 50MB + + 30 + 1GB + true + + + + + debug + ACCEPT + DENY + + + + + + + ${logger.path}/log_info.log + + + [%d{yyyy-MM-dd HH:mm:ss.SSS}] [%thread] [%X{traceId}] %-5level %logger{50} - %msg%n + UTF-8 + + + + + ${logger.path}/info/log-info-%d{yyyy-MM-dd}.%i.log + 50MB + + 30 + 1GB + true + + + + info + ACCEPT + DENY + + + + + + + ${logger.path}/log_warn.log + + + [%d{yyyy-MM-dd HH:mm:ss.SSS}] [%thread] [%X{traceId}] %-5level %logger{50} - %msg%n + UTF-8 + + + + ${logger.path}/warn/log-warn-%d{yyyy-MM-dd}.%i.log + 50MB + + 30 + 1GB + true + + + + warn + ACCEPT + DENY + + + + + + + ${logger.path}/log_error.log + + + [%d{yyyy-MM-dd HH:mm:ss.SSS}] [%thread] [%X{traceId}] %-5level %logger{50} - %msg%n + UTF-8 + + + + ${logger.path}/error/log-error-%d{yyyy-MM-dd}.%i.log + 50MB + + 30 + 1GB + true + + + + ERROR + ACCEPT + DENY + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/zyjblogs-oauth/pom.xml b/zyjblogs-oauth/pom.xml index 218033a..09a0588 100644 --- a/zyjblogs-oauth/pom.xml +++ b/zyjblogs-oauth/pom.xml @@ -9,7 +9,9 @@ 4.0.0 + cn.zyjblogs.pubilc zyjblogs-oauth + ${zyjblogs.version} 11 diff --git a/zyjblogs-oauth/src/main/resources/bootstrap-test.yml b/zyjblogs-oauth/src/main/resources/bootstrap-test.yml index 66f7101..ca0d427 100644 --- a/zyjblogs-oauth/src/main/resources/bootstrap-test.yml +++ b/zyjblogs-oauth/src/main/resources/bootstrap-test.yml @@ -1,8 +1,8 @@ -hatech: +zyjblogs: config: nacos: - host: ${HATECH_CONFIG_NACOS_HOST:127.0.0.1} - port: ${HATECH_CONFIG_NACOS_PORT:8848} - username: ${HATECH_CONFIG_NACOS_USERNAME:nacos} - password: ${HATECH_CONFIG_NACOS_PASSWORD:nacos} + host: ${ZYJBLOGS_CONFIG_NACOS_HOST:127.0.0.1} + port: ${ZYJBLOGS_CONFIG_NACOS_PORT:8848} + username: ${ZYJBLOGS_CONFIG_NACOS_USERNAME:nacos} + password: ${ZYJBLOGS_CONFIG_NACOS_PASSWORD:nacos} diff --git a/zyjblogs-oauth/src/main/resources/bootstrap.yml b/zyjblogs-oauth/src/main/resources/bootstrap.yml index 9e06ff6..8f848b2 100644 --- a/zyjblogs-oauth/src/main/resources/bootstrap.yml +++ b/zyjblogs-oauth/src/main/resources/bootstrap.yml @@ -9,9 +9,9 @@ spring: cloud: nacos: config: - server-addr: ${hatech.config.nacos.host}:${hatech.config.nacos.port} - username: ${hatech.config.nacos.username} - password: ${hatech.config.nacos.password} + server-addr: ${zyjblogs.config.nacos.host}:${zyjblogs.config.nacos.port} + username: ${zyjblogs.config.nacos.username} + password: ${zyjblogs.config.nacos.password} namespace: ${spring.profiles.active} group: public file-extension: yml diff --git a/zyjblogs-rbac/pom.xml b/zyjblogs-rbac/pom.xml index a148248..deabfc0 100644 --- a/zyjblogs-rbac/pom.xml +++ b/zyjblogs-rbac/pom.xml @@ -8,8 +8,9 @@ 1.0-SNAPSHOT 4.0.0 - + cn.zyjblogs.pubilc zyjblogs-rbac + ${zyjblogs.version} 11 diff --git a/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/RbacApplication.java b/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/RbacApplication.java index f2f4da4..36b180b 100644 --- a/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/RbacApplication.java +++ b/zyjblogs-rbac/src/main/java/cn/zyjblogs/rbac/RbacApplication.java @@ -19,9 +19,6 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; @SpringBootApplication public class RbacApplication { public static void main(String[] args) { - BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder(); - - System.out.println(bCryptPasswordEncoder.encode("secret")); SpringApplication.run(RbacApplication.class, args); } } diff --git a/zyjblogs-rbac/src/main/resources/bootstrap-test.yml b/zyjblogs-rbac/src/main/resources/bootstrap-test.yml index 66f7101..ca0d427 100644 --- a/zyjblogs-rbac/src/main/resources/bootstrap-test.yml +++ b/zyjblogs-rbac/src/main/resources/bootstrap-test.yml @@ -1,8 +1,8 @@ -hatech: +zyjblogs: config: nacos: - host: ${HATECH_CONFIG_NACOS_HOST:127.0.0.1} - port: ${HATECH_CONFIG_NACOS_PORT:8848} - username: ${HATECH_CONFIG_NACOS_USERNAME:nacos} - password: ${HATECH_CONFIG_NACOS_PASSWORD:nacos} + host: ${ZYJBLOGS_CONFIG_NACOS_HOST:127.0.0.1} + port: ${ZYJBLOGS_CONFIG_NACOS_PORT:8848} + username: ${ZYJBLOGS_CONFIG_NACOS_USERNAME:nacos} + password: ${ZYJBLOGS_CONFIG_NACOS_PASSWORD:nacos} diff --git a/zyjblogs-rbac/src/main/resources/bootstrap.yml b/zyjblogs-rbac/src/main/resources/bootstrap.yml index a20671a..bc35084 100644 --- a/zyjblogs-rbac/src/main/resources/bootstrap.yml +++ b/zyjblogs-rbac/src/main/resources/bootstrap.yml @@ -9,9 +9,9 @@ spring: cloud: nacos: config: - server-addr: ${hatech.config.nacos.host}:${hatech.config.nacos.port} - username: ${hatech.config.nacos.username} - password: ${hatech.config.nacos.password} + server-addr: ${zyjblogs.config.nacos.host}:${zyjblogs.config.nacos.port} + username: ${zyjblogs.config.nacos.username} + password: ${zyjblogs.config.nacos.password} namespace: ${spring.profiles.active} group: public file-extension: yml