|
@@ -9,7 +9,8 @@ import com.dragonsoft.dcuc.approve.enumresources.ListLevelEnum;
|
|
|
import com.dragonsoft.dcuc.approve.enumresources.ListResourceTypeEnum;
|
|
|
import com.dragonsoft.dcuc.approve.model.resp.OperateRespVO;
|
|
|
import com.dragonsoft.dcuc.approve.model.resp.ResourceInfoVo;
|
|
|
-import com.dragonsoft.dcuc.approve.model.vo.ListItemVO;
|
|
|
+import com.dragonsoft.dcuc.approve.model.vo.AppFunRedListVo;
|
|
|
+import com.dragonsoft.dcuc.approve.model.vo.WhiteListUserApiVo;
|
|
|
import com.dragonsoft.dcuc.approve.properties.ApproveProperties;
|
|
|
import com.dragonsoft.duceap.commons.util.enums.EnumUtils;
|
|
|
import com.dragonsoft.duceap.commons.util.json.JsonUtils;
|
|
@@ -27,6 +28,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -46,59 +48,126 @@ public class DcucAuthBusinessImpl implements IDcucAuthBusiness {
|
|
|
/**
|
|
|
* 红名单接口
|
|
|
*/
|
|
|
- public static final String RED_LIST_URL = "/api/list-service/v1/red-list/search/";
|
|
|
+ public static final String RED_LIST_URL = "/api/list-service/v1/list/func-red-list/";
|
|
|
/**
|
|
|
* 白名单接口
|
|
|
*/
|
|
|
- public static final String WHITE_LIST_URL = "/api/list-service/v1/white-list/search/";
|
|
|
+ public static final String WHITE_LIST_URL = "/api/list-service/v1/list/user-white-list/";
|
|
|
|
|
|
@Autowired
|
|
|
private IRestTemplateProvider restTemplateProvider;
|
|
|
|
|
|
/**
|
|
|
- * 获取白名单等级
|
|
|
+ * 获取红名单等级
|
|
|
*
|
|
|
- * @param idcard 身份证号
|
|
|
+ * @param flowTypeEnum 流程类型
|
|
|
+ * @param resourceCode 资源代码
|
|
|
* @return 等级
|
|
|
*/
|
|
|
@Override
|
|
|
- public Optional<ListLevelEnum> getWhiteListLevel(String idcard) {
|
|
|
- return requestLevel(WHITE_LIST_URL, ListResourceTypeEnum.USER, idcard);
|
|
|
+ public Set<ListLevelEnum> getRedListLevel(FlowTypeEnum flowTypeEnum, String resourceCode) {
|
|
|
+ ListResourceTypeEnum listResourceTypeEnum = flowTypeEnum.toListResourceTypeEnum();
|
|
|
+
|
|
|
+ if (listResourceTypeEnum == ListResourceTypeEnum.FUNCTION) {
|
|
|
+ return getRedFunctionListLevel(resourceCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Collections.emptySet();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取红名单等级
|
|
|
+ * 请求LEVEL
|
|
|
*
|
|
|
- * @param flowTypeEnum 流程类型
|
|
|
* @param resourceCode 资源代码
|
|
|
- * @return 等级
|
|
|
+ * @return 资源等级
|
|
|
*/
|
|
|
- @Override
|
|
|
- public Optional<ListLevelEnum> getRedListLevel(FlowTypeEnum flowTypeEnum, String resourceCode) {
|
|
|
- ListResourceTypeEnum listResourceTypeEnum = flowTypeEnum.toListResourceTypeEnum();
|
|
|
- return requestLevel(RED_LIST_URL, listResourceTypeEnum, resourceCode);
|
|
|
+ @SneakyThrows
|
|
|
+ public Set<ListLevelEnum> getRedFunctionListLevel(String resourceCode) {
|
|
|
+
|
|
|
+ String[] appFunctionArray = resourceCode.split(",");
|
|
|
+ // appCode:funCode/funCode,appCode:funCode/funCode
|
|
|
+ Map<String, String[]> appCodeFunctionCodeMap = new HashMap<>();
|
|
|
+ for (String appFunction : appFunctionArray) {
|
|
|
+ String appCode = appFunction.substring(0, appFunction.indexOf(":"));
|
|
|
+ String funCode = appFunction.substring(appFunction.indexOf(":"));
|
|
|
+ String[] funCodeArray = funCode.split("//");
|
|
|
+ appCodeFunctionCodeMap.put(appCode, funCodeArray);
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<ListLevelEnum> totalListLevelEnum = new HashSet<>();
|
|
|
+ for (String appCode : appCodeFunctionCodeMap.keySet()) {
|
|
|
+ String[] functionCodeArray = appCodeFunctionCodeMap.getOrDefault(appCode, new String[]{});
|
|
|
+ Set<ListLevelEnum> listLevelEnumSet = getFunctionLevel(appCode, functionCodeArray);
|
|
|
+ totalListLevelEnum.addAll(listLevelEnumSet);
|
|
|
+ }
|
|
|
+ return totalListLevelEnum;
|
|
|
+ }
|
|
|
+
|
|
|
+ @SneakyThrows
|
|
|
+ private Set<ListLevelEnum> getFunctionLevel(String appCode, String[] functionCodeArray) {
|
|
|
+ Map<String, SearchParam> filters = new HashMap<>(1);
|
|
|
+ SearchParam searchParamCode = new SearchParam();
|
|
|
+ searchParamCode.setOperator(SearchOperator.eq.name());
|
|
|
+ searchParamCode.setValue(appCode);
|
|
|
+ SearchParam functionSearchParamCode = new SearchParam();
|
|
|
+ functionSearchParamCode.setOperator(SearchOperator.in.name());
|
|
|
+ functionSearchParamCode.setValue(functionCodeArray);
|
|
|
+
|
|
|
+ filters.put("appCode", searchParamCode);
|
|
|
+ filters.put("functionCodeArray", functionSearchParamCode);
|
|
|
+ ApiSearchReq apiSearchReq = new ApiSearchReq();
|
|
|
+
|
|
|
+ ApiPageReq apiPageReq = new ApiPageReq();
|
|
|
+ apiPageReq.setFrom(1);
|
|
|
+ apiPageReq.setSize(1);
|
|
|
+ apiSearchReq.setPage(apiPageReq);
|
|
|
+ apiSearchReq.setFilters(filters);
|
|
|
+
|
|
|
+ HttpEntity<ApiSearchReq> requestEntity = new HttpEntity<>(apiSearchReq);
|
|
|
+ String reqUrl = approveProperties.getAuthServiceUrl() + WHITE_LIST_URL;
|
|
|
+ RestTemplate restTemplate = restTemplateProvider.getRestTemplate();
|
|
|
+ ResponseEntity<ApiResult> resultResponseEntity = restTemplate.exchange(reqUrl, HttpMethod.POST, requestEntity, ApiResult.class);
|
|
|
+ HttpStatus statusCode = resultResponseEntity.getStatusCode();
|
|
|
+ if (statusCode.is2xxSuccessful()) {
|
|
|
+ ApiResult apiResult = resultResponseEntity.getBody();
|
|
|
+ if (apiResult == null) {
|
|
|
+ return Collections.emptySet();
|
|
|
+ }
|
|
|
+
|
|
|
+ Object result = apiResult.getResult();
|
|
|
+ String jsonString = JsonUtils.toJSONString(result);
|
|
|
+
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ ApiResultPage<AppFunRedListVo> apiResultPage = objectMapper.readValue(jsonString, new TypeReference<ApiResultPage<AppFunRedListVo>>() {
|
|
|
+ });
|
|
|
+ List<AppFunRedListVo> content = apiResultPage.getContent();
|
|
|
+ if (content.size() != 1) {
|
|
|
+ log.error("content size error, size :{}", content.size());
|
|
|
+ return Collections.emptySet();
|
|
|
+ }
|
|
|
+
|
|
|
+ return content.stream().map(item -> EnumUtils.enumOf(ListLevelEnum.class, item.getLevel()))
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ } else {
|
|
|
+ log.error("request error:{}", JsonUtils.toJSONString(resultResponseEntity));
|
|
|
+ }
|
|
|
+ return Collections.emptySet();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 请求LEVEL
|
|
|
*
|
|
|
- * @param url 路径
|
|
|
- * @param listResourceTypeEnum 资源类型
|
|
|
- * @param resourceCode 资源代码
|
|
|
+ * @param resourceCode 资源代码
|
|
|
* @return 资源等级
|
|
|
*/
|
|
|
+ @Override
|
|
|
@SneakyThrows
|
|
|
- public Optional<ListLevelEnum> requestLevel(String url, ListResourceTypeEnum listResourceTypeEnum, String resourceCode) {
|
|
|
- Map<String, SearchParam> filters = new HashMap<>(2);
|
|
|
+ public Optional<ListLevelEnum> getWhiteListLevel(String resourceCode) {
|
|
|
+ Map<String, SearchParam> filters = new HashMap<>(1);
|
|
|
SearchParam searchParamCode = new SearchParam();
|
|
|
searchParamCode.setOperator(SearchOperator.eq.name());
|
|
|
searchParamCode.setValue(resourceCode);
|
|
|
- filters.put("resourceCode", searchParamCode);
|
|
|
-
|
|
|
- SearchParam searchParamLevel = new SearchParam();
|
|
|
- searchParamLevel.setOperator(SearchOperator.eq.name());
|
|
|
- searchParamLevel.setValue(listResourceTypeEnum.getValue());
|
|
|
- filters.put("type", searchParamLevel);
|
|
|
+ filters.put("idcard", searchParamCode);
|
|
|
|
|
|
ApiSearchReq apiSearchReq = new ApiSearchReq();
|
|
|
|
|
@@ -109,7 +178,7 @@ public class DcucAuthBusinessImpl implements IDcucAuthBusiness {
|
|
|
apiSearchReq.setFilters(filters);
|
|
|
|
|
|
HttpEntity<ApiSearchReq> requestEntity = new HttpEntity<>(apiSearchReq);
|
|
|
- String reqUrl = approveProperties.getAuthServiceUrl() + url;
|
|
|
+ String reqUrl = approveProperties.getAuthServiceUrl() + RED_LIST_URL;
|
|
|
RestTemplate restTemplate = restTemplateProvider.getRestTemplate();
|
|
|
ResponseEntity<ApiResult> resultResponseEntity = restTemplate.exchange(reqUrl, HttpMethod.POST, requestEntity, ApiResult.class);
|
|
|
HttpStatus statusCode = resultResponseEntity.getStatusCode();
|
|
@@ -123,15 +192,15 @@ public class DcucAuthBusinessImpl implements IDcucAuthBusiness {
|
|
|
String jsonString = JsonUtils.toJSONString(result);
|
|
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
- ApiResultPage<ListItemVO> apiResultPage = objectMapper.readValue(jsonString, new TypeReference<ApiResultPage<ListItemVO>>() {
|
|
|
+ ApiResultPage<WhiteListUserApiVo> apiResultPage = objectMapper.readValue(jsonString, new TypeReference<ApiResultPage<WhiteListUserApiVo>>() {
|
|
|
});
|
|
|
- List<ListItemVO> content = apiResultPage.getContent();
|
|
|
+ List<WhiteListUserApiVo> content = apiResultPage.getContent();
|
|
|
if (content.size() != 1) {
|
|
|
log.error("content size error, size :{}", content.size());
|
|
|
return Optional.empty();
|
|
|
}
|
|
|
- ListItemVO listItemVO = content.get(0);
|
|
|
- String level = listItemVO.getLevel();
|
|
|
+ WhiteListUserApiVo whiteListUserApiVo = content.get(0);
|
|
|
+ String level = whiteListUserApiVo.getListLevel();
|
|
|
ListLevelEnum listLevelEnum = EnumUtils.enumOf(ListLevelEnum.class, level);
|
|
|
return Optional.of(listLevelEnum);
|
|
|
} else {
|
|
@@ -143,9 +212,9 @@ public class DcucAuthBusinessImpl implements IDcucAuthBusiness {
|
|
|
/**
|
|
|
* 判断是否命中红名单
|
|
|
*
|
|
|
- * @param idcard 身份证号
|
|
|
- * @param flowTypeEnum 流程类型
|
|
|
- * @param resourceInfoVo 资源列表
|
|
|
+ * @param idcard 身份证号
|
|
|
+ * @param flowTypeEnum 流程类型
|
|
|
+ * @param resourceInfoVo 资源列表
|
|
|
* @return 命中状态
|
|
|
*/
|
|
|
@Override
|
|
@@ -158,16 +227,9 @@ public class DcucAuthBusinessImpl implements IDcucAuthBusiness {
|
|
|
}
|
|
|
// 获取主体红名单
|
|
|
String visitResourceCode = resourceInfoVo.getVisitResourceCode();
|
|
|
- String[] resourceCodeArray = visitResourceCode.split(",");
|
|
|
-
|
|
|
- Set<ListLevelEnum> objectListLevelEnumList = new HashSet<>();
|
|
|
- for (String resourceCode : resourceCodeArray) {
|
|
|
- ListLevelEnum objectListLevelEnum = getRedListLevel(FlowTypeEnum.APP_FUN_AUTH, resourceCode)
|
|
|
- .orElse(ListLevelEnum.NORMAL);
|
|
|
- objectListLevelEnumList.add(objectListLevelEnum);
|
|
|
- }
|
|
|
+ Set<ListLevelEnum> objectListLevelEnumSet = getRedListLevel(FlowTypeEnum.APP_FUN_AUTH, visitResourceCode);
|
|
|
|
|
|
- ListLevelEnum maxLevel = getMaxLevel(objectListLevelEnumList);
|
|
|
+ ListLevelEnum maxLevel = getMaxLevel(objectListLevelEnumSet);
|
|
|
// 普通资源可以被所有访问无需判断
|
|
|
if (maxLevel.equals(ListLevelEnum.NORMAL)) {
|
|
|
return OperateRespVO.notRequired();
|