对称密钥管理
This commit is contained in:
parent
7452400add
commit
6d03864e23
20
chsm-common/src/main/java/com/sunyard/chsm/model/Option.java
Normal file
20
chsm-common/src/main/java/com/sunyard/chsm/model/Option.java
Normal file
@ -0,0 +1,20 @@
|
||||
package com.sunyard.chsm.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author liulu
|
||||
* @since 2024/10/28
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Option {
|
||||
|
||||
public String code;
|
||||
private String text;
|
||||
|
||||
|
||||
}
|
@ -1,8 +1,13 @@
|
||||
package com.sunyard.chsm.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.sunyard.chsm.dto.KeyInfoDTO;
|
||||
import com.sunyard.chsm.enums.KeyCategory;
|
||||
import com.sunyard.chsm.enums.KeyStatus;
|
||||
import com.sunyard.chsm.model.Option;
|
||||
import com.sunyard.chsm.model.R;
|
||||
import com.sunyard.chsm.service.KeyInfoService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@ -10,6 +15,9 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 对称密钥管理接口
|
||||
@ -24,6 +32,31 @@ public class SymKeyController {
|
||||
@Resource
|
||||
private KeyInfoService keyInfoService;
|
||||
|
||||
/**
|
||||
* 获取密钥状态列表
|
||||
*/
|
||||
@GetMapping("/statusList")
|
||||
public R<List<Option>> getStatusList() {
|
||||
|
||||
List<Option> options = Arrays.stream(KeyStatus.values())
|
||||
.map(it -> new Option(it.getCode(), it.getDesc()))
|
||||
.collect(Collectors.toList());
|
||||
return R.data(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询对称密钥列表
|
||||
*
|
||||
* @param query 查询条件
|
||||
* @return 分页列表
|
||||
*/
|
||||
@GetMapping("/pageList")
|
||||
public R<Page<KeyInfoDTO.View>> servicePageList(KeyInfoDTO.Query query) {
|
||||
query.setKeyType(KeyCategory.SYM_KEY.getCode());
|
||||
Page<KeyInfoDTO.View> page = keyInfoService.selectPageList(query);
|
||||
|
||||
return R.data(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建密钥
|
||||
|
@ -1,9 +1,13 @@
|
||||
package com.sunyard.chsm.dto;
|
||||
|
||||
import com.sunyard.chsm.model.PageQuery;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author liulu
|
||||
@ -11,6 +15,13 @@ import javax.validation.constraints.NotNull;
|
||||
*/
|
||||
public abstract class KeyInfoDTO {
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public static class Query extends PageQuery {
|
||||
private String status;
|
||||
private String keyType;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Save {
|
||||
|
||||
@ -29,4 +40,37 @@ public abstract class KeyInfoDTO {
|
||||
}
|
||||
|
||||
|
||||
@Data
|
||||
public static class View {
|
||||
private Long id;
|
||||
/**
|
||||
* KEY_ID
|
||||
*/
|
||||
private String code;
|
||||
private String keyType;
|
||||
private String keyTypeText;
|
||||
private String keyAlg;
|
||||
private Integer keyLength;
|
||||
private List<String> keyUsages;
|
||||
private String keyUsageText;
|
||||
/**
|
||||
* 校验算法
|
||||
*/
|
||||
private String checkAlg;
|
||||
/**
|
||||
* 校验值
|
||||
*/
|
||||
private String checkValue;
|
||||
private String status;
|
||||
private String statusText;
|
||||
/**
|
||||
* 生效时间
|
||||
*/
|
||||
private LocalDateTime effectiveTime;
|
||||
/**
|
||||
* 过期时间
|
||||
*/
|
||||
private LocalDateTime expiredTime;
|
||||
private LocalDateTime createTime;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.sunyard.chsm.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.sunyard.chsm.dto.KeyInfoDTO;
|
||||
|
||||
/**
|
||||
@ -8,9 +9,8 @@ import com.sunyard.chsm.dto.KeyInfoDTO;
|
||||
*/
|
||||
public interface KeyInfoService {
|
||||
|
||||
Page<KeyInfoDTO.View> selectPageList(KeyInfoDTO.Query query);
|
||||
|
||||
Long save(KeyInfoDTO.Save save);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,13 @@
|
||||
package com.sunyard.chsm.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.sunyard.chsm.dto.KeyInfoDTO;
|
||||
import com.sunyard.chsm.enums.KeyCategory;
|
||||
import com.sunyard.chsm.enums.KeyStatus;
|
||||
import com.sunyard.chsm.enums.KeyUsage;
|
||||
import com.sunyard.chsm.mapper.KeyInfoMapper;
|
||||
import com.sunyard.chsm.mapper.KeyTemplateMapper;
|
||||
import com.sunyard.chsm.mapper.SpKeyRecordMapper;
|
||||
@ -16,13 +19,21 @@ import com.sunyard.chsm.sdf.model.EccKey;
|
||||
import com.sunyard.chsm.service.KeyInfoService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author liulu
|
||||
@ -42,6 +53,42 @@ public class KeyInfoServiceImpl implements KeyInfoService {
|
||||
private SdfApiService sdfApiService;
|
||||
|
||||
|
||||
@Override
|
||||
public Page<KeyInfoDTO.View> selectPageList(KeyInfoDTO.Query query) {
|
||||
|
||||
IPage<KeyInfo> page = keyInfoMapper.selectPage(
|
||||
new Page<>(query.getPageNumber(), query.getPageSize()),
|
||||
new LambdaQueryWrapper<KeyInfo>()
|
||||
.eq(StringUtils.hasText(query.getKeyType()), KeyInfo::getKeyType, query.getKeyType())
|
||||
.eq(StringUtils.hasText(query.getStatus()), KeyInfo::getStatus, query.getStatus())
|
||||
);
|
||||
List<KeyInfo> records = page.getRecords();
|
||||
if (CollectionUtils.isEmpty(records)) {
|
||||
return new Page<>(page.getCurrent(), page.getSize(), page.getTotal());
|
||||
}
|
||||
List<KeyInfoDTO.View> viewList = records.stream()
|
||||
.map(it -> {
|
||||
KeyInfoDTO.View view = new KeyInfoDTO.View();
|
||||
BeanUtils.copyProperties(it, view);
|
||||
Optional.ofNullable(KeyCategory.of(it.getKeyType()))
|
||||
.map(KeyCategory::getDesc)
|
||||
.ifPresent(view::setKeyTypeText);
|
||||
Map<String, String> usageMap = KeyUsage.getUsage(it.getKeyUsage())
|
||||
.stream()
|
||||
.collect(Collectors.toMap(KeyUsage::getCode, KeyUsage::getDesc));
|
||||
view.setKeyUsages(new ArrayList<>(usageMap.keySet()));
|
||||
view.setKeyUsageText(String.join(",", usageMap.values()));
|
||||
Optional.ofNullable(KeyStatus.of(it.getStatus()))
|
||||
.map(KeyStatus::getDesc)
|
||||
.ifPresent(view::setStatusText);
|
||||
|
||||
return view;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return new Page<KeyInfoDTO.View>(page.getCurrent(), page.getSize(), page.getTotal()).setRecords(viewList);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public Long save(KeyInfoDTO.Save save) {
|
||||
|
@ -43,7 +43,7 @@ public class KeyTemplateServiceImpl implements KeyTemplateService {
|
||||
@Override
|
||||
public Page<KeyTemplateDTO.View> selectPageList(KeyTemplateDTO.Query query) {
|
||||
LambdaQueryWrapper<KeyTemplate> wrapper = new LambdaQueryWrapper<KeyTemplate>()
|
||||
.like(StringUtils.hasText(query.getKeyType()), KeyTemplate::getKeyType, query.getKeyType());
|
||||
.eq(StringUtils.hasText(query.getKeyType()), KeyTemplate::getKeyType, query.getKeyType());
|
||||
|
||||
IPage<KeyTemplate> page = keyTemplateMapper.selectPage(
|
||||
new Page<>(query.getPageNumber(), query.getPageSize()),
|
||||
|
Loading…
Reference in New Issue
Block a user