|
@@ -2,21 +2,23 @@ package com.dragoninfo.dcuc.auth.business.impl.zerotrust;
|
|
|
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
+import com.dragoninfo.dcuc.app.dto.ServiceResourceDTO;
|
|
|
import com.dragoninfo.dcuc.app.entity.ApplyInfo;
|
|
|
import com.dragoninfo.dcuc.app.facade.IApplyInfoFacade;
|
|
|
+import com.dragoninfo.dcuc.app.facade.IServiceResourceFacade;
|
|
|
import com.dragoninfo.dcuc.auth.api.enums.zerotrust.AuthApplyRespEnum;
|
|
|
import com.dragoninfo.dcuc.auth.api.enums.zerotrust.ZeroTrustBusinessRespEnum;
|
|
|
import com.dragoninfo.dcuc.auth.api.vo.zerotrust.ZeroTrustDataRespVO;
|
|
|
-import com.dragoninfo.dcuc.auth.api.vo.zerotrust.authapply.ApiRoleAuthContentVo;
|
|
|
-import com.dragoninfo.dcuc.auth.api.vo.zerotrust.authapply.ApiRoleAuthReqVo;
|
|
|
-import com.dragoninfo.dcuc.auth.api.vo.zerotrust.authapply.AuthApplyRespVo;
|
|
|
+import com.dragoninfo.dcuc.auth.api.vo.zerotrust.authapply.*;
|
|
|
import com.dragoninfo.dcuc.auth.api.vo.zerotrust.role.ApiAppRoleRespVo;
|
|
|
import com.dragoninfo.dcuc.auth.api.vo.zerotrust.role.ApiRoleRespVo;
|
|
|
import com.dragoninfo.dcuc.auth.api.vo.zerotrust.role.ApiRolesReqVo;
|
|
|
-import com.dragoninfo.dcuc.auth.auth.dto.RoleAuthApplyDto;
|
|
|
+import com.dragoninfo.dcuc.auth.auth.dto.zerotrust.authapply.RoleAuthApplyDto;
|
|
|
+import com.dragoninfo.dcuc.auth.auth.dto.zerotrust.authapply.ServiceAuthApplyDto;
|
|
|
import com.dragoninfo.dcuc.auth.auth.entity.RoleInfo;
|
|
|
import com.dragoninfo.dcuc.auth.auth.service.IRoleInfoService;
|
|
|
import com.dragoninfo.dcuc.auth.auth.service.zerotrust.IRoleAuthApplyService;
|
|
|
+import com.dragoninfo.dcuc.auth.auth.service.zerotrust.IServiceAuthApplyService;
|
|
|
import com.dragoninfo.dcuc.auth.auth.vo.zerotrust.roleauthapply.ApplyRoleInVo;
|
|
|
import com.dragoninfo.dcuc.auth.business.zerotrust.IAuthTokenBusiness;
|
|
|
import com.dragoninfo.dcuc.auth.business.zerotrust.IZeroTrustAuthApplyBusiness;
|
|
@@ -24,6 +26,7 @@ import com.dragoninfo.dcuc.auth.sub.entity.AuthUserInfo;
|
|
|
import com.dragoninfo.dcuc.auth.sub.service.IAuthUserInfoService;
|
|
|
import com.dragoninfo.dcuc.auth.sub.vo.ApplyInfoVo;
|
|
|
import com.dragoninfo.dcuc.auth.sub.vo.AuthUserVo;
|
|
|
+import com.dragoninfo.dcuc.auth.sub.vo.ServiceResourceVo;
|
|
|
import com.dragoninfo.dcuc.auth.token.vo.AppTokenDetailRespVo;
|
|
|
import com.dragoninfo.dcuc.auth.token.vo.AppTokenInfoRespVO;
|
|
|
import com.dragoninfo.dcuc.auth.token.vo.UserTokenInfoRespVO;
|
|
@@ -42,6 +45,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.validation.Valid;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -55,14 +59,23 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
|
|
|
|
|
|
private IRoleAuthApplyService roleAuthApplyService;
|
|
|
|
|
|
+ private IServiceAuthApplyService serviceAuthApplyService;
|
|
|
+
|
|
|
private IApplyInfoFacade applyInfoFacade;
|
|
|
|
|
|
+ private IServiceResourceFacade serviceResourceFacade;
|
|
|
+
|
|
|
private IRoleInfoService roleInfoService;
|
|
|
|
|
|
private IAuthUserInfoService userInfoService;
|
|
|
|
|
|
private IAuthTokenBusiness authTokenBusiness;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ public void setServiceAuthApplyService(IServiceAuthApplyService serviceAuthApplyService) {
|
|
|
+ this.serviceAuthApplyService = serviceAuthApplyService;
|
|
|
+ }
|
|
|
+
|
|
|
@Autowired
|
|
|
public void setUserInfoService(IAuthUserInfoService userInfoService) {
|
|
|
this.userInfoService = userInfoService;
|
|
@@ -152,7 +165,12 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
|
|
|
return getErrorApplyResp(AuthApplyRespEnum.USER_NOT_EXIST, users);
|
|
|
}
|
|
|
// 校验申请的应用
|
|
|
- Result<List<ApplyInfoVo>> appResult = getAppInfos(reqVo, tokenAppInfo);
|
|
|
+ List<ApiRoleAuthContentVo> contents = reqVo.getContents();
|
|
|
+ List<String> appCodes = contents.stream().map(ApiRoleAuthContentVo::getAppCode)
|
|
|
+ .filter(StringUtils::isNotBlank)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Result<List<ApplyInfoVo>> appResult = getAppInfos(appCodes, tokenAppInfo);
|
|
|
List<ApplyInfoVo> applyInfoVos = appResult.getContent();
|
|
|
if (appResult.isFail()) {
|
|
|
return getErrorApplyResp(AuthApplyRespEnum.APP_NOT_EXIST, applyInfoVos);
|
|
@@ -167,17 +185,125 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
|
|
|
Map<String, List<RoleInfo>> roleMap = roles.stream().collect(Collectors.groupingBy(RoleInfo::getAppId));
|
|
|
Map<String, AuthUserVo> userVoMap = users.stream().collect(Collectors.toMap(AuthUserVo::getIdcard, e -> e));
|
|
|
Map<String, ApplyInfoVo> appVoMap = applyInfoVos.stream().collect(Collectors.toMap(ApplyInfoVo::getApplyCode, e -> e));
|
|
|
- // 设置为当前登录人
|
|
|
+
|
|
|
+ // 设置操作人为当前登录人
|
|
|
setSecurityUser(appTokenDetail);
|
|
|
|
|
|
// 组装批量申请dto
|
|
|
- List<RoleAuthApplyDto> applyDtos = getApplyDtos(reqVo, tokenUserInfo.getIdcard(), tokenAppInfo.getApplyCode(), userVoMap, appVoMap, roleMap);
|
|
|
+ String tokenUserInfoIdcard = tokenUserInfo.getIdcard();
|
|
|
+ String tokenAppInfoApplyCode = tokenAppInfo.getApplyCode();
|
|
|
+ List<RoleAuthApplyDto> applyDtos = getRoleAuthApplyDtos(reqVo, tokenUserInfoIdcard, tokenAppInfoApplyCode, userVoMap, appVoMap, roleMap);
|
|
|
|
|
|
ResponseStatus status = roleAuthApplyService.applyAndPushToApproval(applyDtos, null);
|
|
|
if (ResponseUtil.isFail(status)) {
|
|
|
return getErrorApplyResp(AuthApplyRespEnum.OTHER, status.getMessage());
|
|
|
}
|
|
|
- return ZeroTrustDataRespVO.success(AuthApplyRespVo.success());
|
|
|
+ return ZeroTrustDataRespVO.success(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ZeroTrustDataRespVO<AuthApplyRespVo> serviceAuthApply(@Valid ApiServiceAuthReqVo reqVo) {
|
|
|
+ log.info("服务授权申请,应用令牌:{}, 申请内容:{}", reqVo.getAppTokenId(), JSONUtil.toJsonStr(reqVo));
|
|
|
+
|
|
|
+ // 校验应用令牌
|
|
|
+ AppTokenDetailRespVo appTokenDetail = authTokenBusiness.getByAppTokenId(reqVo.getAppTokenId(), false, true);
|
|
|
+ if (appTokenDetail.isEmpty()) {
|
|
|
+ return ZeroTrustDataRespVO.resultEnumMessage(ZeroTrustBusinessRespEnum.TOKEN_FAIL);
|
|
|
+ }
|
|
|
+ ApplyInfoVo tokenAppInfo = appTokenDetail.getApplyInfo();
|
|
|
+ // 校验应用资源
|
|
|
+ List<String> appCodes = reqVo.getContents().stream()
|
|
|
+ .map(ApiServiceAuthContentVo::getAppCode)
|
|
|
+ .filter(StringUtils::isNotBlank)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Result<List<ApplyInfoVo>> appResult = getAppInfos(appCodes, tokenAppInfo);
|
|
|
+ List<ApplyInfoVo> applyInfoVos = appResult.getContent();
|
|
|
+ if (appResult.isFail()) {
|
|
|
+ return getErrorApplyResp(AuthApplyRespEnum.APP_NOT_EXIST, applyInfoVos);
|
|
|
+ }
|
|
|
+ // 校验服务资源
|
|
|
+ Result<List<ServiceResourceDTO>> serviceResult = getApplyServiceInfos(reqVo, applyInfoVos);
|
|
|
+ List<ServiceResourceDTO> serviceInfos = serviceResult.getContent();
|
|
|
+ if (serviceResult.isFail()) {
|
|
|
+ return getErrorApplyResp(AuthApplyRespEnum.SERVICE_NOT_EXIST, serviceInfos);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置操作人为当前登录人
|
|
|
+ setSecurityUser(appTokenDetail);
|
|
|
+
|
|
|
+ // 组装批量申请dto
|
|
|
+ List<ServiceAuthApplyDto> applyDtos = getServiceAuthApplyDtos(reqVo, applyInfoVos, serviceInfos);
|
|
|
+
|
|
|
+ ResponseStatus status = serviceAuthApplyService.applyAndPushToApproval(applyDtos, null);
|
|
|
+ if (ResponseUtil.isFail(status)) {
|
|
|
+ return getErrorApplyResp(AuthApplyRespEnum.OTHER, status.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return ZeroTrustDataRespVO.success(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<ServiceAuthApplyDto> getServiceAuthApplyDtos(ApiServiceAuthReqVo reqVo, List<ApplyInfoVo> applyInfoVos, List<ServiceResourceDTO> serviceInfos) {
|
|
|
+ Map<String, ApplyInfoVo> appMap = applyInfoVos.stream().collect(Collectors.toMap(ApplyInfoVo::getApplyCode, e -> e));
|
|
|
+ List<ServiceResourceVo> serviceResourceVos = DcucBeanUtil.createCopyToObjectList(serviceInfos, ServiceResourceVo.class);
|
|
|
+ Map<String, ServiceResourceVo> serviceMap = serviceResourceVos.stream().collect(Collectors.toMap(ServiceResourceVo::getServiceCode, e -> e));
|
|
|
+
|
|
|
+ return reqVo.getContents().stream().map(e -> {
|
|
|
+ ApplyInfoVo applyInfoVo = appMap.get( e.getAppCode());
|
|
|
+ List<String> serviceCodes = e.getServiceCodes();
|
|
|
+ ServiceAuthApplyDto dto = new ServiceAuthApplyDto();
|
|
|
+ dto.setApplyInfoVo(applyInfoVo);
|
|
|
+ List<ServiceResourceVo> collect = serviceCodes.stream().map(s -> {
|
|
|
+ ServiceResourceVo vo = serviceMap.get(s);
|
|
|
+ vo.setAppName(applyInfoVo.getApplyName());
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ dto.setServiceVos(collect);
|
|
|
+ return dto;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ private Result<List<ServiceResourceDTO>> getApplyServiceInfos(ApiServiceAuthReqVo reqVo, List<ApplyInfoVo> applyInfoVos) {
|
|
|
+ List<ApiServiceAuthContentVo> contents = reqVo.getContents();
|
|
|
+ List<String> serviceCodes = contents.stream()
|
|
|
+ .map(ApiServiceAuthContentVo::getServiceCodes)
|
|
|
+ .flatMap(List::stream)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<ServiceResourceDTO> serviceInfos = serviceResourceFacade.getServiceByServiceCodes(serviceCodes);
|
|
|
+ Result<List<ServiceResourceDTO>> validated = validateServiceInfos(serviceInfos, contents);
|
|
|
+ if (validated.isFail()) {
|
|
|
+ return validated;
|
|
|
+ }
|
|
|
+ return Result.success(serviceInfos);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Result<List<ServiceResourceDTO>> validateServiceInfos(List<ServiceResourceDTO> serviceInfos, List<ApiServiceAuthContentVo> contents) {
|
|
|
+ Map<String, List<ServiceResourceDTO>> collect = serviceInfos.stream()
|
|
|
+ .collect(Collectors.groupingBy(ServiceResourceDTO::getAppCode));
|
|
|
+ for (ApiServiceAuthContentVo authVo : contents) {
|
|
|
+ String appCode = authVo.getAppCode();
|
|
|
+ List<ServiceResourceDTO> exist = collect.get(appCode);
|
|
|
+ List<String> authServiceCodes = authVo.getServiceCodes();
|
|
|
+ if (CollectionUtils.isEmpty(exist)) {
|
|
|
+ List<ServiceResourceDTO> notExist = authServiceCodes.stream().map(e -> {
|
|
|
+ ServiceResourceDTO dto = new ServiceResourceDTO();
|
|
|
+ dto.setServiceCode(e);
|
|
|
+ return dto;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ return Result.fail(ResultEnum.FAIL.getValue(), AuthApplyRespEnum.SERVICE_NOT_EXIST.getValue(), notExist);
|
|
|
+ }
|
|
|
+ Set<String> existCodes = exist.stream().map(ServiceResourceDTO::getServiceCode).collect(Collectors.toSet());
|
|
|
+ List<ServiceResourceDTO> notExist = authServiceCodes.stream().filter(e -> !existCodes.contains(e)).map(e -> {
|
|
|
+ ServiceResourceDTO dto = new ServiceResourceDTO();
|
|
|
+ dto.setServiceCode(e);
|
|
|
+ return dto;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isNotEmpty(notExist)) {
|
|
|
+ return Result.fail(ResultEnum.FAIL.getValue(), AuthApplyRespEnum.SERVICE_NOT_EXIST.getValue(), notExist);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result.success();
|
|
|
}
|
|
|
|
|
|
private ZeroTrustDataRespVO<AuthApplyRespVo> getErrorApplyResp(AuthApplyRespEnum authApplyRespEnum, Object content) {
|
|
@@ -199,16 +325,26 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
|
|
|
List<RoleInfo> roleInfos = (List<RoleInfo>) content;
|
|
|
Map<String, List<String>> roleAppMap = roleInfos.stream()
|
|
|
.collect(Collectors.groupingBy(RoleInfo::getAppId, Collectors.mapping(RoleInfo::getCode, Collectors.toList())));
|
|
|
- List<String> collect = roleAppMap.entrySet().stream().map(e -> {
|
|
|
+ List<String> roleResp = roleAppMap.entrySet().stream().map(e -> {
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put("appCode", e.getKey());
|
|
|
jsonObject.put("roleCodes", e.getValue());
|
|
|
return jsonObject.toString();
|
|
|
}).collect(Collectors.toList());
|
|
|
- vo.setRespContent(collect);
|
|
|
+ vo.setRespContent(roleResp);
|
|
|
break;
|
|
|
case SERVICE_NOT_EXIST:
|
|
|
- // TODO
|
|
|
+ List<ServiceResourceDTO> services = (List<ServiceResourceDTO>) content;
|
|
|
+ Map<String, List<String>> serviceAppMap = services.stream()
|
|
|
+ .collect(Collectors.groupingBy(ServiceResourceDTO::getAppCode,
|
|
|
+ Collectors.mapping(ServiceResourceDTO::getServiceCode, Collectors.toList())));
|
|
|
+ List<String> serviceResp = serviceAppMap.entrySet().stream().map(e -> {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("appCode", e.getKey());
|
|
|
+ jsonObject.put("serviceCodes", e.getValue());
|
|
|
+ return jsonObject.toString();
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ vo.setRespContent(serviceResp);
|
|
|
break;
|
|
|
case OTHER:
|
|
|
default:
|
|
@@ -219,8 +355,8 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
|
|
|
return ZeroTrustDataRespVO.resultEnumMessage(ZeroTrustBusinessRespEnum.OPERATE_FAIL, vo);
|
|
|
}
|
|
|
|
|
|
- private List<RoleAuthApplyDto> getApplyDtos(ApiRoleAuthReqVo reqVo, String defaultIdcard, String defaultAppCode,
|
|
|
- Map<String, AuthUserVo> userVoMap, Map<String, ApplyInfoVo> appVoMap, Map<String, List<RoleInfo>> roleMap) {
|
|
|
+ private List<RoleAuthApplyDto> getRoleAuthApplyDtos(ApiRoleAuthReqVo reqVo, String defaultIdcard, String defaultAppCode,
|
|
|
+ Map<String, AuthUserVo> userVoMap, Map<String, ApplyInfoVo> appVoMap, Map<String, List<RoleInfo>> roleMap) {
|
|
|
List<ApiRoleAuthContentVo> contents = reqVo.getContents();
|
|
|
return contents.stream().map(e -> {
|
|
|
String applyUserIdcard = Optional.ofNullable(e.getApplyUserIdcard()).orElse(defaultIdcard);
|
|
@@ -246,13 +382,21 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
|
|
|
}
|
|
|
|
|
|
private Result<List<RoleInfo>> getApplyRoles(ApiRoleAuthReqVo reqVo, List<ApplyInfoVo> applyInfoVos) {
|
|
|
- Map<String, ApplyInfoVo> appMap = applyInfoVos.stream().collect(Collectors.toMap(ApplyInfoVo::getApplyCode, e -> e));
|
|
|
List<ApiRoleAuthContentVo> contents = reqVo.getContents();
|
|
|
List<String> roleCodes = contents.stream()
|
|
|
.map(ApiRoleAuthContentVo::getRoleCodes)
|
|
|
.flatMap(List::stream)
|
|
|
.collect(Collectors.toList());
|
|
|
List<RoleInfo> roleInfos = roleInfoService.getByCodes(roleCodes);
|
|
|
+ Result<List<RoleInfo>> validated = validateApplyRoles(applyInfoVos, roleInfos, contents);
|
|
|
+ if (validated.isFail()) {
|
|
|
+ return validated;
|
|
|
+ }
|
|
|
+ return Result.success(roleInfos);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Result<List<RoleInfo>> validateApplyRoles(List<ApplyInfoVo> applyInfoVos, List<RoleInfo> roleInfos, List<ApiRoleAuthContentVo> contents) {
|
|
|
+ Map<String, ApplyInfoVo> appMap = applyInfoVos.stream().collect(Collectors.toMap(ApplyInfoVo::getApplyCode, e -> e));
|
|
|
Map<String, List<RoleInfo>> roleMap = roleInfos.stream().collect(Collectors.groupingBy(RoleInfo::getAppId));
|
|
|
for (ApiRoleAuthContentVo authVo : contents) {
|
|
|
String appCode = authVo.getAppCode();
|
|
@@ -261,16 +405,16 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
|
|
|
List<RoleInfo> roles = roleMap.get(applyInfoVo.getId());
|
|
|
if (CollectionUtils.isEmpty(roles)) {
|
|
|
List<RoleInfo> notExistRoles = mapNotExistRoles(appRoleCodes, applyInfoVo);
|
|
|
- return Result.fail(ResultEnum.FAIL.getValue(), "角色不存在", notExistRoles);
|
|
|
+ return Result.fail(ResultEnum.FAIL.getValue(), AuthApplyRespEnum.ROLE_NOT_EXIST.getValue(), notExistRoles);
|
|
|
}
|
|
|
Set<String> exist = roles.stream().map(RoleInfo::getCode).collect(Collectors.toSet());
|
|
|
List<String> notExist = appRoleCodes.stream().filter(e -> !exist.contains(e)).collect(Collectors.toList());
|
|
|
if (CollectionUtils.isEmpty(notExist)) {
|
|
|
List<RoleInfo> notExistRoles = mapNotExistRoles(notExist, applyInfoVo);
|
|
|
- return Result.fail(ResultEnum.FAIL.getValue(), "角色不存在", notExistRoles);
|
|
|
+ return Result.fail(ResultEnum.FAIL.getValue(), AuthApplyRespEnum.ROLE_NOT_EXIST.getValue(), notExistRoles);
|
|
|
}
|
|
|
}
|
|
|
- return Result.success(roleInfos);
|
|
|
+ return Result.success();
|
|
|
}
|
|
|
|
|
|
private static List<RoleInfo> mapNotExistRoles(List<String> appRoleCodes, ApplyInfoVo applyInfoVo) {
|
|
@@ -282,25 +426,14 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
|
|
|
}).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
- private Result<List<ApplyInfoVo>> getAppInfos(ApiRoleAuthReqVo reqVo, ApplyInfoVo defaultApp) {
|
|
|
- List<ApiRoleAuthContentVo> contents = reqVo.getContents();
|
|
|
- List<String> appCodes = contents.stream().map(ApiRoleAuthContentVo::getAppCode)
|
|
|
- .filter(StringUtils::isNotBlank)
|
|
|
- .distinct()
|
|
|
- .collect(Collectors.toList());
|
|
|
+ private Result<List<ApplyInfoVo>> getAppInfos(List<String> applyAppCodes, ApplyInfoVo defaultApp) {
|
|
|
List<ApplyInfoVo> appInfoVos = new ArrayList<>();
|
|
|
appInfoVos.add(defaultApp);
|
|
|
- if (CollectionUtils.isNotEmpty(appCodes)) {
|
|
|
- List<ApplyInfo> appInfos = applyInfoFacade.getListByCodes(appCodes);
|
|
|
- Set<String> exist = appInfos.stream().map(ApplyInfo::getApplyCode).collect(Collectors.toSet());
|
|
|
- List<String> collect = appCodes.stream().filter(e -> !exist.contains(e)).collect(Collectors.toList());
|
|
|
- if (CollectionUtils.isNotEmpty(collect)) {
|
|
|
- List<ApplyInfoVo> notExistApps = collect.stream().map(e -> {
|
|
|
- ApplyInfoVo vo = new ApplyInfoVo();
|
|
|
- vo.setApplyCode(e);
|
|
|
- return vo;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- return Result.fail(ResultEnum.FAIL.getValue(), "应用资源不存在", notExistApps);
|
|
|
+ if (CollectionUtils.isNotEmpty(applyAppCodes)) {
|
|
|
+ List<ApplyInfo> appInfos = applyInfoFacade.getListByCodes(applyAppCodes);
|
|
|
+ Result<List<ApplyInfoVo>> validated = validateApplyApps(applyAppCodes, appInfos);
|
|
|
+ if (validated.isFail()) {
|
|
|
+ return validated;
|
|
|
}
|
|
|
List<ApplyInfoVo> list = DcucBeanUtil.createCopyToObjectList(appInfos, ApplyInfoVo.class);
|
|
|
appInfoVos.addAll(list);
|
|
@@ -308,6 +441,20 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
|
|
|
return Result.success(appInfoVos);
|
|
|
}
|
|
|
|
|
|
+ private Result<List<ApplyInfoVo>> validateApplyApps(List<String> appCodes, List<ApplyInfo> appInfos) {
|
|
|
+ Set<String> exist = appInfos.stream().map(ApplyInfo::getApplyCode).collect(Collectors.toSet());
|
|
|
+ List<String> collect = appCodes.stream().filter(e -> !exist.contains(e)).collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isNotEmpty(collect)) {
|
|
|
+ List<ApplyInfoVo> notExistApps = collect.stream().map(e -> {
|
|
|
+ ApplyInfoVo vo = new ApplyInfoVo();
|
|
|
+ vo.setApplyCode(e);
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ return Result.fail(ResultEnum.FAIL.getValue(), AuthApplyRespEnum.APP_NOT_EXIST.getValue(), notExistApps);
|
|
|
+ }
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
private Result<List<AuthUserVo>> getApplyUserInfo(ApiRoleAuthReqVo reqVo, AuthUserVo defaultUserVo) {
|
|
|
List<String> applyUserIdcards = reqVo.getContents()
|
|
|
.stream()
|
|
@@ -321,15 +468,9 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
|
|
|
if (CollectionUtils.isNotEmpty(applyUserIdcards)) {
|
|
|
List<AuthUserInfo> userInfos = userInfoService.findByIdcards(applyUserIdcards);
|
|
|
// 判断人员是否都存在
|
|
|
- Set<String> exist = userInfos.stream().map(AuthUserInfo::getIdcard).collect(Collectors.toSet());
|
|
|
- List<String> collect = applyUserIdcards.stream().filter(e -> !exist.contains(e)).collect(Collectors.toList());
|
|
|
- if (CollectionUtils.isNotEmpty(collect)) {
|
|
|
- List<AuthUserVo> notExistUsers = collect.stream().map(e -> {
|
|
|
- AuthUserVo vo = new AuthUserVo();
|
|
|
- vo.setIdcard(e);
|
|
|
- return vo;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- return Result.fail(ResultEnum.FAIL.getValue(), "申请授权人员不存在", notExistUsers);
|
|
|
+ Result<List<AuthUserVo>> validated = validateApplyUsers(userInfos, applyUserIdcards);
|
|
|
+ if (validated.isFail()) {
|
|
|
+ return validated;
|
|
|
}
|
|
|
List<AuthUserVo> userVos = DcucBeanUtil.createCopyToObjectList(userInfos, AuthUserVo.class);
|
|
|
list.addAll(userVos);
|
|
@@ -337,6 +478,20 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
|
|
|
return Result.success(list);
|
|
|
}
|
|
|
|
|
|
+ private Result<List<AuthUserVo>> validateApplyUsers(List<AuthUserInfo> userInfos, List<String> applyUserIdcards) {
|
|
|
+ Set<String> exist = userInfos.stream().map(AuthUserInfo::getIdcard).collect(Collectors.toSet());
|
|
|
+ List<String> collect = applyUserIdcards.stream().filter(e -> !exist.contains(e)).collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isNotEmpty(collect)) {
|
|
|
+ List<AuthUserVo> notExistUsers = collect.stream().map(e -> {
|
|
|
+ AuthUserVo vo = new AuthUserVo();
|
|
|
+ vo.setIdcard(e);
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ return Result.fail(ResultEnum.FAIL.getValue(), AuthApplyRespEnum.USER_NOT_EXIST.getValue(), notExistUsers);
|
|
|
+ }
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
private void setSecurityUser(AppTokenDetailRespVo appTokenDetail) {
|
|
|
UserTokenInfoRespVO userToken = appTokenDetail.getUserToken();
|
|
|
AppTokenInfoRespVO appToken = appTokenDetail.getAppToken();
|