Skip to content

Commit

Permalink
[fix admin #3090 ] Fix click on the "EditResourceDetails" button error (
Browse files Browse the repository at this point in the history
#3113)

* fix #3088 : Click on the EditResourceDetails button error

* fix #3088 : Click on the EditResourceDetails button error

* fix #3088 : Click on the EditResourceDetails button error

* fix #3088 : Click on the EditResourceDetails button error

* fix #3088 : Click on the EditResourceDetails button error

* fix #3088 : Click on the EditResourceDetails button error

* fix #3088 : Click on the EditResourceDetails button error

* [fix admin #3088] : Click on the EditResourceDetails button error

* [fix admin #3088] : Click on the EditResourceDetails button error

* [fix admin #3088] : Click on the EditResourceDetails button error

* [fix admin #3088] : Click on the EditResourceDetails button error

* Merge branch 'master' of github.com:apache/incubator-shenyu into fix-3090

# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.

Co-authored-by: andy.l.an <andy.l.an@yzw.cn>
Co-authored-by: admin <an88411980@gmail.com>
  • Loading branch information
3 people committed Mar 28, 2022
1 parent 40c5170 commit 04e2b33
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 20 deletions.
Expand Up @@ -143,15 +143,17 @@ public ShenyuAdminResult updateDetail(@RequestBody @Valid final AppAuthDTO appAu
/**
* Detail path of App auth.
*
* @param id the id
* @param authId the authId
* @return the shenyu result
*/
@GetMapping("/detailPath")
@RequiresPermissions("system:authen:editResourceDetails")
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));
@Existed(message = "auth path not existed",
providerMethodName = "existedByAuthId",
provider = AuthPathMapper.class)
@NotBlank final String authId) {
return ShenyuAdminResult.success(ShenyuResultMessage.DETAIL_SUCCESS, appAuthService.detailPath(authId));
}

/**
Expand Down
Expand Up @@ -40,7 +40,15 @@ public interface AuthPathMapper extends ExistProvider {
*/
@Override
Boolean existed(@Param("id") Serializable id);


/**
* existedByAuthId.
*
* @param authId authId
* @return java.lang.Boolean
*/
Boolean existedByAuthId(Serializable authId);

/**
* Save int.
*
Expand Down
Expand Up @@ -369,8 +369,8 @@ public AppAuthVO findById(final String id) {
}

@Override
public List<AuthPathVO> detailPath(final String id) {
List<AuthPathDO> authPathDOList = authPathMapper.findByAuthId(id);
public List<AuthPathVO> detailPath(final String authId) {
List<AuthPathDO> authPathDOList = authPathMapper.findByAuthId(authId);
if (CollectionUtils.isEmpty(authPathDOList)) {
return new ArrayList<>();
}
Expand Down
Expand Up @@ -72,7 +72,14 @@
* @return class
*/
Class<? extends ExistProvider> provider();


/**
* existed provider.
*
* @return class
*/
String providerMethodName() default "existed";

/**
* support groups.
*
Expand Down
Expand Up @@ -17,6 +17,7 @@

package org.apache.shenyu.admin.validation.validator;

import org.apache.commons.lang3.reflect.MethodUtils;
import org.apache.shenyu.admin.exception.ResourceNotFoundException;
import org.apache.shenyu.admin.spring.SpringBeanUtils;
import org.apache.shenyu.admin.validation.ExistProvider;
Expand All @@ -38,7 +39,7 @@ public class ExistedValidator implements ConstraintValidator<Existed, Serializab
* target annotation.
*/
private Existed annotation;

/**
* provider cache.
*/
Expand All @@ -54,16 +55,17 @@ public boolean isValid(final Serializable value, final ConstraintValidatorContex
if (Objects.isNull(annotation.provider())) {
throw new ResourceNotFoundException("the validation ExistProvider is not found");
}

if (annotation.nullOfIgnore() && Objects.isNull(value)) {
// null of ignore
return true;
}
if (annotation.reverse()) {
return !Boolean.TRUE.equals(getExistProvider().existed(value));
return !doValid(value);
}
return Boolean.TRUE.equals(getExistProvider().existed(value));
return doValid(value);
}

private ExistProvider getExistProvider() {
ExistProvider provider = providerCacheMap.get(annotation.provider().getName());
if (!Objects.isNull(provider)) {
Expand All @@ -73,4 +75,17 @@ private ExistProvider getExistProvider() {
providerCacheMap.put(annotation.provider().getName(), provider);
return provider;
}

private Boolean doValid(final Serializable value) {
Object provider = getExistProvider();
// custom providerMethod
if (!"existed".equals(annotation.providerMethodName())) {
try {
return Boolean.TRUE.equals(MethodUtils.invokeMethod(provider, annotation.providerMethodName(), value));
} catch (Exception e) {
throw new ResourceNotFoundException("the validation ExistProviderMethod invoked error");
}
}
return Boolean.TRUE.equals(getExistProvider().existed(value));
}
}
17 changes: 14 additions & 3 deletions shenyu-admin/src/main/resources/mappers/auth-path-sqlmap.xml
Expand Up @@ -70,7 +70,18 @@
WHERE id = #{id}
LIMIT 1
</select>


<select id="existedByAuthId" resultType="java.lang.Boolean">
SELECT
true
FROM
auth_path
WHERE
auth_id = #{authId}
LIMIT 1
</select>


<insert id="save" parameterType="org.apache.shenyu.admin.model.entity.AuthParamDO">
INSERT INTO auth_path
(id,
Expand All @@ -89,7 +100,7 @@
#{dateCreated, jdbcType=TIMESTAMP},
#{dateUpdated, jdbcType=TIMESTAMP})
</insert>

<insert id="batchSave">
INSERT INTO auth_path
(id,
Expand Down Expand Up @@ -139,5 +150,5 @@
#{authId, jdbcType=VARCHAR}
</foreach>
</delete>

</mapper>
Expand Up @@ -16,7 +16,7 @@
*/

package org.apache.shenyu.admin.service.register;

import org.apache.commons.lang3.StringUtils;
import org.apache.shenyu.admin.model.entity.MetaDataDO;
import org.apache.shenyu.admin.model.entity.SelectorDO;
Expand Down Expand Up @@ -45,7 +45,7 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
Expand Down
Expand Up @@ -41,7 +41,7 @@

import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
Expand Down
Expand Up @@ -17,15 +17,15 @@

package org.apache.shenyu.loadbalancer.cache;

import java.util.concurrent.TimeUnit;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.shenyu.common.dto.SelectorData;
import org.apache.shenyu.loadbalancer.entity.Upstream;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

import java.util.concurrent.TimeUnit;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down

0 comments on commit 04e2b33

Please sign in to comment.