开启 Dubbo Consumer 参数校验

pull/3/head
YunaiV 2020-07-17 07:53:24 +08:00
parent 3b5199b60b
commit d619f0fae8
16 changed files with 35 additions and 29 deletions

View File

@ -27,9 +27,9 @@ import static cn.iocoder.mall.systemservice.enums.SystemErrorCodeEnum.OAUTH_USER
public class AdminSecurityInterceptor extends HandlerInterceptorAdapter {
@Reference(validation = "true", version = "${dubbo.consumer.OAuth2Rpc.version}")
@Reference(version = "${dubbo.consumer.OAuth2Rpc.version}")
private OAuth2Rpc oauth2Rpc;
@Reference(validation = "true", version = "${dubbo.consumer.PermissionRpc.version}")
@Reference(version = "${dubbo.consumer.PermissionRpc.version}")
private PermissionRpc permissionRpc;
@Override

View File

@ -23,7 +23,7 @@ import static cn.iocoder.mall.systemservice.enums.SystemErrorCodeEnum.OAUTH_USER
public class UserSecurityInterceptor extends HandlerInterceptorAdapter {
@Reference(validation = "true", version = "${dubbo.consumer.OAuth2Rpc.version}")
@Reference(version = "${dubbo.consumer.OAuth2Rpc.version}")
private OAuth2Rpc oauth2Rpc;
@Override

View File

@ -51,7 +51,7 @@ public class GlobalExceptionHandler {
private String applicationName;
// TODO 目前存在一个问题,如果未引入 system-rpc-api 依赖GlobalExceptionHandler 会报类不存在。未来封装出 Repository 解决该问题
@Reference(validation = "true", version = "${dubbo.consumer.SystemExceptionLogRpc.version}")
@Reference(version = "${dubbo.consumer.SystemExceptionLogRpc.version}")
private SystemExceptionLogRpc systemExceptionLogRpc;
/**
@ -199,6 +199,7 @@ public class GlobalExceptionHandler {
.setExceptionTime(new Date());
}
// TODO 优化点:后续可以增加事件
@Async
public void addExceptionLog(SystemExceptionLogCreateDTO exceptionLog) {
try {

View File

@ -26,7 +26,7 @@ public class AccessLogInterceptor extends HandlerInterceptorAdapter {
private Logger logger = LoggerFactory.getLogger(getClass());
@Reference(validation = "false", version = "${dubbo.consumer.SystemAccessLogRpc.version}")
@Reference(version = "${dubbo.consumer.SystemAccessLogRpc.version}")
private SystemAccessLogRpc systemAccessLogRpc;
@Value("${spring.application.name}")
@ -77,6 +77,7 @@ public class AccessLogInterceptor extends HandlerInterceptorAdapter {
.setResponseTime((int) (System.currentTimeMillis() - accessLog.getStartTime().getTime())); // 默认响应时间设为 0
}
// TODO 优化点:后续可以增加事件
@Async // 异步入库
public void addAccessLog(SystemAccessLogCreateDTO accessLog) {
try {

View File

@ -10,6 +10,12 @@ Content-Type: application/x-www-form-urlencoded
username=admin&password=1024
### /passport/login 少传参数
POST {{baseUrl}}/passport/login
Content-Type: application/x-www-form-urlencoded
username=admin
### /passport/info 成功
GET {{baseUrl}}/passport/info
Authorization: Bearer {{accessToken}}

View File

@ -27,13 +27,13 @@ import java.util.*;
@Validated
public class AdminManager {
@Reference(version = "${dubbo.consumer.AdminRpc.version}", validation = "false")
@Reference(version = "${dubbo.consumer.AdminRpc.version}")
private AdminRpc adminRpc;
@Reference(version = "${dubbo.consumer.RoleRpc.version}", validation = "false")
@Reference(version = "${dubbo.consumer.RoleRpc.version}")
private RoleRpc roleRpc;
@Reference(version = "${dubbo.consumer.DepartmentRpc.version}", validation = "false")
@Reference(version = "${dubbo.consumer.DepartmentRpc.version}")
private DepartmentRpc departmentRpc;
@Reference(version = "${dubbo.consumer.PermissionRpc.version}", validation = "false")
@Reference(version = "${dubbo.consumer.PermissionRpc.version}")
private PermissionRpc permissionRpc;
public PageResult<AdminPageItemVO> pageAdmin(AdminPageDTO pageDTO) {

View File

@ -22,7 +22,7 @@ import java.util.stream.Collectors;
@Slf4j
public class DepartmentManager {
@Reference(version = "${dubbo.consumer.DepartmentRpc.version}", validation = "false")
@Reference(version = "${dubbo.consumer.DepartmentRpc.version}")
private DepartmentRpc departmentRpc;
/**

View File

@ -19,15 +19,11 @@ import java.util.List;
@Service
public class DataDictManager {
private static final Comparator<cn.iocoder.mall.systemservice.rpc.datadict.vo.DataDictVO> COMPARATOR_ENUM_VALUE_SORT = (o1, o2) -> {
int cmp = o1.getEnumValue().compareTo(o2.getEnumValue());
if (cmp != 0) {
return cmp;
}
return o1.getSort().compareTo(o2.getSort());
};
private static final Comparator<cn.iocoder.mall.systemservice.rpc.datadict.vo.DataDictVO> COMPARATOR_ENUM_VALUE_SORT = Comparator
.comparing(cn.iocoder.mall.systemservice.rpc.datadict.vo.DataDictVO::getEnumValue)
.thenComparingInt(cn.iocoder.mall.systemservice.rpc.datadict.vo.DataDictVO::getSort);
@Reference(version = "${dubbo.consumer.DataDictRpc.version}", validation = "false")
@Reference(version = "${dubbo.consumer.DataDictRpc.version}")
private DataDictRpc dataDictRpc;
/**

View File

@ -30,13 +30,13 @@ import java.util.Set;
@Service
public class PassportManager {
@Reference(version = "${dubbo.consumer.AdminRpc.version}", validation = "false")
@Reference(version = "${dubbo.consumer.AdminRpc.version}")
private AdminRpc adminRpc;
@Reference(version = "${dubbo.consumer.OAuth2Rpc.version}", validation = "false")
@Reference(version = "${dubbo.consumer.OAuth2Rpc.version}")
private OAuth2Rpc oauth2Rpc;
@Reference(version = "${dubbo.consumer.RoleRpc.version}", validation = "false")
@Reference(version = "${dubbo.consumer.RoleRpc.version}")
private RoleRpc roleRpc;
@Reference(version = "${dubbo.consumer.ResourceRpc.version}", validation = "false")
@Reference(version = "${dubbo.consumer.ResourceRpc.version}")
private ResourceRpc resourceRpc;
public PassportAccessTokenVO login(PassportLoginDTO loginDTO, String ip) {

View File

@ -16,7 +16,7 @@ import java.util.Set;
@Service
public class PermissionManager {
@Reference(version = "${dubbo.consumer.PermissionRpc.version}", validation = "false")
@Reference(version = "${dubbo.consumer.PermissionRpc.version}")
private PermissionRpc permissionRpc;
/**

View File

@ -23,9 +23,9 @@ import java.util.stream.Collectors;
@Slf4j
public class ResourceManager {
@Reference(version = "${dubbo.consumer.ResourceRpc.version}", validation = "false")
@Reference(version = "${dubbo.consumer.ResourceRpc.version}")
private ResourceRpc resourceRpc;
@Reference(version = "${dubbo.consumer.RoleRpc.version}", validation = "false")
@Reference(version = "${dubbo.consumer.RoleRpc.version}")
private RoleRpc roleRpc;
/**

View File

@ -19,7 +19,7 @@ import java.util.List;
@Service
public class RoleManager {
@Reference(version = "${dubbo.consumer.RoleRpc.version}", validation = "false")
@Reference(version = "${dubbo.consumer.RoleRpc.version}")
private RoleRpc roleRpc;
/**

View File

@ -15,7 +15,7 @@ import org.springframework.stereotype.Service;
@Service
public class SystemAccessLogManager {
@Reference(version = "${dubbo.consumer.SystemAccessLogRpc.version}", validation = "false")
@Reference(version = "${dubbo.consumer.SystemAccessLogRpc.version}")
private SystemAccessLogRpc systemAccessLogRpc;
/**

View File

@ -19,9 +19,9 @@ import org.springframework.stereotype.Service;
@Service
public class SystemExceptionLogManager {
@Reference(version = "${dubbo.consumer.SystemExceptionLogRpc.version}", validation = "false")
@Reference(version = "${dubbo.consumer.SystemExceptionLogRpc.version}")
private SystemExceptionLogRpc systemExceptionLogRpc;
@Reference(version = "${dubbo.consumer.AdminRpc.version}", validation = "false")
@Reference(version = "${dubbo.consumer.AdminRpc.version}")
private AdminRpc adminRpc;
/**

View File

@ -24,6 +24,7 @@ dubbo:
# Dubbo 服务消费者的配置
consumer:
timeout: 10000
validation: true # 开启 Consumer 参数校验
UserSmsCodeRpc:
version: 1.0.0
UserRpc:

View File

@ -20,6 +20,7 @@ dubbo:
# Dubbo 服务消费者的配置
consumer:
timeout: 10000
validation: true # 开启 Consumer 的参数校验
UserSmsCodeRpc:
version: 1.0.0
UserRpc: