mirror of
https://gitee.com/wangkang/udf.git
synced 2026-10-21 15:26:02 +00:00
修改rms逻辑
This commit is contained in:
@@ -39,16 +39,6 @@ public class Constant {
|
||||
*/
|
||||
public static final String DATA_FORMAT = "yyyy-MM-dd'T'HH";
|
||||
|
||||
/**
|
||||
* 描述 : 所有权限
|
||||
*/
|
||||
public static final String PURVIEW_ALL = "all";
|
||||
|
||||
/**
|
||||
* 描述 : 禁用权限
|
||||
*/
|
||||
public static final String PURVIEW_DISABLED = "disabled";
|
||||
|
||||
/**
|
||||
* 描述 : http头
|
||||
*/
|
||||
|
||||
@@ -6,9 +6,6 @@
|
||||
*/
|
||||
package com.egridcloud.udf.rms;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -69,8 +66,7 @@ public class Rms {
|
||||
* @param <O> 输出类型
|
||||
* @return 服务结果
|
||||
*/
|
||||
public <I, O> RestResponse<O> call(String serviceCode, I input, String uriParam,
|
||||
Object... uriVariables) {
|
||||
public <I, O> RestResponse<O> call(String serviceCode, I input, String uriParam, Object... uriVariables) {
|
||||
//构建请求路径
|
||||
String path = getRmsUrl(serviceCode);
|
||||
//获得请求方法
|
||||
@@ -85,8 +81,8 @@ public class Rms {
|
||||
HttpEntity<I> requestEntity = new HttpEntity<>(input, httpHeaders);
|
||||
//请求并且返回
|
||||
LOGGER.info("rms url : {} , method : {} ", path, method);
|
||||
return restTemplate.exchange(path, HttpMethod.resolve(method), requestEntity,
|
||||
new ParameterizedTypeReference<RestResponse<O>>() {
|
||||
return restTemplate
|
||||
.exchange(path, HttpMethod.resolve(method), requestEntity, new ParameterizedTypeReference<RestResponse<O>>() {
|
||||
}, uriVariables).getBody();
|
||||
}
|
||||
|
||||
@@ -128,12 +124,10 @@ public class Rms {
|
||||
PathMate pathMate = rmsProperties.getService().get(springApplicationName);
|
||||
//判断路径访问权限
|
||||
if (authMate.getPurview() != null) {
|
||||
String[] purviewArray = authMate.getPurview().split(",");
|
||||
List<String> purviewList = Arrays.asList(purviewArray);
|
||||
if (purviewList.contains(Constant.PURVIEW_DISABLED)) {
|
||||
if (authMate.getDisabled()) {
|
||||
throw new SystemRuntimeException(springApplicationName + " is disabled");
|
||||
}
|
||||
if (!purviewList.contains(Constant.PURVIEW_ALL) && !purviewList.contains(serviceCode)) {
|
||||
if (!authMate.getAll() && authMate.getPurview().indexOf(serviceCode) == -1) {
|
||||
throw new SystemRuntimeException(serviceCode + " no access");
|
||||
}
|
||||
} else {
|
||||
|
||||
+26
-22
@@ -62,13 +62,12 @@ public class RmsAuthHandlerInterceptor implements HandlerInterceptor {
|
||||
String rmsServiceCode = request.getHeader(Constant.HEADER_SERVICE_CODE_CODE);
|
||||
String url = request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE).toString();
|
||||
String method = request.getMethod();
|
||||
LOGGER.info("rmsApplicationName:{},rmsSign:{},rmsServiceCode:{},url:{},method:{}",
|
||||
rmsApplicationName, rmsSign, rmsServiceCode, url, method);
|
||||
LOGGER.info("rmsApplicationName:{},rmsSign:{},rmsServiceCode:{},url:{},method:{}", rmsApplicationName, rmsSign,
|
||||
rmsServiceCode, url, method);
|
||||
//判断是否缺少认证信息
|
||||
if (StringUtils.isBlank(rmsApplicationName) || StringUtils.isBlank(rmsSign)
|
||||
|| StringUtils.isBlank(rmsServiceCode)) {
|
||||
throw new AuthException(
|
||||
"missing required authentication parameters (rmsApplicationName , rmsSign)");
|
||||
throw new AuthException("missing required authentication parameters (rmsApplicationName , rmsSign)");
|
||||
}
|
||||
//判断环境(开发环境无需校验)
|
||||
if (!DEV_PROFILES.equals(env.getProperty("spring.profiles.active"))) {
|
||||
@@ -82,24 +81,29 @@ public class RmsAuthHandlerInterceptor implements HandlerInterceptor {
|
||||
if (!rmsSign.equals(sign)) {
|
||||
throw new AuthException("sign Validation failed");
|
||||
}
|
||||
//比较接口编号的有效性
|
||||
if (rmsProperties.getService().containsKey(rmsServiceCode)) {
|
||||
//获得服务元数据
|
||||
PathMate pathMate = rmsProperties.getService().get(rmsServiceCode);
|
||||
//比较url和method
|
||||
if (!pathMate.getUri().equals(url) || !pathMate.getMethod().equals(method)) {
|
||||
throw new AuthException("url and method verification error");
|
||||
}
|
||||
} else {
|
||||
throw new AuthException("service code not exist");
|
||||
}
|
||||
//比较是否有调用接口的权限
|
||||
AuthMate authMate = rmsProperties.getAuthorization().get(rmsApplicationName);
|
||||
if (authMate.getPurview().indexOf(Constant.PURVIEW_ALL) == -1) {
|
||||
if (authMate.getPurview().indexOf(Constant.PURVIEW_DISABLED) != -1 //NOSONAR
|
||||
|| authMate.getPurview().indexOf(rmsServiceCode) == -1) {
|
||||
throw new PermissionException(
|
||||
"no access to this url : " + url + ", method : " + method);
|
||||
//判断是否有调用所有服务的权限
|
||||
if (!authMate.getAll()) {
|
||||
//判断是否禁止调用所有服务权限
|
||||
if (authMate.getDisabled()) {
|
||||
throw new PermissionException("all services are disabled");
|
||||
}
|
||||
//判断是否有调用该服务的权限
|
||||
if (authMate.getPurview().indexOf(rmsServiceCode) != -1) {
|
||||
//比较接口编号和服务设定的有效性
|
||||
if (rmsProperties.getService().containsKey(rmsServiceCode)) {
|
||||
//获得服务元数据
|
||||
PathMate pathMate = rmsProperties.getService().get(rmsServiceCode);
|
||||
//比较url和method
|
||||
if (!pathMate.getUri().equals(url) || !pathMate.getMethod().equals(method)) {
|
||||
throw new AuthException("url and method verification error");
|
||||
}
|
||||
} else {
|
||||
throw new AuthException("service code not exist");
|
||||
}
|
||||
} else {
|
||||
throw new PermissionException("no access to this url : " + url + ", method : " + method);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -117,8 +121,8 @@ public class RmsAuthHandlerInterceptor implements HandlerInterceptor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
|
||||
Object handler, Exception ex) throws Exception {
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
|
||||
throws Exception {
|
||||
LOGGER.debug("SystemTagAuthHandlerInterceptor.afterCompletion");
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,52 @@ public class AuthMate {
|
||||
*/
|
||||
private String purview;
|
||||
|
||||
/**
|
||||
* 描述 : 所有服务的调用权限(优先判定)
|
||||
*/
|
||||
private Boolean all = false;
|
||||
|
||||
/**
|
||||
* 描述 : 禁止服务调用
|
||||
*/
|
||||
private Boolean disabled = false;
|
||||
|
||||
/**
|
||||
* 描述 : 获取all
|
||||
*
|
||||
* @return the all
|
||||
*/
|
||||
public Boolean getAll() {
|
||||
return all;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 设置all
|
||||
*
|
||||
* @param all the all to set
|
||||
*/
|
||||
public void setAll(Boolean all) {
|
||||
this.all = all;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 获取disabled
|
||||
*
|
||||
* @return the disabled
|
||||
*/
|
||||
public Boolean getDisabled() {
|
||||
return disabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 设置disabled
|
||||
*
|
||||
* @param disabled the disabled to set
|
||||
*/
|
||||
public void setDisabled(Boolean disabled) {
|
||||
this.disabled = disabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 获取secret
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user