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

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


The following commit(s) were added to refs/heads/master by this push:
     new 0c2719a  [ISSUE: #2956] valid parm in aop auth (#2973)
0c2719a is described below

commit 0c2719aeac58e6c2cf84b3366f8d3fc063f88f23
Author: likeguo <[email protected]>
AuthorDate: Fri Mar 4 11:22:49 2022 +0800

    [ISSUE: #2956] valid parm in aop auth (#2973)
    
    * valid parm in aop auth
    
    * valid parm in aop auth
    
    * valid parm in aop auth
    
    * valid parm in aop auth
    
    * valid parm in aop auth
---
 .../http/http-debug-app-auth-controller-api.http   | 72 +++++++++++++++++++++
 .../shenyu/admin/controller/AppAuthController.java | 50 +++++++++------
 .../apache/shenyu/admin/mapper/AppAuthMapper.java  | 55 ++++++++++------
 .../apache/shenyu/admin/mapper/AuthPathMapper.java | 34 ++++++----
 .../apache/shenyu/admin/model/dto/AppAuthDTO.java  | 74 ++++++++++++----------
 .../shenyu/admin/model/dto/AuthPathWarpDTO.java    |  8 ++-
 .../admin/service/impl/AppAuthServiceImpl.java     |  3 -
 .../provider/AppKeyProvider.java}                  | 35 +++++-----
 .../shenyu/admin/utils/PluginHandleH2Trigger.java  |  2 +-
 .../shenyu/admin/validation/ExistProvider.java     |  9 ---
 .../validation/validator/ExistedValidator.java     |  2 +-
 .../src/main/resources/mappers/app-auth-sqlmap.xml |  8 +++
 .../main/resources/mappers/auth-path-sqlmap.xml    |  4 ++
 .../admin/controller/AppAuthControllerTest.java    | 39 +++++++++---
 .../shenyu/admin/service/AppAuthServiceTest.java   | 19 +++---
 15 files changed, 281 insertions(+), 133 deletions(-)

diff --git a/shenyu-admin/src/http/http-debug-app-auth-controller-api.http 
b/shenyu-admin/src/http/http-debug-app-auth-controller-api.http
new file mode 100644
index 0000000..eb34ec7
--- /dev/null
+++ b/shenyu-admin/src/http/http-debug-app-auth-controller-api.http
@@ -0,0 +1,72 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# if you debug api, replace your own token
+
+### updateSk
+GET http://localhost:9095/appAuth/updateSk?appKey=123&appSecret=123
+Accept: application/json
+Content-Type: application/json
+X-Access-Token: 
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6ImFkbWluIiwiZXhwIjoxNjQ2MzIyMTI4fQ.amilvuSJfMM-qt9bYsEr-Ih12NKC9aK-3mB-VUq-fdo
+
+{
+  "id": 123,
+  "name": "order"
+}
+
+### app auth list by page
+GET http://localhost:9095/appAuth/findPageByQuery?currentPage=1&pageSize=10
+Accept: application/json
+Content-Type: application/json
+X-Access-Token: 
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6ImFkbWluIiwiZXhwIjoxNjQ2MzIyMTI4fQ.amilvuSJfMM-qt9bYsEr-Ih12NKC9aK-3mB-VUq-fdo
+
+
+### app auth detail
+GET http://localhost:9095/appAuth/detail?id=12
+Accept: application/json
+Content-Type: application/json
+X-Access-Token: 
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6ImFkbWluIiwiZXhwIjoxNjQ2MzIyMTI4fQ.amilvuSJfMM-qt9bYsEr-Ih12NKC9aK-3mB-VUq-fdo
+
+### app auth update detail
+POST http://localhost:9095/appAuth/updateDetail
+Accept: application/json
+Content-Type: application/json
+X-Access-Token: 
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6ImFkbWluIiwiZXhwIjoxNjQ2MzIyMTI4fQ.amilvuSJfMM-qt9bYsEr-Ih12NKC9aK-3mB-VUq-fdo
+
+{
+  "id": 1,
+  "appKey": "12",
+  "appSecret": "appSecret"
+}
+
+### app auth detail path
+GET http://localhost:9095/appAuth/detailPath?id=12
+Accept: application/json
+Content-Type: application/json
+X-Access-Token: 
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6ImFkbWluIiwiZXhwIjoxNjQ2MzIyMTI4fQ.amilvuSJfMM-qt9bYsEr-Ih12NKC9aK-3mB-VUq-fdo
+
+### app auth update detail path
+POST http://localhost:9095/appAuth/updateDetailPath
+Accept: application/json
+Content-Type: application/json
+X-Access-Token: 
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6ImFkbWluIiwiZXhwIjoxNjQ2MzIyMTI4fQ.amilvuSJfMM-qt9bYsEr-Ih12NKC9aK-3mB-VUq-fdo
+
+{
+  "id": 1,
+  "authPathDTOList": [
+  ]
+}
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/AppAuthController.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/AppAuthController.java
index c115ea6..e30a696 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/AppAuthController.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/AppAuthController.java
@@ -18,6 +18,8 @@
 package org.apache.shenyu.admin.controller;
 
 import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.admin.mapper.AppAuthMapper;
+import org.apache.shenyu.admin.mapper.AuthPathMapper;
 import org.apache.shenyu.admin.model.dto.AppAuthDTO;
 import org.apache.shenyu.admin.model.dto.AuthApplyDTO;
 import org.apache.shenyu.admin.model.dto.AuthPathWarpDTO;
@@ -28,7 +30,9 @@ import org.apache.shenyu.admin.model.query.AppAuthQuery;
 import org.apache.shenyu.admin.model.result.ShenyuAdminResult;
 import org.apache.shenyu.admin.model.vo.AppAuthVO;
 import org.apache.shenyu.admin.service.AppAuthService;
+import org.apache.shenyu.admin.service.provider.AppKeyProvider;
 import org.apache.shenyu.admin.utils.ShenyuResultMessage;
+import org.apache.shenyu.admin.validation.annotation.Existed;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -41,6 +45,7 @@ import org.springframework.web.bind.annotation.RestController;
 import javax.validation.Valid;
 import javax.validation.constraints.NotBlank;
 import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
 import java.util.List;
 
 /**
@@ -50,13 +55,13 @@ import java.util.List;
 @RestController
 @RequestMapping("/appAuth")
 public class AppAuthController {
-
+    
     private final AppAuthService appAuthService;
-
+    
     public AppAuthController(final AppAuthService appAuthService) {
         this.appAuthService = appAuthService;
     }
-
+    
     /**
      * Apply App auth.
      *
@@ -71,7 +76,7 @@ public class AppAuthController {
         }
         return appAuthService.applyCreate(authApplyDTO);
     }
-
+    
     /**
      * Update sk of App auth.
      *
@@ -80,10 +85,13 @@ public class AppAuthController {
      * @return the shenyu result
      */
     @GetMapping("/updateSk")
-    public ShenyuAdminResult updateSk(@RequestParam("appKey") final String 
appKey, @RequestParam("appSecret") final String appSecret) {
+    public ShenyuAdminResult updateSk(@RequestParam("appKey")
+                                      @Existed(message = "app key not existed",
+                                              provider = AppKeyProvider.class) 
final String appKey,
+                                      @RequestParam("appSecret") final String 
appSecret) {
         return appAuthService.updateAppSecretByAppKey(appKey, appSecret);
     }
-
+    
     /**
      * Find App auth page by query.
      *
@@ -95,7 +103,9 @@ public class AppAuthController {
      */
     @GetMapping("/findPageByQuery")
     @RequiresPermissions("system:authen:list")
-    public ShenyuAdminResult findPageByQuery(final String appKey, final String 
phone, final Integer currentPage, final Integer pageSize) {
+    public ShenyuAdminResult findPageByQuery(final String appKey, final String 
phone,
+                                             @NotNull(message = "currentPage 
not null") final Integer currentPage,
+                                             @NotNull(message = "pageSize not 
null") final Integer pageSize) {
         AppAuthQuery query = new AppAuthQuery();
         query.setPhone(phone);
         query.setAppKey(appKey);
@@ -103,7 +113,7 @@ public class AppAuthController {
         CommonPager<AppAuthVO> commonPager = appAuthService.listByPage(query);
         return ShenyuAdminResult.success(ShenyuResultMessage.QUERY_SUCCESS, 
commonPager);
     }
-
+    
     /**
      * Get detail of App auth.
      *
@@ -112,10 +122,12 @@ public class AppAuthController {
      */
     @GetMapping("/detail")
     @RequiresPermissions("system:authen:editResourceDetails")
-    public ShenyuAdminResult detail(@RequestParam("id") final String id) {
+    public ShenyuAdminResult detail(@RequestParam("id")
+                                    @Existed(message = "app key not existed",
+                                            provider = AppAuthMapper.class) 
final String id) {
         return ShenyuAdminResult.success(ShenyuResultMessage.DETAIL_SUCCESS, 
appAuthService.findById(id));
     }
-
+    
     /**
      * Update App auth.
      *
@@ -124,10 +136,10 @@ public class AppAuthController {
      */
     @PostMapping("/updateDetail")
     @RequiresPermissions("system:authen:edit")
-    public ShenyuAdminResult updateDetail(@RequestBody final AppAuthDTO 
appAuthDTO) {
+    public ShenyuAdminResult updateDetail(@RequestBody @Valid final AppAuthDTO 
appAuthDTO) {
         return appAuthService.updateDetail(appAuthDTO);
     }
-
+    
     /**
      * Detail path of App auth.
      *
@@ -136,10 +148,12 @@ public class AppAuthController {
      */
     @GetMapping("/detailPath")
     @RequiresPermissions("system:authen:editResourceDetails")
-    public ShenyuAdminResult detailPath(@RequestParam("id") final @NotBlank 
String id) {
+    public ShenyuAdminResult detailPath(@RequestParam("id")
+                                        @Existed(message = "app key not 
existed", provider = AuthPathMapper.class)
+                                        @NotBlank final String id) {
         return ShenyuAdminResult.success(ShenyuResultMessage.DETAIL_SUCCESS, 
appAuthService.detailPath(id));
     }
-
+    
     /**
      * Update detail path.
      *
@@ -148,10 +162,10 @@ public class AppAuthController {
      */
     @PostMapping("/updateDetailPath")
     @RequiresPermissions("system:authen:editResourceDetails")
-    public ShenyuAdminResult updateDetailPath(@RequestBody final 
AuthPathWarpDTO authPathWarpDTO) {
+    public ShenyuAdminResult updateDetailPath(@RequestBody @Valid final 
AuthPathWarpDTO authPathWarpDTO) {
         return appAuthService.updateDetailPath(authPathWarpDTO);
     }
-
+    
     /**
      * delete application authorities.
      *
@@ -164,7 +178,7 @@ public class AppAuthController {
         Integer deleteCount = appAuthService.delete(ids);
         return ShenyuAdminResult.success(ShenyuResultMessage.DELETE_SUCCESS, 
deleteCount);
     }
-
+    
     /**
      * Batch enabled App auth.
      *
@@ -180,7 +194,7 @@ public class AppAuthController {
         }
         return ShenyuAdminResult.success(ShenyuResultMessage.ENABLE_SUCCESS);
     }
-
+    
     /**
      * Sync App auth data.
      *
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/AppAuthMapper.java 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/AppAuthMapper.java
index 4671f07..4906724 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/AppAuthMapper.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/AppAuthMapper.java
@@ -21,7 +21,9 @@ import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.shenyu.admin.model.entity.AppAuthDO;
 import org.apache.shenyu.admin.model.query.AppAuthQuery;
+import org.apache.shenyu.admin.validation.ExistProvider;
 
+import java.io.Serializable;
 import java.util.List;
 import java.util.Set;
 
@@ -29,8 +31,25 @@ import java.util.Set;
  * AppAuthMapper.
  */
 @Mapper
-public interface AppAuthMapper {
-
+public interface AppAuthMapper extends ExistProvider {
+    
+    /**
+     * exited.
+     *
+     * @param id id.
+     * @return existed
+     */
+    @Override
+    Boolean existed(@Param("id") Serializable id);
+    
+    /**
+     * exited.
+     *
+     * @param appKey app key
+     * @return existed
+     */
+    Boolean appKeyExisted(@Param("appKey") Serializable appKey);
+    
     /**
      * select application authority by id.
      *
@@ -38,7 +57,7 @@ public interface AppAuthMapper {
      * @return {@linkplain AppAuthDO}
      */
     AppAuthDO selectById(String id);
-
+    
     /**
      * select application authority by id.
      *
@@ -46,7 +65,7 @@ public interface AppAuthMapper {
      * @return {@linkplain AppAuthDO}
      */
     List<AppAuthDO> selectByIds(List<String> ids);
-
+    
     /**
      * select application authority by query.
      *
@@ -54,14 +73,14 @@ public interface AppAuthMapper {
      * @return {@linkplain List}
      */
     List<AppAuthDO> selectByQuery(AppAuthQuery appAuthQuery);
-
+    
     /**
      * select all.
      *
      * @return {@linkplain List}
      */
     List<AppAuthDO> selectAll();
-
+    
     /**
      * count application authority by query.
      *
@@ -69,7 +88,7 @@ public interface AppAuthMapper {
      * @return {@linkplain Integer}
      */
     Integer countByQuery(AppAuthQuery appAuthQuery);
-
+    
     /**
      * insert application authority.
      *
@@ -77,7 +96,7 @@ public interface AppAuthMapper {
      * @return rows int
      */
     int insert(AppAuthDO appAuthDO);
-
+    
     /**
      * insert selective application authority.
      *
@@ -85,7 +104,7 @@ public interface AppAuthMapper {
      * @return rows int
      */
     int insertSelective(AppAuthDO appAuthDO);
-
+    
     /**
      * update application authority.
      *
@@ -93,7 +112,7 @@ public interface AppAuthMapper {
      * @return rows int
      */
     int update(AppAuthDO appAuthDO);
-
+    
     /**
      * Update enable int.
      *
@@ -101,17 +120,17 @@ public interface AppAuthMapper {
      * @return the int
      */
     int updateEnable(AppAuthDO appAuthDO);
-
+    
     /**
      * update enable batch.
      *
-     * @param idSet the ids
+     * @param idSet   the ids
      * @param enabled the status
      * @return the count
      */
     int updateEnableBatch(@Param("idSet") Set<String> idSet, @Param("enabled") 
Boolean enabled);
-
-
+    
+    
     /**
      * Update app secret by app key int.
      *
@@ -120,7 +139,7 @@ public interface AppAuthMapper {
      * @return the int
      */
     int updateAppSecretByAppKey(@Param("appKey") String appKey, 
@Param("appSecret") String appSecret);
-
+    
     /**
      * update selective application authority.
      *
@@ -128,7 +147,7 @@ public interface AppAuthMapper {
      * @return rows int
      */
     int updateSelective(AppAuthDO appAuthDO);
-
+    
     /**
      * deleteSelector application authority.
      *
@@ -136,7 +155,7 @@ public interface AppAuthMapper {
      * @return rows int
      */
     int delete(String id);
-
+    
     /**
      * deleteSelector application authority.
      *
@@ -144,7 +163,7 @@ public interface AppAuthMapper {
      * @return rows int
      */
     int deleteByIds(List<String> ids);
-
+    
     /**
      * Find by app key app auth do.
      *
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/AuthPathMapper.java 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/AuthPathMapper.java
index e7892f8..1cea256 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/AuthPathMapper.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/AuthPathMapper.java
@@ -20,7 +20,9 @@ package org.apache.shenyu.admin.mapper;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.shenyu.admin.model.entity.AuthPathDO;
+import org.apache.shenyu.admin.validation.ExistProvider;
 
+import java.io.Serializable;
 import java.util.List;
 import java.util.Set;
 
@@ -28,8 +30,17 @@ import java.util.Set;
  * The interface Auth path mapper.
  */
 @Mapper
-public interface AuthPathMapper {
-
+public interface AuthPathMapper extends ExistProvider {
+    
+    /**
+     * existed.
+     *
+     * @param id id
+     * @return existed
+     */
+    @Override
+    Boolean existed(@Param("id") Serializable id);
+    
     /**
      * Save int.
      *
@@ -37,7 +48,7 @@ public interface AuthPathMapper {
      * @return the int
      */
     int save(AuthPathDO authPathDO);
-
+    
     /**
      * Batch save int.
      *
@@ -45,7 +56,7 @@ public interface AuthPathMapper {
      * @return the int
      */
     int batchSave(@Param("authPathDOList") List<AuthPathDO> authPathDOList);
-
+    
     /**
      * Update int.
      *
@@ -53,7 +64,7 @@ public interface AuthPathMapper {
      * @return the int
      */
     int update(AuthPathDO authPathDO);
-
+    
     /**
      * Find by auth id list.
      *
@@ -61,14 +72,15 @@ public interface AuthPathMapper {
      * @return the list
      */
     List<AuthPathDO> findByAuthId(String authId);
-
+    
     /**
      * find all the {@link AuthPathDO} by authIdList.
+     *
      * @param authIdSet batch auth id
      * @return the list
      */
     List<AuthPathDO> findByAuthIdList(@Param("authIdSet") Set<String> 
authIdSet);
-
+    
     /**
      * Find by auth id and app name list.
      *
@@ -77,8 +89,8 @@ public interface AuthPathMapper {
      * @return the list
      */
     List<AuthPathDO> findByAuthIdAndAppName(@Param("authId") String authId, 
@Param("appName") String appName);
-
-
+    
+    
     /**
      * Delete by auth id and app name int.
      *
@@ -87,7 +99,7 @@ public interface AuthPathMapper {
      * @return the int
      */
     int deleteByAuthIdAndAppName(@Param("authId") String authId, 
@Param("appName") String appName);
-
+    
     /**
      * Delete by auth id int.
      *
@@ -95,7 +107,7 @@ public interface AuthPathMapper {
      * @return the int
      */
     int deleteByAuthId(@Param("authId") String authId);
-
+    
     /**
      * Delete by auth id int.
      *
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/AppAuthDTO.java 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/AppAuthDTO.java
index 1725a9c..1488362 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/AppAuthDTO.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/AppAuthDTO.java
@@ -17,6 +17,10 @@
 
 package org.apache.shenyu.admin.model.dto;
 
+import org.apache.shenyu.admin.mapper.AppAuthMapper;
+import org.apache.shenyu.admin.validation.annotation.Existed;
+
+import javax.validation.constraints.NotNull;
 import java.io.Serializable;
 import java.util.List;
 import java.util.Objects;
@@ -25,44 +29,48 @@ import java.util.Objects;
  * this is application authority from by web front.
  */
 public class AppAuthDTO implements Serializable {
-
+    
     private static final long serialVersionUID = 3906547569699874743L;
-
+    
     /**
      * primary key.
      */
+    @NotNull(message = "app auth id not null")
+    @Existed(message = "app auth is not existed", provider = 
AppAuthMapper.class)
     private String id;
-
+    
     /**
      * application key.
      */
+    @NotNull(message = "app auth appKey not null")
     private String appKey;
-
+    
     /**
      * encryption secret.
      */
+    @NotNull(message = "app auth appSecret not null")
     private String appSecret;
-
+    
     private String userId;
-
+    
     private String phone;
-
+    
     private String extInfo;
-
+    
     /**
      * whether open authPath.
      */
     private Boolean open;
-
+    
     /**
      * whether enabled.
      */
     private Boolean enabled;
-
+    
     private List<AuthParamDTO> authParamDTOList;
-
+    
     private List<AuthPathDTO> authPathDTOList;
-
+    
     /**
      * Gets the value of id.
      *
@@ -71,7 +79,7 @@ public class AppAuthDTO implements Serializable {
     public String getId() {
         return id;
     }
-
+    
     /**
      * Sets the id.
      *
@@ -80,7 +88,7 @@ public class AppAuthDTO implements Serializable {
     public void setId(final String id) {
         this.id = id;
     }
-
+    
     /**
      * Gets the value of appKey.
      *
@@ -89,7 +97,7 @@ public class AppAuthDTO implements Serializable {
     public String getAppKey() {
         return appKey;
     }
-
+    
     /**
      * Sets the appKey.
      *
@@ -98,7 +106,7 @@ public class AppAuthDTO implements Serializable {
     public void setAppKey(final String appKey) {
         this.appKey = appKey;
     }
-
+    
     /**
      * Gets the value of appSecret.
      *
@@ -107,7 +115,7 @@ public class AppAuthDTO implements Serializable {
     public String getAppSecret() {
         return appSecret;
     }
-
+    
     /**
      * Sets the appSecret.
      *
@@ -116,7 +124,7 @@ public class AppAuthDTO implements Serializable {
     public void setAppSecret(final String appSecret) {
         this.appSecret = appSecret;
     }
-
+    
     /**
      * Gets the value of userId.
      *
@@ -125,7 +133,7 @@ public class AppAuthDTO implements Serializable {
     public String getUserId() {
         return userId;
     }
-
+    
     /**
      * Sets the userId.
      *
@@ -134,7 +142,7 @@ public class AppAuthDTO implements Serializable {
     public void setUserId(final String userId) {
         this.userId = userId;
     }
-
+    
     /**
      * Gets the value of phone.
      *
@@ -143,7 +151,7 @@ public class AppAuthDTO implements Serializable {
     public String getPhone() {
         return phone;
     }
-
+    
     /**
      * Sets the phone.
      *
@@ -152,7 +160,7 @@ public class AppAuthDTO implements Serializable {
     public void setPhone(final String phone) {
         this.phone = phone;
     }
-
+    
     /**
      * Gets the value of extInfo.
      *
@@ -161,7 +169,7 @@ public class AppAuthDTO implements Serializable {
     public String getExtInfo() {
         return extInfo;
     }
-
+    
     /**
      * Sets the extInfo.
      *
@@ -170,7 +178,7 @@ public class AppAuthDTO implements Serializable {
     public void setExtInfo(final String extInfo) {
         this.extInfo = extInfo;
     }
-
+    
     /**
      * Gets the value of open.
      *
@@ -179,7 +187,7 @@ public class AppAuthDTO implements Serializable {
     public Boolean getOpen() {
         return open;
     }
-
+    
     /**
      * Sets the open.
      *
@@ -188,7 +196,7 @@ public class AppAuthDTO implements Serializable {
     public void setOpen(final Boolean open) {
         this.open = open;
     }
-
+    
     /**
      * Gets the value of enabled.
      *
@@ -197,7 +205,7 @@ public class AppAuthDTO implements Serializable {
     public Boolean getEnabled() {
         return enabled;
     }
-
+    
     /**
      * Sets the enabled.
      *
@@ -206,7 +214,7 @@ public class AppAuthDTO implements Serializable {
     public void setEnabled(final Boolean enabled) {
         this.enabled = enabled;
     }
-
+    
     /**
      * Gets the value of authParamDTOList.
      *
@@ -215,7 +223,7 @@ public class AppAuthDTO implements Serializable {
     public List<AuthParamDTO> getAuthParamDTOList() {
         return authParamDTOList;
     }
-
+    
     /**
      * Sets the authParamDTOList.
      *
@@ -224,7 +232,7 @@ public class AppAuthDTO implements Serializable {
     public void setAuthParamDTOList(final List<AuthParamDTO> authParamDTOList) 
{
         this.authParamDTOList = authParamDTOList;
     }
-
+    
     /**
      * Gets the value of authPathDTOList.
      *
@@ -233,7 +241,7 @@ public class AppAuthDTO implements Serializable {
     public List<AuthPathDTO> getAuthPathDTOList() {
         return authPathDTOList;
     }
-
+    
     /**
      * Sets the authPathDTOList.
      *
@@ -242,7 +250,7 @@ public class AppAuthDTO implements Serializable {
     public void setAuthPathDTOList(final List<AuthPathDTO> authPathDTOList) {
         this.authPathDTOList = authPathDTOList;
     }
-
+    
     @Override
     public boolean equals(final Object o) {
         if (this == o) {
@@ -263,7 +271,7 @@ public class AppAuthDTO implements Serializable {
                 && Objects.equals(authParamDTOList, that.authParamDTOList)
                 && Objects.equals(authPathDTOList, that.authPathDTOList);
     }
-
+    
     @Override
     public int hashCode() {
         return Objects.hash(id, appKey, appSecret, userId, phone, extInfo, 
open, enabled, authParamDTOList, authPathDTOList);
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/AuthPathWarpDTO.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/AuthPathWarpDTO.java
index ee7050f..4b74439 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/AuthPathWarpDTO.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/AuthPathWarpDTO.java
@@ -17,6 +17,10 @@
 
 package org.apache.shenyu.admin.model.dto;
 
+import org.apache.shenyu.admin.mapper.AuthPathMapper;
+import org.apache.shenyu.admin.validation.annotation.Existed;
+
+import javax.validation.constraints.NotEmpty;
 import java.io.Serializable;
 import java.util.List;
 import java.util.Objects;
@@ -27,9 +31,11 @@ import java.util.Objects;
 public class AuthPathWarpDTO implements Serializable {
 
     private static final long serialVersionUID = -3167442906221294444L;
-
+    
+    @Existed(message = "app key not existed", provider = AuthPathMapper.class)
     private String id;
 
+    @NotEmpty(message = "auth path is not empty")
     private List<AuthPathDTO> authPathDTOList;
 
     /**
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/AppAuthServiceImpl.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/AppAuthServiceImpl.java
index 862ad34..b2b6a15 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/AppAuthServiceImpl.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/AppAuthServiceImpl.java
@@ -166,9 +166,6 @@ public class AppAuthServiceImpl implements AppAuthService {
     @Override
     @Transactional(rollbackFor = Exception.class)
     public ShenyuAdminResult updateDetail(final AppAuthDTO appAuthDTO) {
-        if (StringUtils.isAnyBlank(appAuthDTO.getAppKey(), 
appAuthDTO.getAppSecret(), appAuthDTO.getId())) {
-            return 
ShenyuAdminResult.error(ShenyuResultMessage.PARAMETER_ERROR);
-        }
         AppAuthDO appAuthDO = AppAuthTransfer.INSTANCE.mapToEntity(appAuthDTO);
         appAuthMapper.update(appAuthDO);
         List<AuthParamDTO> authParamDTOList = appAuthDTO.getAuthParamDTOList();
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/validation/ExistProvider.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/provider/AppKeyProvider.java
similarity index 60%
copy from 
shenyu-admin/src/main/java/org/apache/shenyu/admin/validation/ExistProvider.java
copy to 
shenyu-admin/src/main/java/org/apache/shenyu/admin/service/provider/AppKeyProvider.java
index 7dff44f..c0df93d 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/validation/ExistProvider.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/provider/AppKeyProvider.java
@@ -15,31 +15,28 @@
  * limitations under the License.
  */
 
-package org.apache.shenyu.admin.validation;
+package org.apache.shenyu.admin.service.provider;
+
+import org.apache.shenyu.admin.mapper.AppAuthMapper;
+import org.apache.shenyu.admin.validation.ExistProvider;
+import org.springframework.stereotype.Component;
 
 import java.io.Serializable;
 
 /**
- * ExistProvider.
+ * AppKeyProvider.
  */
-public interface ExistProvider {
+@Component
+public class AppKeyProvider implements ExistProvider {
     
-    /**
-     * not existed.
-     *
-     * @param key key
-     * @return not exited
-     */
-    default boolean notExisted(final Serializable key) {
-        return !Boolean.TRUE.equals(existed(key));
-    }
+    private final AppAuthMapper appAuthMapper;
     
+    public AppKeyProvider(final AppAuthMapper appAuthMapper) {
+        this.appAuthMapper = appAuthMapper;
+    }
     
-    /**
-     * existed.
-     *
-     * @param key key
-     * @return existed, if not existed nullable
-     */
-    Boolean existed(Serializable key);
+    @Override
+    public Boolean existed(final Serializable key) {
+        return appAuthMapper.existed(key);
+    }
 }
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/PluginHandleH2Trigger.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/PluginHandleH2Trigger.java
index b9e326d..eb04a89 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/PluginHandleH2Trigger.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/PluginHandleH2Trigger.java
@@ -46,7 +46,7 @@ public class PluginHandleH2Trigger implements Trigger {
                         + " VALUES ( ?, ?, ?, ?, ?, ?, ?, ?)")) {
             BaseTrigger.sqlExecute(newRow, statement);
         } catch (ShenyuException e) {
-            LOG.error("PluginHandleH2Trigger Error:" + e);
+            LOG.error("PluginHandleH2Trigger Error:", e);
         }
     }
 
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/validation/ExistProvider.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/validation/ExistProvider.java
index 7dff44f..5648945 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/validation/ExistProvider.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/validation/ExistProvider.java
@@ -24,15 +24,6 @@ import java.io.Serializable;
  */
 public interface ExistProvider {
     
-    /**
-     * not existed.
-     *
-     * @param key key
-     * @return not exited
-     */
-    default boolean notExisted(final Serializable key) {
-        return !Boolean.TRUE.equals(existed(key));
-    }
     
     
     /**
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/validation/validator/ExistedValidator.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/validation/validator/ExistedValidator.java
index b114a60..957c010 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/validation/validator/ExistedValidator.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/validation/validator/ExistedValidator.java
@@ -54,7 +54,7 @@ public class ExistedValidator implements 
ConstraintValidator<Existed, Serializab
         if (Objects.isNull(annotation.provider())) {
             throw new ResourceNotFoundException("the validation ExistProvider 
is not found");
         }
-        return !getExistProvider().notExisted(value);
+        return Boolean.TRUE.equals(getExistProvider().existed(value));
     }
     
     private ExistProvider getExistProvider() {
diff --git a/shenyu-admin/src/main/resources/mappers/app-auth-sqlmap.xml 
b/shenyu-admin/src/main/resources/mappers/app-auth-sqlmap.xml
index b143e42..a6e72c7 100644
--- a/shenyu-admin/src/main/resources/mappers/app-auth-sqlmap.xml
+++ b/shenyu-admin/src/main/resources/mappers/app-auth-sqlmap.xml
@@ -94,6 +94,14 @@
         from app_auth
     </select>
 
+    <select id="existed" resultType="java.lang.Boolean">
+        select true from app_auth where id = #{id} limit 1
+    </select>
+
+    <select id="appKeyExisted" resultType="java.lang.Boolean">
+        select true from app_auth where app_key = #{appKey} limit 1
+    </select>
+
     <insert id="insert" 
parameterType="org.apache.shenyu.admin.model.entity.AppAuthDO">
         insert into app_auth
         (id,
diff --git a/shenyu-admin/src/main/resources/mappers/auth-path-sqlmap.xml 
b/shenyu-admin/src/main/resources/mappers/auth-path-sqlmap.xml
index 99b9d4e..bc5c177 100644
--- a/shenyu-admin/src/main/resources/mappers/auth-path-sqlmap.xml
+++ b/shenyu-admin/src/main/resources/mappers/auth-path-sqlmap.xml
@@ -58,6 +58,10 @@
         and app_name = #{appName,jdbcType=VARCHAR}
     </select>
 
+    <select id="existed" resultType="java.lang.Boolean">
+        select true from auth_path where id = #{id} limit 1
+    </select>
+
 
     <insert id="save" 
parameterType="org.apache.shenyu.admin.model.entity.AuthParamDO">
         insert into auth_path
diff --git 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/AppAuthControllerTest.java
 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/AppAuthControllerTest.java
index e705382..2265206 100644
--- 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/AppAuthControllerTest.java
+++ 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/AppAuthControllerTest.java
@@ -18,30 +18,33 @@
 package org.apache.shenyu.admin.controller;
 
 import org.apache.commons.lang3.StringUtils;
-import org.apache.shenyu.admin.model.dto.AuthApplyDTO;
+import org.apache.shenyu.admin.mapper.AppAuthMapper;
+import org.apache.shenyu.admin.mapper.AuthPathMapper;
 import org.apache.shenyu.admin.model.dto.AppAuthDTO;
+import org.apache.shenyu.admin.model.dto.AuthApplyDTO;
 import org.apache.shenyu.admin.model.dto.AuthPathDTO;
 import org.apache.shenyu.admin.model.dto.AuthPathWarpDTO;
 import org.apache.shenyu.admin.model.dto.BatchCommonDTO;
-import org.apache.shenyu.admin.service.AppAuthService;
-import org.apache.shenyu.admin.model.vo.AppAuthVO;
 import org.apache.shenyu.admin.model.page.CommonPager;
 import org.apache.shenyu.admin.model.page.PageParameter;
 import org.apache.shenyu.admin.model.query.AppAuthQuery;
 import org.apache.shenyu.admin.model.result.ShenyuAdminResult;
-import org.apache.shenyu.admin.utils.ShenyuResultMessage;
+import org.apache.shenyu.admin.model.vo.AppAuthVO;
 import org.apache.shenyu.admin.model.vo.AuthPathVO;
+import org.apache.shenyu.admin.service.AppAuthService;
+import org.apache.shenyu.admin.spring.SpringBeanUtils;
+import org.apache.shenyu.admin.utils.ShenyuResultMessage;
 import org.apache.shenyu.common.constant.AdminConstants;
+import org.apache.shenyu.common.exception.CommonErrorCode;
 import org.apache.shenyu.common.utils.DateUtils;
 import org.apache.shenyu.common.utils.GsonUtils;
-import org.apache.shenyu.common.exception.CommonErrorCode;
-
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.http.MediaType;
 import org.springframework.test.web.servlet.MockMvc;
 import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
@@ -55,6 +58,8 @@ import java.util.List;
 
 import static org.hamcrest.core.Is.is;
 import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 import static 
org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
 import static 
org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
 
@@ -71,6 +76,12 @@ public final class AppAuthControllerTest {
 
     @Mock
     private AppAuthService appAuthService;
+    
+    @Mock
+    private AuthPathMapper authPathMapper;
+    
+    @Mock
+    private AppAuthMapper appAuthMapper;
 
     private final AppAuthVO appAuthVO = new AppAuthVO("0001", "testAppKey", 
"testAppSecret",
             "testUser", "18600000000", "{\"extInfo\": \"test\"}",
@@ -79,7 +90,10 @@ public final class AppAuthControllerTest {
 
     @BeforeEach
     public void setUp() {
-        this.mockMvc = 
MockMvcBuilders.standaloneSetup(appAuthController).build();
+        this.mockMvc = MockMvcBuilders.standaloneSetup(appAuthController)
+                .setControllerAdvice(appAuthMapper)
+                .setControllerAdvice(authPathMapper)
+                .build();
     }
 
     @Test
@@ -168,9 +182,15 @@ public final class AppAuthControllerTest {
     public void testUpdateDetail() throws Exception {
         AppAuthDTO appAuthDTO = new AppAuthDTO();
         appAuthDTO.setId("0001");
+        appAuthDTO.setAppKey("app key");
+        appAuthDTO.setAppSecret("app secret");
         appAuthDTO.setPhone("18600000001");
         given(this.appAuthService.updateDetail(appAuthDTO)).willReturn(
                 ShenyuAdminResult.success(ShenyuResultMessage.UPDATE_SUCCESS));
+        ConfigurableApplicationContext context = 
mock(ConfigurableApplicationContext.class);
+        SpringBeanUtils.getInstance().setApplicationContext(context);
+        
when(SpringBeanUtils.getInstance().getBean(AppAuthMapper.class)).thenReturn(appAuthMapper);
+        when(appAuthMapper.existed(appAuthDTO.getId())).thenReturn(true);
         
this.mockMvc.perform(MockMvcRequestBuilders.post("/appAuth/updateDetail")
                 .contentType(MediaType.APPLICATION_JSON)
                 .content(GsonUtils.getInstance().toJson(appAuthDTO)))
@@ -206,7 +226,10 @@ public final class AppAuthControllerTest {
         final AuthPathWarpDTO authPathWarpDTO = new AuthPathWarpDTO();
         authPathWarpDTO.setId("0001");
         authPathWarpDTO.setAuthPathDTOList(authPathDTOS);
-
+        ConfigurableApplicationContext context = 
mock(ConfigurableApplicationContext.class);
+        SpringBeanUtils.getInstance().setApplicationContext(context);
+        
when(SpringBeanUtils.getInstance().getBean(AuthPathMapper.class)).thenReturn(authPathMapper);
+        when(authPathMapper.existed(authPathWarpDTO.getId())).thenReturn(true);
         
given(this.appAuthService.updateDetailPath(authPathWarpDTO)).willReturn(ShenyuAdminResult.success());
         
this.mockMvc.perform(MockMvcRequestBuilders.post("/appAuth/updateDetailPath")
                 .contentType(MediaType.APPLICATION_JSON)
diff --git 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/AppAuthServiceTest.java
 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/AppAuthServiceTest.java
index 7c89b0e..ca6d78d 100644
--- 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/AppAuthServiceTest.java
+++ 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/AppAuthServiceTest.java
@@ -19,26 +19,26 @@ package org.apache.shenyu.admin.service;
 
 import com.google.common.collect.Lists;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.admin.mapper.AppAuthMapper;
+import org.apache.shenyu.admin.mapper.AuthParamMapper;
+import org.apache.shenyu.admin.mapper.AuthPathMapper;
 import org.apache.shenyu.admin.model.dto.AppAuthDTO;
 import org.apache.shenyu.admin.model.dto.AuthApplyDTO;
-import org.apache.shenyu.admin.model.dto.AuthPathWarpDTO;
 import org.apache.shenyu.admin.model.dto.AuthParamDTO;
 import org.apache.shenyu.admin.model.dto.AuthPathDTO;
+import org.apache.shenyu.admin.model.dto.AuthPathWarpDTO;
 import org.apache.shenyu.admin.model.dto.BatchCommonDTO;
 import org.apache.shenyu.admin.model.entity.AppAuthDO;
 import org.apache.shenyu.admin.model.entity.AuthParamDO;
 import org.apache.shenyu.admin.model.entity.AuthPathDO;
-import org.apache.shenyu.admin.mapper.AppAuthMapper;
-import org.apache.shenyu.admin.mapper.AuthParamMapper;
-import org.apache.shenyu.admin.mapper.AuthPathMapper;
 import org.apache.shenyu.admin.model.page.CommonPager;
 import org.apache.shenyu.admin.model.page.PageParameter;
 import org.apache.shenyu.admin.model.query.AppAuthQuery;
 import org.apache.shenyu.admin.model.result.ShenyuAdminResult;
-import org.apache.shenyu.admin.service.impl.AppAuthServiceImpl;
-import org.apache.shenyu.admin.utils.ShenyuResultMessage;
 import org.apache.shenyu.admin.model.vo.AppAuthVO;
 import org.apache.shenyu.admin.model.vo.AuthPathVO;
+import org.apache.shenyu.admin.service.impl.AppAuthServiceImpl;
+import org.apache.shenyu.admin.utils.ShenyuResultMessage;
 import org.apache.shenyu.common.constant.AdminConstants;
 import org.apache.shenyu.common.dto.AppAuthData;
 import org.apache.shenyu.common.exception.CommonErrorCode;
@@ -57,11 +57,11 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.greaterThan;
 import static org.hamcrest.Matchers.greaterThanOrEqualTo;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.hamcrest.MatcherAssert.assertThat;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.BDDMockito.given;
@@ -108,10 +108,7 @@ public final class AppAuthServiceTest {
 
     @Test
     public void testUpdateDetail() {
-        AppAuthDTO appAuthDTO = new AppAuthDTO();
-        ShenyuAdminResult parameterErrorResult = 
this.appAuthService.updateDetail(appAuthDTO);
-        assertEquals(ShenyuResultMessage.PARAMETER_ERROR, 
parameterErrorResult.getMessage());
-        appAuthDTO = 
buildAppAuthDTO(UUIDUtils.getInstance().generateShortUuid());
+        AppAuthDTO appAuthDTO = 
buildAppAuthDTO(UUIDUtils.getInstance().generateShortUuid());
         List<AuthParamDTO> authParamDTOList = 
Collections.singletonList(buildAuthParamDTO());
         appAuthDTO.setAuthParamDTOList(authParamDTOList);
         ShenyuAdminResult successResult = 
this.appAuthService.updateDetail(appAuthDTO);

Reply via email to