更新时间:2023-12-04 07:58:28
您将需要导入java.security.cert.X509Certificate
和.在您的doGet(...)
方法中,使用以下命令:
You will need to import java.security.cert.X509Certificate
and . In your doGet(...)
method, use the following:
String cn = null;
X509Certificate[] certs = (X509Certificate[]) req
.getAttribute("javax.servlet.request.X509Certificate");
if (certs != null) {
String dn = certs[0].getSubjectX500Principal().getName();
// parse the CN out from the DN (distinguished name)
Pattern p = Pattern.compile("(^|,)CN=([^,]*)(,|$)");
cn = p.matcher(dn).find().group(2);
} else {
// no certificate provided
}