Hi
I don't understand one thing - if client makes HTTPS requests to your web application deployed on application server, then your application, and hence Spring, is invoked after all the processing related to SSL validation using TrustStore.
I can give you a solution where Spring (particularily Spring-WS client) makes calls to external, SSL-protected web service and must do server certificate validation using TrustStore, but that's not what you want.
On the opposite site, If you configure app server (what: Tomcat?, WebSphere?, other?) to not reject client connection on the basis of app server's trust establishment, then you can configure Spring-Security to properly perform X.509 validation:
Code:
<http auto-config="false" ...>
<!-- custom X.509 filter -->
<custom-filter position="X509_FILTER" ref="myX509AuthenticationFilter" />
</http>
<beans:bean id="myX509AuthenticationFilter" class="org.springframework.security.web.authentication.preauth.x509.X509AuthenticationFilter">
<beans:property name="authenticationManager" ref="authenticationManager" />
<beans:property name="principalExtractor">
<beans:bean class="com.example.MyX509PrincipalExtractor" />
</beans:property>
</beans:bean>
com.example.MyX509PrincipalExtractor could look like this (it returns serialNumber as principal name):
Code:
public class MyX509PrincipalExtractor implements X509PrincipalExtractor
{
private static Pattern serialNumber = Pattern.compile("serialNumber=([^=,]*)", Pattern.CASE_INSENSITIVE);
public Object extractPrincipal(X509Certificate cert)
{
String name = cert.getSubjectDN().getName();
Matcher m = serialNumber.matcher(name);
if (!m.find())
throw new BadCredentialsException("Haven't found serialNumber in certificate.");
return m.group(1);
}
}
regards
Grzegorz Grzybek