120 lines
3.1 KiB
Java
120 lines
3.1 KiB
Java
package com.sunyard.chsm.controller;
|
|
|
|
|
|
import com.sunyard.chsm.model.R;
|
|
import com.sunyard.chsm.model.dto.CertDTO;
|
|
import com.sunyard.chsm.param.CertExinfoResp;
|
|
import com.sunyard.chsm.param.CertInfoResp;
|
|
import com.sunyard.chsm.param.ExportCertReq;
|
|
import com.sunyard.chsm.param.ExportCertResp;
|
|
import com.sunyard.chsm.param.ImportCertReq;
|
|
import com.sunyard.chsm.service.AppCertService;
|
|
import com.sunyard.chsm.service.CertService;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.web.bind.WebDataBinder;
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.InitBinder;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.validation.Valid;
|
|
|
|
|
|
/**
|
|
* 证书管理类接口
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/cert")
|
|
public class CertController {
|
|
|
|
|
|
@Resource
|
|
private AppCertService appCertService;
|
|
|
|
@Resource
|
|
private CertService certService;
|
|
|
|
@InitBinder
|
|
public void initBinder(WebDataBinder binder) {
|
|
binder.setDisallowedFields("qwer");
|
|
}
|
|
|
|
/**
|
|
* 导出证书
|
|
*
|
|
* @param req
|
|
* @return
|
|
*/
|
|
@PostMapping("/exportCert")
|
|
public R<ExportCertResp> exportCert(@Valid @RequestBody ExportCertReq req) {
|
|
ExportCertResp resp = certService.exportCert(req);
|
|
return R.data(resp);
|
|
}
|
|
|
|
/**
|
|
* 获取证书信息
|
|
*
|
|
* @param certString 证书内容
|
|
*/
|
|
@GetMapping("/info")
|
|
public R<CertInfoResp> getCertInfo(@RequestParam String certString) {
|
|
CertInfoResp certInfo = certService.getCertInfo(certString);
|
|
return R.data(certInfo);
|
|
}
|
|
|
|
/**
|
|
* 获取证书拓展信息
|
|
*
|
|
* @param certString 证书内容
|
|
*/
|
|
@GetMapping("/exinfo")
|
|
public R<CertExinfoResp> getCertExinfo(@RequestParam String certString) {
|
|
CertExinfoResp certExinfo = certService.getCertExinfo(certString);
|
|
return R.data(certExinfo);
|
|
}
|
|
|
|
|
|
/**
|
|
* 验证证书
|
|
*
|
|
* @param certString 证书内容
|
|
*/
|
|
@GetMapping("/check")
|
|
public R<Boolean> certCheck(@RequestParam String certString) {
|
|
Boolean res = certService.checkCert(certString);
|
|
return R.data(res);
|
|
}
|
|
|
|
|
|
/**
|
|
* 导入证书
|
|
*
|
|
* @param req 证书
|
|
*/
|
|
@PostMapping("/import")
|
|
public R<Void> importCert(@Valid @RequestBody ImportCertReq req) {
|
|
CertDTO.ImportCert importCert = new CertDTO.ImportCert();
|
|
BeanUtils.copyProperties(req, importCert);
|
|
appCertService.importCert(importCert);
|
|
return R.ok();
|
|
}
|
|
|
|
/**
|
|
* 删除证书
|
|
*
|
|
* @param id id
|
|
* @return void
|
|
*/
|
|
@DeleteMapping
|
|
public R<Void> delete(Long id) {
|
|
appCertService.delete(id);
|
|
return R.ok();
|
|
}
|
|
|
|
}
|