diff --git a/chsm-common/src/main/java/com/sunyard/chsm/service/AppCertService.java b/chsm-common/src/main/java/com/sunyard/chsm/service/AppCertService.java index 17a0fce..0bedce5 100644 --- a/chsm-common/src/main/java/com/sunyard/chsm/service/AppCertService.java +++ b/chsm-common/src/main/java/com/sunyard/chsm/service/AppCertService.java @@ -12,4 +12,6 @@ public interface AppCertService { Page selectPageList(CertDTO.Query query); void importCert(CertDTO.ImportCert importCert); + + void delete(Long id); } diff --git a/chsm-common/src/main/java/com/sunyard/chsm/service/impl/AppCertServiceImpl.java b/chsm-common/src/main/java/com/sunyard/chsm/service/impl/AppCertServiceImpl.java index 611a738..60fc7cf 100644 --- a/chsm-common/src/main/java/com/sunyard/chsm/service/impl/AppCertServiceImpl.java +++ b/chsm-common/src/main/java/com/sunyard/chsm/service/impl/AppCertServiceImpl.java @@ -173,6 +173,8 @@ public class AppCertServiceImpl implements AppCertService { } catch (Exception ex) { throw new IllegalArgumentException("证书内容格式错误,无法解析"); } + Assert.isTrue(Objects.equals(signCert.getSubjectX500Principal().getName(), encCert.getSubjectX500Principal().getName()), + "证书主题不一致"); PublicKey signPk = signCert.getPublicKey(); String signPkHex = BCECUtils.getHexPubKey((BCECPublicKey) signPk); String encPkHex = BCECUtils.getHexPubKey((BCECPublicKey) encCert.getPublicKey()); @@ -274,4 +276,25 @@ public class AppCertServiceImpl implements AppCertService { return Pair.of(Hex.toHexString(xy), pd); } + + @Override + public void delete(Long id) { + + AppCert appCert = appCertMapper.selectById(id); + Assert.notNull(appCert, "证书不存在"); + + if (appCert.getSingle()) { + appCertMapper.deleteById(id); + return; + } + + List appCerts = appCertMapper.selectList( + new LambdaQueryWrapper() + .eq(AppCert::getKeyId, appCert.getKeyId()) + .eq(AppCert::getSubject, appCert.getSubject()) + + ); + appCertMapper.deleteBatchIds(appCerts.stream().map(AppCert::getId).collect(Collectors.toList())); + } + } diff --git a/chsm-web-manage/src/main/java/com/sunyard/chsm/controller/AppCertController.java b/chsm-web-manage/src/main/java/com/sunyard/chsm/controller/AppCertController.java index e538b33..8f6ea6b 100644 --- a/chsm-web-manage/src/main/java/com/sunyard/chsm/controller/AppCertController.java +++ b/chsm-web-manage/src/main/java/com/sunyard/chsm/controller/AppCertController.java @@ -1,10 +1,13 @@ package com.sunyard.chsm.controller; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.sunyard.chsm.constant.AuditLogConst; import com.sunyard.chsm.model.R; import com.sunyard.chsm.model.dto.CertDTO; import com.sunyard.chsm.service.AppCertService; +import com.sunyard.ssp.common.annotation.AuditControllerLog; import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -53,5 +56,17 @@ public class AppCertController { appCertService.importCert(importCert); } + /** + * 删除证书 + * + * @param id id + * @return void + */ + @DeleteMapping + @AuditControllerLog(description = "删除证书", operateType = AuditLogConst.DELETE) + public R delete(Long id) { + appCertService.delete(id); + return R.ok(); + } }