Is there a way to recover the common name of a client certificate from java code in a 2 way ssl connection?

妖精的绣舞 提交于 2019-12-07 01:51:26
Vineet Reynolds

The client's certificate can be read from the incoming Servlet request using the HttpServletRequest.getAttribute(String) method invocation. The attribute with name javax.servlet.request.X509Certificate is populated by the servlet container when it creates an instance of the Request object for processing by the servlet/webservice.

The DN of the certificate can then be obtained from the X500Principal object, obtained from the certificate object via the getX500Principal method invocation. This does not give the CN, but will provide your with the complete distinguished name in a specified format; this could be parsed to provide the CN.

As far as accessing the ServletRequest object is concerned, JAX-WS web services can be programmed to read the MessageContext which allows access to the underlying HttpServletRequest object.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!