This is an automated email from the ASF dual-hosted git repository.

likeguo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 19c0fb228 [ISSUE #4399]  check rule uri condition on save. (#4403)
19c0fb228 is described below

commit 19c0fb228a31bc9bb636f5836f326342ff547c19
Author: iwangjie <[email protected]>
AuthorDate: Mon Mar 6 09:12:11 2023 +0800

    [ISSUE #4399]  check rule uri condition on save. (#4403)
    
    * check rule uri condition on save.
    
    * review
    
    * collections no longer
    
    * fix ci
    
    ---------
    
    Co-authored-by: moremind <[email protected]>
    Co-authored-by: likeguo <[email protected]>
---
 .../java/org/apache/shenyu/admin/service/RuleService.java  | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/RuleService.java 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/RuleService.java
index b5d1c506e..9680bc8d5 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/RuleService.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/RuleService.java
@@ -18,6 +18,8 @@
 package org.apache.shenyu.admin.service;
 
 import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.admin.exception.ShenyuAdminException;
+import org.apache.shenyu.admin.model.dto.RuleConditionDTO;
 import org.apache.shenyu.admin.model.dto.RuleDTO;
 import org.apache.shenyu.admin.model.entity.RuleDO;
 import org.apache.shenyu.admin.model.page.CommonPager;
@@ -25,6 +27,8 @@ import org.apache.shenyu.admin.model.query.RuleQuery;
 import org.apache.shenyu.admin.model.query.RuleQueryCondition;
 import org.apache.shenyu.admin.model.vo.RuleVO;
 import org.apache.shenyu.common.dto.RuleData;
+import org.apache.shenyu.common.enums.ParamTypeEnum;
+import org.springframework.web.util.pattern.PathPatternParser;
 
 import java.util.List;
 
@@ -48,6 +52,16 @@ public interface RuleService extends 
PageService<RuleQueryCondition, RuleVO> {
      * @return rows int
      */
     default int createOrUpdate(final RuleDTO ruleDTO) {
+        // check rule uri condition
+        try {
+            final List<RuleConditionDTO> ruleConditions = 
ruleDTO.getRuleConditions();
+            ruleConditions.stream()
+                    .filter(conditionData -> 
ParamTypeEnum.URI.getName().equals(conditionData.getParamType()))
+                    .map(RuleConditionDTO::getParamValue)
+                    .forEach(PathPatternParser.defaultInstance::parse);
+        } catch (Exception e) {
+            throw new ShenyuAdminException("uri validation of Condition 
failed, please check.");
+        }
         return StringUtils.isBlank(ruleDTO.getId()) ? create(ruleDTO) : 
update(ruleDTO);
     }
     

Reply via email to