秘钥管理改造,服务端返回sign

1.x
tanghc 5 years ago
parent fe40161170
commit 800f7e8d82
  1. 29
      sop-gateway/src/main/java/com/gitee/sop/gateway/entity/IsvDetailDTO.java
  2. 10
      sop-gateway/src/main/java/com/gitee/sop/gateway/manager/DbIsvManager.java
  3. 15
      sop-gateway/src/main/java/com/gitee/sop/gateway/mapper/IsvInfoMapper.java

@ -0,0 +1,29 @@
package com.gitee.sop.gateway.entity;
import lombok.Data;
/**
* @author tanghc
*/
@Data
public class IsvDetailDTO {
/** appKey, 数据库字段:app_key */
private String appKey;
/** 0启用,1禁用, 数据库字段:status */
private Byte status;
// keys
/** secret, 数据库字段:secret */
private String secret;
/** 开发者生成的公钥, 数据库字段:public_key_isv */
private String publicKeyIsv;
/** 平台生成的私钥, 数据库字段:private_key_platform */
private String privateKeyPlatform;
private Byte signType;
}

@ -1,14 +1,12 @@
package com.gitee.sop.gateway.manager; package com.gitee.sop.gateway.manager;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.gitee.fastmybatis.core.query.Query; import com.gitee.sop.gateway.entity.IsvDetailDTO;
import com.gitee.sop.gateway.entity.IsvInfo;
import com.gitee.sop.gateway.mapper.IsvInfoMapper; import com.gitee.sop.gateway.mapper.IsvInfoMapper;
import com.gitee.sop.gatewaycommon.bean.ChannelMsg; import com.gitee.sop.gatewaycommon.bean.ChannelMsg;
import com.gitee.sop.gatewaycommon.bean.IsvDefinition; import com.gitee.sop.gatewaycommon.bean.IsvDefinition;
import com.gitee.sop.gatewaycommon.manager.ZookeeperContext; import com.gitee.sop.gatewaycommon.manager.ZookeeperContext;
import com.gitee.sop.gatewaycommon.secret.CacheIsvManager; import com.gitee.sop.gatewaycommon.secret.CacheIsvManager;
import com.gitee.sop.gatewaycommon.secret.SecretContext;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -16,7 +14,6 @@ import org.springframework.core.env.Environment;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import java.util.List; import java.util.List;
import java.util.function.Function;
/** /**
* @author tanghc * @author tanghc
@ -33,14 +30,11 @@ public class DbIsvManager extends CacheIsvManager {
@Override @Override
public void load() { public void load() {
List<IsvInfo> isvInfoList = isvInfoMapper.list(new Query()); List<IsvDetailDTO> isvInfoList = isvInfoMapper.listIsvDetail();
Function<IsvDefinition, String> secretGetter = SecretContext.getSecretGetter();
isvInfoList.stream() isvInfoList.stream()
.forEach(isvInfo -> { .forEach(isvInfo -> {
IsvDefinition isvDefinition = new IsvDefinition(); IsvDefinition isvDefinition = new IsvDefinition();
BeanUtils.copyProperties(isvInfo, isvDefinition); BeanUtils.copyProperties(isvInfo, isvDefinition);
String secret = secretGetter.apply(isvDefinition);
isvDefinition.setSecret(secret);
this.getIsvCache().put(isvDefinition.getAppKey(), isvDefinition); this.getIsvCache().put(isvDefinition.getAppKey(), isvDefinition);
}); });
} }

@ -1,11 +1,26 @@
package com.gitee.sop.gateway.mapper; package com.gitee.sop.gateway.mapper;
import com.gitee.fastmybatis.core.mapper.CrudMapper; import com.gitee.fastmybatis.core.mapper.CrudMapper;
import com.gitee.sop.gateway.entity.IsvDetailDTO;
import com.gitee.sop.gateway.entity.IsvInfo; import com.gitee.sop.gateway.entity.IsvInfo;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/** /**
* @author tanghc * @author tanghc
*/ */
public interface IsvInfoMapper extends CrudMapper<IsvInfo, Long> { public interface IsvInfoMapper extends CrudMapper<IsvInfo, Long> {
@Select("SELECT " +
" t.app_key appKey " +
" ,t.status " +
" ,t2.sign_type signType " +
" ,t2.secret " +
" ,t2.public_key_isv publicKeyIsv " +
" ,t2.private_key_platform privateKeyPlatform " +
"FROM isv_info t " +
"INNER JOIN isv_keys t2 ON t.app_key = t2.app_key")
List<IsvDetailDTO> listIsvDetail();
} }

Loading…
Cancel
Save