Tuesday, July 3, 2012

Surefire/Failsafe maven plugin and SSL

I was puzzled today by an interesting feature introduced by the "surefire" and "failsafe" maven plugins (used for unit/integration test my components). These were introduced with their 2.1 release.  As I had components calling web services using 2-way SSL for authentication, I noticed that my test cases where failing when using maven via command line (mvn clean install). They worked on the IDE (Eclipse/STS) fine, but were not working on the command line. I saw the following error:
PKIX path building failed: ... unable to find valid certification path to requested target
 So it was clear that maven was not passing the SSL system properties from my .mavenrc file:

MAVEN_OPTS="-Djavax.net.ssl.keyStore=<YOU KEYSTORE FILE> \
-Djavax.net.ssl.keyStorePassword=<YOUR KEYSTORE PASSWORD> \
-Djavax.net.ssl.keyStoreType=JKS \
-Djavax.net.ssl.trustStore=<YOUR TRUSTSTORE FILE> \
-Djavax.net.ssl.trustStorePassword=<YOUR TRUSTSTORE PASSWORD> \
-Djavax.net.ssl.trustStoreType=JKS"
view raw .mavenrc hosted with ❤ by GitHub

This is what I discovered as I read more the documentation.