This commit is contained in:
六如
2024-12-22 08:42:31 +08:00
parent bb2a9eb314
commit 02fb5a9e85
12 changed files with 471 additions and 421 deletions

View File

@@ -9,9 +9,21 @@ import lombok.Getter;
@AllArgsConstructor
@Getter
public enum StatusEnum {
NONE(0),
ENABLE(1),
DISABLE(2);
private final int value;
public static StatusEnum of(Number number) {
if (number == null) {
return NONE;
}
for (StatusEnum value : StatusEnum.values()) {
if (value.value == number.intValue()) {
return value;
}
}
return NONE;
}
}

View File

@@ -35,8 +35,8 @@ public class RedisIsvApiPermissionManagerImpl extends LocalIsvApiPermissionManag
@Override
public boolean doCheck(Long isvId, ApiInfoDTO apiInfoDTO) {
BoundHashOperations<String, Object, String> operations = stringRedisTemplate.boundHashOps(CACHE_KEY);
String value = operations.get(isvId);
BoundHashOperations<String, String, String> operations = stringRedisTemplate.boundHashOps(CACHE_KEY);
String value = operations.get(String.valueOf(isvId));
if (Objects.equals(value, SopConstants.NULL)) {
return false;
}
@@ -53,7 +53,7 @@ public class RedisIsvApiPermissionManagerImpl extends LocalIsvApiPermissionManag
@Override
protected void cache(Long isvId, List<Long> apiIdList) {
stringRedisTemplate.opsForHash().put(CACHE_KEY, isvId, JsonUtil.toJSONString(apiIdList));
stringRedisTemplate.opsForHash().put(CACHE_KEY, String.valueOf(isvId), JsonUtil.toJSONString(apiIdList));
log.info("更新isv接口id redis缓存, isvId={}, apiIdList={}", isvId, apiIdList);
}

View File

@@ -48,7 +48,7 @@ public class RedisIsvManagerImpl extends LocalIsvManagerImpl {
@Override
protected void cache(String appId, IsvDTO isvDTO) {
stringRedisTemplate.opsForHash().put(KEY_ISV, appId, JsonUtil.toJSONString(isvDTO));
log.info("更新isv redis缓存, isvDTO={}", isvDTO);
log.debug("更新isv redis缓存, isvDTO={}", isvDTO);
}
@PostConstruct

View File

@@ -27,7 +27,7 @@ public class RedisSecretManager extends LocalSecretManagerImpl {
@Override
public String getIsvPublicKey(Long isvId) {
try {
Object value = stringRedisTemplate.opsForHash().get(KEY_SEC, isvId);
Object value = stringRedisTemplate.opsForHash().get(KEY_SEC, buildHashKey(isvId));
if (Objects.equals(value, SopConstants.NULL)) {
return null;
}
@@ -47,8 +47,13 @@ public class RedisSecretManager extends LocalSecretManagerImpl {
if (publicKey == null) {
publicKey = SopConstants.NULL;
}
stringRedisTemplate.opsForHash().put(KEY_SEC, isvId, publicKey);
log.info("更新isv秘钥redis缓存, isvId={}", isvId);
stringRedisTemplate.opsForHash().put(KEY_SEC, buildHashKey(isvId), publicKey);
log.debug("更新isv秘钥redis缓存, isvId={}", isvId);
}
private String buildHashKey(Long isvId) {
return String.valueOf(isvId);
}
@PostConstruct

View File

@@ -111,7 +111,7 @@ public class ApiValidator implements Validator {
throw new ApiException(ErrorEnum.ISV_INVALID_METHOD, apiRequestContext.getLocale());
}
// 检查路由是否启用
if (!BooleanUtils.toBoolean(apiInfoDTO.getStatus())) {
if (StatusEnum.of(apiInfoDTO.getStatus()) != StatusEnum.ENABLE) {
throw new ApiException(ErrorEnum.ISP_API_DISABLED, apiRequestContext.getLocale());
}
// 校验是否需要授权访问