From b52d813aa48e33d5df9e59793dc4080da224197e Mon Sep 17 00:00:00 2001 From: lbw Date: Sun, 7 Aug 2022 14:06:29 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20Introducing=20new=20features.=20cl?= =?UTF-8?q?ose=20#4206=20Spring=20MVC=20=E5=A4=84=E7=90=86=E6=98=A0?= =?UTF-8?q?=E5=B0=84=E5=8C=B9=E9=85=8D=E4=BF=AE=E6=94=B9=E4=B8=BAPathPatte?= =?UTF-8?q?rnParser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/6pigxx_config.sql | 2 +- .../common/security/component/PermitAllUrlResolver.java | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/db/6pigxx_config.sql b/db/6pigxx_config.sql index a86a17c7e..94197c00d 100644 --- a/db/6pigxx_config.sql +++ b/db/6pigxx_config.sql @@ -32,7 +32,7 @@ CREATE TABLE `config_info` ( -- Records of config_info -- ---------------------------- BEGIN; -INSERT INTO `config_info` VALUES (1, 'application-dev.yml', 'DEFAULT_GROUP', '# 配置文件加密根密码\njasypt:\n encryptor:\n password: pigx\n algorithm: PBEWithMD5AndDES\n iv-generator-classname: org.jasypt.iv.NoIvGenerator\n\nspring:\n mvc:\n pathmatch:\n matching-strategy: ant_path_matcher\n redis:\n host: pigx-redis\n servlet:\n multipart:\n max-file-size: 100MB\n max-request-size: 100MB\n cloud:\n sentinel:\n eager: true\n transport:\n dashboard: pigx-sentinel:5020\n\n# 端点对外暴露\nmanagement:\n endpoints:\n web:\n exposure:\n include: \'*\' \n endpoint:\n restart:\n enabled: true\n health:\n show-details: ALWAYS\n# feign 相关配置\nfeign:\n sentinel:\n enabled: true\n okhttp:\n enabled: true\n httpclient:\n enabled: false\n client:\n config:\n default:\n connectTimeout: 20000\n readTimeout: 20000\n compression:\n request:\n enabled: true\n response:\n enabled: true\n\n#开启灰度\ngray:\n rule:\n enabled: true\n\n# mybatis-plus 配置\nmybatis-plus:\n tenant-enable: ture\n mapper-locations: classpath:/mapper/*Mapper.xml\n global-config:\n capitalMode: true\n banner: false\n db-config:\n id-type: auto\n select-strategy: not_empty\n insert-strategy: not_empty\n update-strategy: not_empty\n type-handlers-package: com.pig4cloud.pigx.common.data.handler\n configuration:\n jdbc-type-for-null: \'null\'\n call-setters-on-nulls: true\n# swagger 全局配置\nknife4j:\n enable: true\nswagger:\n enabled: true\n title: PigX Swagger API\n license: Powered By PigX\n licenseUrl: https://pig4cloud.com/\n terms-of-service-url: https://pig4cloud.com/\n contact:\n email: wangiegie@gmail.com\n url: https://pig4cloud.com/about.html\n authorization:\n name: oauth2\n auth-regex: ^.*$\n authorization-scope-list:\n - scope: server\n description: server all\n token-url-list:\n - http://${GATEWAY_HOST:pigx-gateway}:${GATEWAY_PORT:9999}/auth/oauth/token\n\n# oauth2 资源服务器相关配置\nsecurity:\n oauth2:\n client:\n ignore-urls:\n - /css/**\n - /error\n - /actuator/**\n - /v2/api-docs\n resource:\n loadBalanced: true\n token-info-uri: http://pigx-auth/oauth/check_token', '77d9d4800dc7537704e228f2a04dac55', '2019-04-18 02:10:20', '2022-02-13 21:44:06', 'nacos', '127.0.0.1', '', '', '通用配置文件', 'null', 'null', 'yaml', 'null'); +INSERT INTO `config_info` VALUES (1, 'application-dev.yml', 'DEFAULT_GROUP', '# 配置文件加密根密码\njasypt:\n encryptor:\n password: pigx\n algorithm: PBEWithMD5AndDES\n iv-generator-classname: org.jasypt.iv.NoIvGenerator\n\nspring:\n redis:\n host: pigx-redis\n servlet:\n multipart:\n max-file-size: 100MB\n max-request-size: 100MB\n cloud:\n sentinel:\n eager: true\n transport:\n dashboard: pigx-sentinel:5020\n\n# 端点对外暴露\nmanagement:\n endpoints:\n web:\n exposure:\n include: \'*\' \n endpoint:\n restart:\n enabled: true\n health:\n show-details: ALWAYS\n# feign 相关配置\nfeign:\n sentinel:\n enabled: true\n okhttp:\n enabled: true\n httpclient:\n enabled: false\n client:\n config:\n default:\n connectTimeout: 20000\n readTimeout: 20000\n compression:\n request:\n enabled: true\n response:\n enabled: true\n\n#开启灰度\ngray:\n rule:\n enabled: true\n\n# mybatis-plus 配置\nmybatis-plus:\n tenant-enable: ture\n mapper-locations: classpath:/mapper/*Mapper.xml\n global-config:\n capitalMode: true\n banner: false\n db-config:\n id-type: auto\n select-strategy: not_empty\n insert-strategy: not_empty\n update-strategy: not_null\n type-handlers-package: com.pig4cloud.pigx.common.data.handler\n configuration:\n jdbc-type-for-null: \'null\'\n call-setters-on-nulls: true\n# swagger 全局配置\nknife4j:\n enable: true\nswagger:\n enabled: true\n title: PigX Swagger API\n license: Powered By PigX\n licenseUrl: https://pig4cloud.com/\n terms-of-service-url: https://pig4cloud.com/\n contact:\n email: wangiegie@gmail.com\n url: https://pig4cloud.com/about.html\n authorization:\n name: oauth2\n auth-regex: ^.*$\n authorization-scope-list:\n - scope: server\n description: server all\n token-url-list:\n - http://${GATEWAY_HOST:pigx-gateway}:${GATEWAY_PORT:9999}/auth/oauth/token\n\n# oauth2 资源服务器相关配置\nsecurity:\n oauth2:\n client:\n ignore-urls:\n - /css/**\n - /error\n - /actuator/**\n - /v2/api-docs\n resource:\n loadBalanced: true\n token-info-uri: http://pigx-auth/oauth/check_token', '01f97b71c9b83d7efd03d6f56881c3db', '2019-04-18 02:10:20', '2022-08-07 14:05:10', 'nacos', '127.0.0.1', '', '', '通用配置文件', 'null', 'null', 'yaml', 'null'); INSERT INTO `config_info` VALUES (2, 'pigx-auth-dev.yml', 'DEFAULT_GROUP', '# 数据源\nspring:\n freemarker:\n allow-request-override: false\n allow-session-override: false\n cache: true\n charset: UTF-8\n check-template-location: true\n content-type: text/html\n enabled: true\n expose-request-attributes: false\n expose-session-attributes: false\n expose-spring-macro-helpers: true\n prefer-file-system-access: true\n suffix: .ftl\n template-loader-path: classpath:/templates/', '74f53b71c7799aa754da75662378b93c', '2019-04-18 02:11:32', '2021-05-07 23:40:38', NULL, '10.1.1.143', '', '', '认证中心配置文件', 'null', 'null', 'yaml', 'null'); INSERT INTO `config_info` VALUES (3, 'pigx-codegen-dev.yml', 'DEFAULT_GROUP', '## spring security 配置\nsecurity:\n oauth2:\n client:\n client-id: ENC(gPFcUOmJm8WqM3k3eSqS0Q==)\n client-secret: ENC(gPFcUOmJm8WqM3k3eSqS0Q==)\n scope: server\n# 数据源\nspring:\n datasource:\n type: com.alibaba.druid.pool.DruidDataSource\n druid:\n driver-class-name: com.mysql.cj.jdbc.Driver\n username: ${MYSQL_USER:root}\n password: ${MYSQL_PWD:root}\n url: jdbc:mysql://${MYSQL_HOST:pigx-mysql}:${MYSQL_PORT:3306}/${MYSQL_DB:pigxx_codegen}?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true\n resources:\n static-locations: classpath:/static/,classpath:/views/\n\n# 租户表维护\npigx:\n tenant:\n column: tenant_id\n tables:\n - gen_datasource_conf\n - gen_form_conf', 'ed93a557f5709d65bb45c14e80c7e9e1', '2019-04-18 02:12:10', '2022-01-27 21:27:50', 'nacos', '127.0.0.1', '', '', '代码生成', 'null', 'null', 'yaml', 'null'); INSERT INTO `config_info` VALUES (4, 'pigx-daemon-elastic-job-dev.yml', 'DEFAULT_GROUP', '## spring security 配置\nsecurity:\n oauth2:\n client:\n client-id: ENC(tz2NM4GcmnE7sNJTYL8ZSg==)\n client-secret: ENC(tz2NM4GcmnE7sNJTYL8ZSg==)\n scope: server\n## 定时任务\n# 数据源\nspring:\n datasource:\n type: com.alibaba.druid.pool.DruidDataSource\n druid:\n driver-class-name: com.mysql.cj.jdbc.Driver\n username: ${MYSQL_USER:root}\n password: ${MYSQL_PWD:root}\n url: jdbc:mysql://${MYSQL_HOST:pigx-mysql}:${MYSQL_PORT:3306}/${MYSQL_DB:pigxx_job}?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true', '4124589805657db024b20772cccf57f5', '2019-04-18 02:12:57', '2020-11-09 16:18:05', NULL, '172.16.1.198', '', '', '定时任务-elastic-job配置', 'null', 'null', 'yaml', 'null'); diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PermitAllUrlResolver.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PermitAllUrlResolver.java index 74f2e3a00..87084def8 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PermitAllUrlResolver.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PermitAllUrlResolver.java @@ -87,8 +87,8 @@ public class PermitAllUrlResolver implements InitializingBean { // 2. 当类上不包含 @Inner 注解则获取该方法的注解 if (controller == null) { Inner method = AnnotationUtils.findAnnotation(handlerMethod.getMethod(), Inner.class); - Optional.ofNullable(method).ifPresent(inner -> info.getPatternsCondition().getPatterns() - .forEach(url -> this.filterPath(url, info, map))); + Optional.ofNullable(method).ifPresent(inner -> Objects.requireNonNull(info.getPathPatternsCondition()) + .getPatternValues().forEach(url -> this.filterPath(url, info, map))); continue; } @@ -97,7 +97,8 @@ public class PermitAllUrlResolver implements InitializingBean { Method[] methods = beanType.getDeclaredMethods(); Method method = handlerMethod.getMethod(); if (ArrayUtil.contains(methods, method)) { - info.getPatternsCondition().getPatterns().forEach(url -> filterPath(url, info, map)); + Objects.requireNonNull(info.getPathPatternsCondition()).getPatternValues() + .forEach(url -> filterPath(url, info, map)); } } @@ -155,7 +156,7 @@ public class PermitAllUrlResolver implements InitializingBean { } // 如果请求方法路径匹配 - Set patterns = info.getPatternsCondition().getPatterns(); + Set patterns = Objects.requireNonNull(info.getPathPatternsCondition()).getPatternValues(); for (String pattern : patterns) { // 跳过自身 if (StrUtil.equals(url, pattern)) {