package com.qianwen.license.controller; import java.util.ArrayList; import java.util.Arrays; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import com.alibaba.fastjson.JSONObject; import com.qianwen.license.common.License; import com.qianwen.license.common.LicenseCreator; import com.qianwen.license.common.LicenseExtraModel; import com.qianwen.license.dto.LicenseCreateDTO; @RestController public class LicenseCreateController { private static Logger logger = LoggerFactory.getLogger(LicenseCreateController.class); //@Autowired //SuperProcessParameterMapper pMapper; @PostMapping("create") public JSONObject generateLicense(@RequestBody LicenseCreateDTO createDTO) { JSONObject result = new JSONObject(); org.springframework.util.ResourceUtils a; org.apache.logging.log4j.LogManager b; try { // 生成license需要的一些参数 License param = new License(); // 证书授权主体(即CA机构,证书发放者,我们发放,应该是qianwen) param.setSubject(createDTO.getSubject()); // 私钥别名 param.setPrivateAlias(createDTO.getPrivateAlias()); // 私钥密码(需要妥善保管,不能让使用者知道) param.setKeyPass(createDTO.getKeyPass()); // 访问私钥库的密码 param.setStorePass(createDTO.getStorePass()); // 证书存储地址(磁盘位置) param.setLicensePath(createDTO.getLicensePath()); // 私钥库所在地址 param.setPrivateKeysStorePath(createDTO.getPrivateKeysStorePath()); //证书生效时间 param.setIssuedTime(createDTO.getIssuedTime()); param.setExpiryTime(createDTO.getExpiryTime()); // 用户类型 param.setConsumerType(createDTO.getConsumerType()); // 用户数量 param.setConsumerAmount(createDTO.getConsumerAmount()); // 描述 param.setDescription(createDTO.getDescription()); LicenseExtraModel extraModel = new LicenseExtraModel(); ArrayList macList = new ArrayList<>(Arrays.asList(StringUtils.split(createDTO.getMacAddress()))); extraModel.setMacAddress(macList); ArrayList ipList = new ArrayList<>(Arrays.asList(StringUtils.split(createDTO.getIpAddress()))); extraModel.setIpAddress(ipList); extraModel.setCpuSerial(createDTO.getCpuSerial()); extraModel.setExtData(createDTO.getExtData()); param.setLicenseExtraModel(extraModel);//这里配置额外信息,比如设备数量,ip等等 LicenseCreator licenseCreator = new LicenseCreator(param); // 生成license boolean genResult = licenseCreator.generateLicense(); logger.info("证书生成完成"); result.put("success", genResult); }catch(Exception e) { logger.error("生成证书失败",e); result.put("success", false); result.put("msg", e.getMessage()); } return result; } }