我正在尝试使用正则表达式来匹配来自 X.509 证书的 CN。
整个字符串看起来像这样:
CN=杰森,OU=MYOU,O=MYORG
这是无效的代码:
Object certChain = request
.getAttribute("javax.servlet.request.X509Certificate");
String name = "";
if (certChain != null) {
X509Certificate certs[] = (X509Certificate[]) certChain;
X509Certificate cert = certs[0];
name = cert.getSubjectDN().getName();
}
String strPattern = "CN=(.*?),";
Pattern pattern = Pattern.compile(strPattern);
Matcher matcher = pattern.matcher(name);
String cname = "";
if (matcher.matches()) {
cname = matcher.group(1);
}
Matcher.matches() 返回 false,但我看不出该模式有问题。任何人都可以帮忙吗?
杰森