更多内容请访问 www.uusystem.com
if(request.isSecure()) //判断是否采用SSL { final String attname= "javax.servlet.request.X509Certificate"; X509Certificate[] chain= (X509Certificate[])request.getAttribute(attname);//客户证书链 if(chain == null) { resultBasicVO.setMessage("没有客户端证书链"); return resultBasicVO; } X509Certificate userCert= chain[0]; //客户证书 String dname = userCert.getSubjectDN().getName(); String field = "CN="; String udata = dname.substring(dname.indexOf(field) + field.length()); String[] dataArr = udata.split(","); String nameAndId = dataArr[0]; String idcard = nameAndId.split(" ")[1]; resultBasicVO.setMessage(idcard); resultBasicVO.setResult(true); return resultBasicVO; }
参考链接:
https://blog.csdn.net/loman_yt/article/details/44675105