use of com.itrus.portal.db.CrlContext in project portal by ixinportal.
the class CrlContextController method delete.
// 删除
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE, produces = "text/html")
public String delete(@PathVariable("id") Long id, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, HttpServletRequest request, Model uiModel) {
String retPath = getReferer(request, "redirect:/crlcontext", true);
CrlContext crlContext = sqlSession.selectOne("com.itrus.portal.db.CrlContextMapper.selectByPrimaryKey", id);
if (crlContext == null) {
uiModel.addAttribute("message", "未找到要删除信任源信息");
} else {
try {
X509Certificate x509cert = null;
if (crlContext.getCaCertBuf() != null && crlContext.getCaCertBuf().length > 0) {
x509cert = X509Certificate.getInstance(crlContext.getCaCertBuf());
}
sqlSession.delete("com.itrus.portal.db.CrlContextMapper.deleteByPrimaryKey", id);
// 删除ca的支持
cacheCustomer.initCrlConfig();
String oper = "删除信任源";
String info = "证书主题: " + crlContext.getCertSubject() + "\r\n" + "crl颁发地址" + crlContext.getCrlUrl();
LogUtil.adminlog(sqlSession, oper, info);
} catch (Exception e) {
uiModel.addAttribute("message", "要删除信任源存在关联,无法删除");
}
}
return retPath;
}
use of com.itrus.portal.db.CrlContext in project portal by ixinportal.
the class CrlContextController method updateForm.
// 返回修改页面
@RequestMapping(value = "/{id}", params = "form", produces = "text/html")
public String updateForm(@PathVariable("id") Long id, Model uiModel) {
CrlContext crlContext = sqlSession.selectOne("com.itrus.portal.db.CrlContextMapper.selectByPrimaryKey", id);
uiModel.addAttribute("crlContext", crlContext);
return "crlcontext/update";
}
use of com.itrus.portal.db.CrlContext in project portal by ixinportal.
the class CrlContextController method show.
// 显示详情
@RequestMapping(value = "/{id}", produces = "text/html")
public String show(@PathVariable("id") Long id, Model uiModel) {
CrlContext crlContext = sqlSession.selectOne("com.itrus.portal.db.CrlContextMapper.selectByPrimaryKey", id);
uiModel.addAttribute("crlContext", crlContext);
return "crlcontext/show";
}
use of com.itrus.portal.db.CrlContext in project portal by ixinportal.
the class CrlContextController method update.
// 修改处理
@RequestMapping(params = "update", produces = "text/html")
public String update(@Valid CrlContext crlContext, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
if (bindingResult.hasErrors()) {
uiModel.addAttribute("crlContext", crlContext);
uiModel.addAttribute("message", "提交数据不正确");
return "crlcontext/update";
}
CrlContext crlContext0 = sqlSession.selectOne("com.itrus.portal.db.CrlContextMapper.selectByPrimaryKey", crlContext.getId());
// 不存在要更新数据时,抛出异常
if (crlContext0 == null) {
uiModel.addAttribute("crlContext", crlContext);
uiModel.addAttribute("message", "要修改数据不存在");
return "crlcontext/update";
}
// 检查是否包含CA证书
if (crlContext.getCaCertBuf() == null || crlContext.getCaCertBuf().length == 0) {
crlContext0.setCheckCrl(crlContext.getCheckCrl());
crlContext0.setCrlUrl(crlContext.getCrlUrl());
crlContext0.setRetryPolicy(crlContext.getRetryPolicy());
sqlSession.update("com.itrus.portal.db.CrlContextMapper.updateByPrimaryKeySelective", crlContext0);
} else {
String message = null;
// 验证CRL文件有效性
try {
X509Certificate caCert = com.itrus.cert.X509Certificate.getInstance(crlContext.getCaCertBuf());
crlContext.setIssuerdn(caCert.getIssuerDNString());
crlContext.setCertSn(caCert.getHexSerialNumber().toUpperCase());
crlContext.setCertSubject(caCert.getSubjectDNString());
crlContext.setCertStartTime(caCert.getNotBefore());
crlContext.setCertEndTime(caCert.getNotAfter());
// 检查crl文件的有效性,此处未设置
/*
* if (crlContext.crlBuf != null && crlContext.crlBuf.length > 0) {
* X509CRL crl =
* com.itrus.cert.X509CRL.getInstance(crlContext.crlBuf); if
* (crlContext.getCheckCrl()) { if
* (java.security.Security.getProvider("BC") == null) {
* java.security.Security.addProvider(new BouncyCastleProvider()); }
* crl.verify(caCert.publicKey); } }
*/
} catch (Exception e) {
if (e instanceof SignatureException)
message = "CRL签名验证失败,请您检查CRL是否为CA签发。";
else if (e instanceof CertificateException)
message = "X509Certificate对象实例化失败,请您检查CA证书格式是否正确。";
else if (e instanceof CRLException)
message = "X509CRL对象实例化失败,请您检查CRL文件格式是否正确。";
uiModel.addAttribute("message", message);
return updateForm(crlContext.getId(), uiModel);
}
sqlSession.update("com.itrus.portal.db.CrlContextMapper.updateByPrimaryKeyWithBLOBs", crlContext);
}
// 重新初始化信任源配置
cacheCustomer.initCrlConfig();
String oper = "修改信任源";
String info = "CA证书主题: " + crlContext.getCertSubject();
LogUtil.adminlog(sqlSession, oper, info);
return "redirect:/crlcontext/" + crlContext.getId();
}
use of com.itrus.portal.db.CrlContext in project portal by ixinportal.
the class TrustService method initCVM.
/**
* 初始化CVM
*/
public void initCVM() {
CVM.clear();
CrlContextExample example = new CrlContextExample();
List<CrlContext> contexts = sqlSession.selectList("com.itrus.portal.db.CrlContextMapper.selectByExampleWithBLOBs", example);
// 若没有配置信任源则不进行初始化
if (contexts.isEmpty())
return;
try {
for (CrlContext context : contexts) {
X509Certificate x509cert = null;
if (context.getCaCertBuf() != null && context.getCaCertBuf().length > 0) {
x509cert = X509Certificate.getInstance(context.getCaCertBuf());
}
CVM.addSupportCA(x509cert, context.getCrlUrl().trim(), context.getRetryPolicy().trim(), !context.getCheckCrl());
}
} catch (CertificateException e) {
e.printStackTrace();
} catch (NoSuchProviderException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations