I want to retrieve Common Name (CN) property from client certificate in SOAP communication. I'm using Spring WebServiceTemplate to create my webservice endpoint. I have already implemented WS mutual authentication following the example.
Is there any solution to obtain certificate details from client request by means of WebServiceTemplate or some other library?
Fortunately, I have managed to figure it out! Spring WS provides very convenient way to retrieve the X509Certificate.
Normally, You have an endpoint like this:
However, Spring allows to add additional parameters the method annotated as @PayloadRoot. It can be a MessageContext instance.
Then You will be able to obtain the
wsse:Securityheader as follows:Now get the right content of
BinarySecurityTokentag:At the end, you should recreate the X509Certificate by passing binarySecurityToken as its constructor parameter. Later You can extract CN by many different ways for example by means of LDAP utlis.