|
@@ -1,5 +1,6 @@
|
|
package com.dragoninfo.dcuc.auth.business.impl.zerotrust;
|
|
package com.dragoninfo.dcuc.auth.business.impl.zerotrust;
|
|
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.json.JSONObject;
|
|
import cn.hutool.json.JSONObject;
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
import com.dragoninfo.dcuc.app.dto.ServiceResourceDTO;
|
|
import com.dragoninfo.dcuc.app.dto.ServiceResourceDTO;
|
|
@@ -22,7 +23,6 @@ import com.dragoninfo.dcuc.auth.auth.service.zerotrust.IServiceAuthApplyService;
|
|
import com.dragoninfo.dcuc.auth.auth.vo.zerotrust.roleauthapply.ApplyRoleInVo;
|
|
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.IAuthTokenBusiness;
|
|
import com.dragoninfo.dcuc.auth.business.zerotrust.IZeroTrustAuthApplyBusiness;
|
|
import com.dragoninfo.dcuc.auth.business.zerotrust.IZeroTrustAuthApplyBusiness;
|
|
-import com.dragoninfo.dcuc.auth.sub.entity.AuthUserInfo;
|
|
|
|
import com.dragoninfo.dcuc.auth.sub.service.IAuthUserInfoService;
|
|
import com.dragoninfo.dcuc.auth.sub.service.IAuthUserInfoService;
|
|
import com.dragoninfo.dcuc.auth.sub.vo.ApplyInfoVo;
|
|
import com.dragoninfo.dcuc.auth.sub.vo.ApplyInfoVo;
|
|
import com.dragoninfo.dcuc.auth.sub.vo.AuthUserVo;
|
|
import com.dragoninfo.dcuc.auth.sub.vo.AuthUserVo;
|
|
@@ -158,49 +158,49 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
|
|
AuthUserVo tokenUserInfo = appTokenDetail.getUserInfo();
|
|
AuthUserVo tokenUserInfo = appTokenDetail.getUserInfo();
|
|
ApplyInfoVo tokenAppInfo = appTokenDetail.getApplyInfo();
|
|
ApplyInfoVo tokenAppInfo = appTokenDetail.getApplyInfo();
|
|
|
|
|
|
- // 校验申请人
|
|
|
|
- Result<List<AuthUserVo>> userResult = getApplyUserInfo(reqVo, tokenUserInfo);
|
|
|
|
- List<AuthUserVo> users = userResult.getContent();
|
|
|
|
- if (userResult.isFail()) {
|
|
|
|
- return getErrorApplyResp(AuthApplyRespEnum.USER_NOT_EXIST, users);
|
|
|
|
- }
|
|
|
|
// 校验申请的应用
|
|
// 校验申请的应用
|
|
- 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);
|
|
|
|
|
|
+ String applyAppCode = reqVo.getContents().getAppCode();
|
|
|
|
+ Result<ApplyInfoVo> validate = validateApplyApp(applyAppCode, tokenAppInfo);
|
|
|
|
+ if (validate.isFail()) {
|
|
|
|
+ return getErrorApplyResp(AuthApplyRespEnum.APP_NOT_EXIST, Collections.singletonList(applyAppCode));
|
|
}
|
|
}
|
|
|
|
+
|
|
// 校验申请的角色
|
|
// 校验申请的角色
|
|
- Result<List<RoleInfo>> roleResult = getApplyRoles(reqVo, applyInfoVos);
|
|
|
|
|
|
+ ApplyInfoVo applyInfoVo = validate.getContent();
|
|
|
|
+ List<String> roleCodes = reqVo.getContents().getRoleCodes();
|
|
|
|
+ Result<List<RoleInfo>> roleResult = getApplyRoles(roleCodes, applyInfoVo);
|
|
List<RoleInfo> roles = roleResult.getContent();
|
|
List<RoleInfo> roles = roleResult.getContent();
|
|
if (roleResult.isFail()) {
|
|
if (roleResult.isFail()) {
|
|
return getErrorApplyResp(AuthApplyRespEnum.ROLE_NOT_EXIST, roles);
|
|
return getErrorApplyResp(AuthApplyRespEnum.ROLE_NOT_EXIST, roles);
|
|
}
|
|
}
|
|
|
|
|
|
- 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);
|
|
setSecurityUser(appTokenDetail);
|
|
|
|
|
|
// 组装批量申请dto
|
|
// 组装批量申请dto
|
|
- String tokenUserInfoIdcard = tokenUserInfo.getIdcard();
|
|
|
|
- String tokenAppInfoApplyCode = tokenAppInfo.getApplyCode();
|
|
|
|
- List<RoleAuthApplyDto> applyDtos = getRoleAuthApplyDtos(reqVo, tokenUserInfoIdcard, tokenAppInfoApplyCode, userVoMap, appVoMap, roleMap);
|
|
|
|
|
|
+ RoleAuthApplyDto applyDto = getRoleAuthApplyDto(tokenUserInfo, applyInfoVo, roles);
|
|
|
|
|
|
- ResponseStatus status = roleAuthApplyService.applyAndPushToApproval(applyDtos, null);
|
|
|
|
|
|
+ ResponseStatus status = roleAuthApplyService.applyAndPushToApproval(applyDto, null);
|
|
if (ResponseUtil.isFail(status)) {
|
|
if (ResponseUtil.isFail(status)) {
|
|
return getErrorApplyResp(AuthApplyRespEnum.OTHER, status.getMessage());
|
|
return getErrorApplyResp(AuthApplyRespEnum.OTHER, status.getMessage());
|
|
}
|
|
}
|
|
return ZeroTrustDataRespVO.success(null);
|
|
return ZeroTrustDataRespVO.success(null);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private Result<ApplyInfoVo> validateApplyApp(String applyAppCode, ApplyInfoVo tokenAppInfo) {
|
|
|
|
+ ApplyInfoVo applyInfoVo = tokenAppInfo;
|
|
|
|
+ if (StringUtils.isNotBlank(applyAppCode)) {
|
|
|
|
+ ApplyInfo appByCode = applyInfoFacade.getAppByCode(applyAppCode);
|
|
|
|
+ if (Objects.isNull(appByCode)) {
|
|
|
|
+ return Result.fail();
|
|
|
|
+ }
|
|
|
|
+ ApplyInfoVo vo = new ApplyInfoVo();
|
|
|
|
+ BeanUtil.copyProperties(appByCode, vo);
|
|
|
|
+ applyInfoVo = vo;
|
|
|
|
+ }
|
|
|
|
+ return Result.success(applyInfoVo);
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public ZeroTrustDataRespVO<AuthApplyRespVo> serviceAuthApply(@Valid ApiServiceAuthReqVo reqVo) {
|
|
public ZeroTrustDataRespVO<AuthApplyRespVo> serviceAuthApply(@Valid ApiServiceAuthReqVo reqVo) {
|
|
log.info("服务授权申请,应用令牌:{}, 申请内容:{}", reqVo.getAppTokenId(), JSONUtil.toJsonStr(reqVo));
|
|
log.info("服务授权申请,应用令牌:{}, 申请内容:{}", reqVo.getAppTokenId(), JSONUtil.toJsonStr(reqVo));
|
|
@@ -211,19 +211,17 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
|
|
return ZeroTrustDataRespVO.resultEnumMessage(ZeroTrustBusinessRespEnum.TOKEN_FAIL);
|
|
return ZeroTrustDataRespVO.resultEnumMessage(ZeroTrustBusinessRespEnum.TOKEN_FAIL);
|
|
}
|
|
}
|
|
ApplyInfoVo tokenAppInfo = appTokenDetail.getApplyInfo();
|
|
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();
|
|
|
|
|
|
+ String applyAppCode = reqVo.getContents().getAppCode();
|
|
|
|
+ Result<ApplyInfoVo> appResult = validateApplyApp(applyAppCode, tokenAppInfo);
|
|
if (appResult.isFail()) {
|
|
if (appResult.isFail()) {
|
|
- return getErrorApplyResp(AuthApplyRespEnum.APP_NOT_EXIST, applyInfoVos);
|
|
|
|
|
|
+ return getErrorApplyResp(AuthApplyRespEnum.APP_NOT_EXIST, Collections.singletonList(applyAppCode));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
// 校验服务资源
|
|
// 校验服务资源
|
|
- Result<List<ServiceResourceDTO>> serviceResult = getApplyServiceInfos(reqVo, applyInfoVos);
|
|
|
|
|
|
+ Result<List<ServiceResourceDTO>> serviceResult = getApplyServiceInfos(reqVo.getContents().getServiceCodes());
|
|
List<ServiceResourceDTO> serviceInfos = serviceResult.getContent();
|
|
List<ServiceResourceDTO> serviceInfos = serviceResult.getContent();
|
|
if (serviceResult.isFail()) {
|
|
if (serviceResult.isFail()) {
|
|
return getErrorApplyResp(AuthApplyRespEnum.SERVICE_NOT_EXIST, serviceInfos);
|
|
return getErrorApplyResp(AuthApplyRespEnum.SERVICE_NOT_EXIST, serviceInfos);
|
|
@@ -233,9 +231,10 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
|
|
setSecurityUser(appTokenDetail);
|
|
setSecurityUser(appTokenDetail);
|
|
|
|
|
|
// 组装批量申请dto
|
|
// 组装批量申请dto
|
|
- List<ServiceAuthApplyDto> applyDtos = getServiceAuthApplyDtos(reqVo, tokenAppInfo.getApplyCode(), applyInfoVos, serviceInfos);
|
|
|
|
|
|
+ ApplyInfoVo applyInfoVo = appResult.getContent();
|
|
|
|
+ ServiceAuthApplyDto applyDto = getServiceAuthApplyDto(applyInfoVo, serviceInfos);
|
|
|
|
|
|
- ResponseStatus status = serviceAuthApplyService.applyAndPushToApproval(applyDtos, null);
|
|
|
|
|
|
+ ResponseStatus status = serviceAuthApplyService.applyAndPushToApproval(applyDto, null);
|
|
if (ResponseUtil.isFail(status)) {
|
|
if (ResponseUtil.isFail(status)) {
|
|
return getErrorApplyResp(AuthApplyRespEnum.OTHER, status.getMessage());
|
|
return getErrorApplyResp(AuthApplyRespEnum.OTHER, status.getMessage());
|
|
}
|
|
}
|
|
@@ -243,83 +242,31 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
|
|
return ZeroTrustDataRespVO.success(null);
|
|
return ZeroTrustDataRespVO.success(null);
|
|
}
|
|
}
|
|
|
|
|
|
- private List<ServiceAuthApplyDto> getServiceAuthApplyDtos(ApiServiceAuthReqVo reqVo, String defaultAppCode, 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 -> {
|
|
|
|
- String appCode = Optional.ofNullable(e.getAppCode()).orElse(defaultAppCode);
|
|
|
|
- ApplyInfoVo applyInfoVo = appMap.get(appCode);
|
|
|
|
- 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 ServiceAuthApplyDto getServiceAuthApplyDto(ApplyInfoVo applyInfoVo, List<ServiceResourceDTO> serviceInfos) {
|
|
|
|
+ ServiceAuthApplyDto dto = new ServiceAuthApplyDto();
|
|
|
|
+ dto.setApplyInfoVo(applyInfoVo);
|
|
|
|
+ List<ServiceResourceVo> list = DcucBeanUtil.createCopyToObjectList(serviceInfos, ServiceResourceVo.class);
|
|
|
|
+ list.forEach(e -> e.setAppName(applyInfoVo.getApplyName()));
|
|
|
|
+ dto.setServiceVos(list);
|
|
|
|
+ return dto;
|
|
}
|
|
}
|
|
|
|
|
|
- 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());
|
|
|
|
|
|
+ private Result<List<ServiceResourceDTO>> getApplyServiceInfos(List<String> serviceCodes) {
|
|
List<ServiceResourceDTO> serviceInfos = serviceResourceFacade.getServiceByServiceCodes(serviceCodes);
|
|
List<ServiceResourceDTO> serviceInfos = serviceResourceFacade.getServiceByServiceCodes(serviceCodes);
|
|
- Result<List<ServiceResourceDTO>> validated = validateServiceInfos(serviceInfos, contents);
|
|
|
|
|
|
+ Result<List<ServiceResourceDTO>> validated = validateServiceInfos(serviceInfos, serviceCodes);
|
|
if (validated.isFail()) {
|
|
if (validated.isFail()) {
|
|
return validated;
|
|
return validated;
|
|
}
|
|
}
|
|
return Result.success(serviceInfos);
|
|
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));
|
|
|
|
- List<ServiceResourceDTO> errList = new ArrayList<>();
|
|
|
|
- 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());
|
|
|
|
- errList.addAll(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)) {
|
|
|
|
- errList.addAll(notExist);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (!errList.isEmpty()) {
|
|
|
|
- return Result.fail(ResultEnum.FAIL.getValue(), AuthApplyRespEnum.SERVICE_NOT_EXIST.getValue(), errList);
|
|
|
|
- } else {
|
|
|
|
- return Result.success();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private ZeroTrustDataRespVO<AuthApplyRespVo> getErrorApplyResp(AuthApplyRespEnum authApplyRespEnum, Object content) {
|
|
private ZeroTrustDataRespVO<AuthApplyRespVo> getErrorApplyResp(AuthApplyRespEnum authApplyRespEnum, Object content) {
|
|
AuthApplyRespVo vo = new AuthApplyRespVo();
|
|
AuthApplyRespVo vo = new AuthApplyRespVo();
|
|
vo.setRespCode(authApplyRespEnum.getValue());
|
|
vo.setRespCode(authApplyRespEnum.getValue());
|
|
vo.setRespMsg(authApplyRespEnum.getLabel());
|
|
vo.setRespMsg(authApplyRespEnum.getLabel());
|
|
switch (authApplyRespEnum) {
|
|
switch (authApplyRespEnum) {
|
|
case APP_NOT_EXIST:
|
|
case APP_NOT_EXIST:
|
|
- List<ApplyInfoVo> apps = (List<ApplyInfoVo>) content;
|
|
|
|
- List<String> appCodes = apps.stream().map(ApplyInfoVo::getApplyCode).collect(Collectors.toList());
|
|
|
|
|
|
+ List<String> appCodes = (List<String>) content;
|
|
vo.setRespContent(appCodes);
|
|
vo.setRespContent(appCodes);
|
|
break;
|
|
break;
|
|
case USER_NOT_EXIST:
|
|
case USER_NOT_EXIST:
|
|
@@ -361,66 +308,46 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
|
|
return ZeroTrustDataRespVO.resultEnumMessage(ZeroTrustBusinessRespEnum.OPERATE_FAIL, vo);
|
|
return ZeroTrustDataRespVO.resultEnumMessage(ZeroTrustBusinessRespEnum.OPERATE_FAIL, vo);
|
|
}
|
|
}
|
|
|
|
|
|
- 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);
|
|
|
|
- String appCode = Optional.ofNullable(e.getAppCode()).orElse(defaultAppCode);
|
|
|
|
-
|
|
|
|
- RoleAuthApplyDto applyDto = new RoleAuthApplyDto();
|
|
|
|
- applyDto.setUserInfo(userVoMap.get(applyUserIdcard));
|
|
|
|
-
|
|
|
|
- ApplyInfoVo applyInfoVo = appVoMap.get(appCode);
|
|
|
|
- List<RoleInfo> roleList = roleMap.get(applyInfoVo.getId());
|
|
|
|
- List<ApplyRoleInVo> collect = roleList.stream().map(r -> {
|
|
|
|
- ApplyRoleInVo applyVo = new ApplyRoleInVo();
|
|
|
|
- applyVo.setApply(BooleanEnum.FALSE.value);
|
|
|
|
- applyVo.setRoleCode(r.getCode());
|
|
|
|
- applyVo.setRoleName(r.getName());
|
|
|
|
- applyVo.setAppId(applyInfoVo.getId());
|
|
|
|
- applyVo.setAppName(applyInfoVo.getApplyName());
|
|
|
|
- return applyVo;
|
|
|
|
- }).collect(Collectors.toList());
|
|
|
|
- applyDto.setApplyRoleIns(collect);
|
|
|
|
- return applyDto;
|
|
|
|
|
|
+ private RoleAuthApplyDto getRoleAuthApplyDto(AuthUserVo userVo, ApplyInfoVo applyInfoVo, List<RoleInfo> roleList) {
|
|
|
|
+ RoleAuthApplyDto applyDto = new RoleAuthApplyDto();
|
|
|
|
+ applyDto.setUserInfo(userVo);
|
|
|
|
+ List<ApplyRoleInVo> collect = roleList.stream().map(r -> {
|
|
|
|
+ ApplyRoleInVo applyVo = new ApplyRoleInVo();
|
|
|
|
+ applyVo.setApply(BooleanEnum.FALSE.value);
|
|
|
|
+ applyVo.setRoleCode(r.getCode());
|
|
|
|
+ applyVo.setRoleName(r.getName());
|
|
|
|
+ applyVo.setAppId(applyInfoVo.getId());
|
|
|
|
+ applyVo.setAppName(applyInfoVo.getApplyName());
|
|
|
|
+ return applyVo;
|
|
}).collect(Collectors.toList());
|
|
}).collect(Collectors.toList());
|
|
|
|
+ applyDto.setApplyRoleIns(collect);
|
|
|
|
+ return applyDto;
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
- private Result<List<RoleInfo>> getApplyRoles(ApiRoleAuthReqVo reqVo, List<ApplyInfoVo> applyInfoVos) {
|
|
|
|
- List<ApiRoleAuthContentVo> contents = reqVo.getContents();
|
|
|
|
- List<String> roleCodes = contents.stream()
|
|
|
|
- .map(ApiRoleAuthContentVo::getRoleCodes)
|
|
|
|
- .flatMap(List::stream)
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
|
+ private Result<List<RoleInfo>> getApplyRoles(List<String> roleCodes, ApplyInfoVo applyInfoVo) {
|
|
List<RoleInfo> roleInfos = roleInfoService.getByCodes(roleCodes);
|
|
List<RoleInfo> roleInfos = roleInfoService.getByCodes(roleCodes);
|
|
- Result<List<RoleInfo>> validated = validateApplyRoles(applyInfoVos, roleInfos, contents);
|
|
|
|
|
|
+ Result<List<RoleInfo>> validated = validateApplyRoles(applyInfoVo, roleInfos, roleCodes);
|
|
if (validated.isFail()) {
|
|
if (validated.isFail()) {
|
|
return validated;
|
|
return validated;
|
|
}
|
|
}
|
|
return Result.success(roleInfos);
|
|
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));
|
|
|
|
|
|
+ private Result<List<RoleInfo>> validateApplyRoles(ApplyInfoVo applyInfoVo, List<RoleInfo> roleInfos, List<String> roleCodes) {
|
|
List<RoleInfo> errList = new ArrayList<>();
|
|
List<RoleInfo> errList = new ArrayList<>();
|
|
- for (ApiRoleAuthContentVo authVo : contents) {
|
|
|
|
- String appCode = authVo.getAppCode();
|
|
|
|
- List<String> appRoleCodes = authVo.getRoleCodes();
|
|
|
|
- ApplyInfoVo applyInfoVo = appMap.get(appCode);
|
|
|
|
- List<RoleInfo> roles = roleMap.get(applyInfoVo.getId());
|
|
|
|
- if (CollectionUtils.isEmpty(roles)) {
|
|
|
|
- List<RoleInfo> notExistRoles = mapNotExistRoles(appRoleCodes, applyInfoVo);
|
|
|
|
- errList.addAll(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(roleInfos)) {
|
|
|
|
+ List<RoleInfo> notExistRoles = mapNotExistRoles(roleCodes, applyInfoVo);
|
|
|
|
+ errList.addAll(notExistRoles);
|
|
|
|
+ } else {
|
|
|
|
+ Set<String> exist = roleInfos.stream().map(RoleInfo::getCode).collect(Collectors.toSet());
|
|
|
|
+ List<String> notExist = roleCodes.stream().filter(e -> !exist.contains(e)).collect(Collectors.toList());
|
|
if (CollectionUtils.isEmpty(notExist)) {
|
|
if (CollectionUtils.isEmpty(notExist)) {
|
|
List<RoleInfo> notExistRoles = mapNotExistRoles(notExist, applyInfoVo);
|
|
List<RoleInfo> notExistRoles = mapNotExistRoles(notExist, applyInfoVo);
|
|
errList.addAll(notExistRoles);
|
|
errList.addAll(notExistRoles);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
if (!errList.isEmpty()) {
|
|
if (!errList.isEmpty()) {
|
|
return Result.fail(ResultEnum.FAIL.getValue(), AuthApplyRespEnum.ROLE_NOT_EXIST.getValue(), errList);
|
|
return Result.fail(ResultEnum.FAIL.getValue(), AuthApplyRespEnum.ROLE_NOT_EXIST.getValue(), errList);
|
|
} else {
|
|
} else {
|
|
@@ -428,79 +355,43 @@ public class ZeroTrustAuthApplyBusinessImpl implements IZeroTrustAuthApplyBusine
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private static List<RoleInfo> mapNotExistRoles(List<String> appRoleCodes, ApplyInfoVo applyInfoVo) {
|
|
|
|
- return appRoleCodes.stream().map(e -> {
|
|
|
|
- RoleInfo roleInfo = new RoleInfo();
|
|
|
|
- roleInfo.setAppId(applyInfoVo.getApplyCode());
|
|
|
|
- roleInfo.setCode(e);
|
|
|
|
- return roleInfo;
|
|
|
|
- }).collect(Collectors.toList());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private Result<List<ApplyInfoVo>> getAppInfos(List<String> applyAppCodes, ApplyInfoVo defaultApp) {
|
|
|
|
- List<ApplyInfoVo> appInfoVos = new ArrayList<>();
|
|
|
|
- appInfoVos.add(defaultApp);
|
|
|
|
- if (CollectionUtils.isNotEmpty(applyAppCodes)) {
|
|
|
|
- List<ApplyInfo> appInfos = applyInfoFacade.getListByCodes(applyAppCodes);
|
|
|
|
- Result<List<ApplyInfoVo>> validated = validateApplyApps(applyAppCodes, appInfos);
|
|
|
|
- if (validated.isFail()) {
|
|
|
|
- return validated;
|
|
|
|
|
|
+ private Result<List<ServiceResourceDTO>> validateServiceInfos(List<ServiceResourceDTO> serviceInfos, List<String> serviceCodes) {
|
|
|
|
+ List<ServiceResourceDTO> errList = new ArrayList<>();
|
|
|
|
+ if (CollectionUtils.isEmpty(serviceInfos)) {
|
|
|
|
+ List<ServiceResourceDTO> notExist = mapNotExistService(serviceCodes);
|
|
|
|
+ errList.addAll(notExist);
|
|
|
|
+ } else {
|
|
|
|
+ Set<String> existCodes = serviceInfos.stream().map(ServiceResourceDTO::getServiceCode).collect(Collectors.toSet());
|
|
|
|
+ List<String> notExist = serviceCodes.stream().filter(e -> !existCodes.contains(e)).collect(Collectors.toList());
|
|
|
|
+ if (CollectionUtils.isNotEmpty(notExist)) {
|
|
|
|
+ List<ServiceResourceDTO> serviceResourceDTOS = mapNotExistService(notExist);
|
|
|
|
+ errList.addAll(serviceResourceDTOS);
|
|
}
|
|
}
|
|
- List<ApplyInfoVo> list = DcucBeanUtil.createCopyToObjectList(appInfos, ApplyInfoVo.class);
|
|
|
|
- appInfoVos.addAll(list);
|
|
|
|
}
|
|
}
|
|
- 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);
|
|
|
|
|
|
+ if (!errList.isEmpty()) {
|
|
|
|
+ return Result.fail(ResultEnum.FAIL.getValue(), AuthApplyRespEnum.SERVICE_NOT_EXIST.getValue(), errList);
|
|
|
|
+ } else {
|
|
|
|
+ return Result.success();
|
|
}
|
|
}
|
|
- return Result.success();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- private Result<List<AuthUserVo>> getApplyUserInfo(ApiRoleAuthReqVo reqVo, AuthUserVo defaultUserVo) {
|
|
|
|
- List<String> applyUserIdcards = reqVo.getContents()
|
|
|
|
- .stream()
|
|
|
|
- .map(ApiRoleAuthContentVo::getApplyUserIdcard)
|
|
|
|
- .distinct()
|
|
|
|
- .filter(StringUtils::isNotBlank)
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
-
|
|
|
|
- List<AuthUserVo> list = new ArrayList<>();
|
|
|
|
- list.add(defaultUserVo);
|
|
|
|
- if (CollectionUtils.isNotEmpty(applyUserIdcards)) {
|
|
|
|
- List<AuthUserInfo> userInfos = userInfoService.findByIdcards(applyUserIdcards);
|
|
|
|
- // 判断人员是否都存在
|
|
|
|
- Result<List<AuthUserVo>> validated = validateApplyUsers(userInfos, applyUserIdcards);
|
|
|
|
- if (validated.isFail()) {
|
|
|
|
- return validated;
|
|
|
|
- }
|
|
|
|
- List<AuthUserVo> userVos = DcucBeanUtil.createCopyToObjectList(userInfos, AuthUserVo.class);
|
|
|
|
- list.addAll(userVos);
|
|
|
|
- }
|
|
|
|
- return Result.success(list);
|
|
|
|
|
|
+ private List<ServiceResourceDTO> mapNotExistService(List<String> serviceCodes) {
|
|
|
|
+ List<ServiceResourceDTO> notExist = serviceCodes.stream().map(e -> {
|
|
|
|
+ ServiceResourceDTO dto = new ServiceResourceDTO();
|
|
|
|
+ dto.setServiceCode(e);
|
|
|
|
+ return dto;
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+ return notExist;
|
|
}
|
|
}
|
|
|
|
|
|
- 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 List<RoleInfo> mapNotExistRoles(List<String> appRoleCodes, ApplyInfoVo applyInfoVo) {
|
|
|
|
+ return appRoleCodes.stream().map(e -> {
|
|
|
|
+ RoleInfo roleInfo = new RoleInfo();
|
|
|
|
+ roleInfo.setAppId(applyInfoVo.getApplyCode());
|
|
|
|
+ roleInfo.setCode(e);
|
|
|
|
+ return roleInfo;
|
|
|
|
+ }).collect(Collectors.toList());
|
|
}
|
|
}
|
|
|
|
|
|
private void setSecurityUser(AppTokenDetailRespVo appTokenDetail) {
|
|
private void setSecurityUser(AppTokenDetailRespVo appTokenDetail) {
|