当我尝试从 Eclipse 运行以下代码时,我总是将返回值设为 null:
X509Certificate cert[] = (X509Certificate[]) request.getAttribute("javax.servlet.request.X509Certificate");
System.out.println("cert: " + cert[0]); //always returns null
有人可以帮我解决这个问题吗?我在某处读到说我必须将客户端身份验证值设置为 true,但我该怎么做呢?我使用 pom.xml 和 web.xml(附在下面)
web.xml:
<security-constraint>
<web-resource-collection>
<web-resource-name>HTTPS<web-resource-name>
<url-pattern>/*<url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>CLIENT-CERT</auth-method>
</login-config>
pom.xml:
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<httpsPort>8443</httpsPort>
<keystoreFile>${basedir}/certs/keystore.jks</keystoreFile>
<keystorePass>changeit</keystorePass>
</configuration>
任何帮助都非常感谢!
谢谢!