The solution for me was to make another CryptoFactoryBean in which I searched for the jks in a different location.
1. I've put the jks in WEB-INF instead of WEB-INF/classes
2. in setKeyStoreLocation I obtained the root of the classpath (which is 'classes' directory) and stepped up one level in the search for the jks.
Below is the code:
Code:
public void setKeyStoreLocation(Resource location) throws IOException {
File keyStoreFile = null;
if (location.exists()) {
keyStoreFile = location.getFile();
}
else {
// if the resource is not found, search in /WEB-INF directory - one level up
// root of classpath is the 'classes' directory
log.debug("keyStoreLocation resource not found in classpath. Searching one level up from 'classes' directory");
String path = this.getClass().getResource("/").getPath();
String root = "/classes";
int index = path.lastIndexOf(root);
path = path.substring(0, index);
log.debug("resource " + location.getFilename() + " searched in path [" + path + "]");
path += "/" + location.getFilename();
keyStoreFile = new File(path);
if (keyStoreFile != null && keyStoreFile.exists()) {
log.debug("resource found in [" + keyStoreFile.getAbsolutePath() + "]");
}
else {
log.debug("resource not found .. bummer");
}
}
this.configuration.setProperty("org.apache.ws.security.crypto.merlin.file", keyStoreFile.getPath());
}
The bean definition:
Code:
<bean id="cryptoFactory" class="a.b.c.CustomCryptoFactoryBean">
<property name="keyStorePassword" value="password" />
<property name="keyStoreLocation" value="classpath:keystore.jks" />
</bean>