[SWS-726] CryptoFactoryBean keystore location can't resolve ClassPathResource where resource is located in a jar Created: 24/Aug/11  Updated: 04/May/12  Resolved: 17/Oct/11

Status: Closed
Project: Spring Web Services
Component/s: Security
Affects Version/s: 2.0.2
Fix Version/s: 2.0.3

Type: Bug Priority: Minor
Reporter: Kyle Cronin Assignee: Arjen Poutsma
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: 14m
Original Estimate: Not Specified


When using a ClassPathResource to set the keyStoreLocation property, if the resource is located in a jar file a FileNotFoundException is thrown.

Caused by: java.io.FileNotFoundException: class path resource [com/foo/security/foo.keystore] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/C:/views/java/jboss/server/oneforce/deploy/oba.war/WEB-INF/lib/foo-security.jar!/com/foo/security/foo.keystore
	at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:204)
	at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:52)
	at org.springframework.ws.soap.security.wss4j.support.CryptoFactoryBean.setKeyStoreLocation(CryptoFactoryBean.java:88)

org.apache.ws.security.components.crypto.AbstractCrypto has it's own mechanism for locating classpath resources. The following patch will fallback to the ClassPathResource path if can't be resolved to a file.

public void setKeyStoreLocation(Resource location) throws IOException {
	String resourcePath = null;
	try {
		File keyStoreFile = location.getFile();
		resourcePath = keyStoreFile.getAbsolutePath();
	} catch (IOException ioe) {
		// can't resolve to file on the file system
		// allow org.apache.ws.security.components.crypto.AbstractCrypt to resolve from resource path
		if(location instanceof ClassPathResource) {
			resourcePath = ((ClassPathResource) location).getPath();
		} else {
			throw ioe;
	this.configuration.setProperty("org.apache.ws.security.crypto.merlin.file", resourcePath);	

Comment by Arjen Poutsma [ 17/Oct/11 ]

Fixed, thanks for the patch!

Comment by Arjen Poutsma [ 04/May/12 ]

Closing old issues

Generated at Wed Oct 17 07:19:00 UTC 2018 using JIRA 7.9.2#79002-sha1:3bb15b68ecd99a30eb364c4c1a393359bcad6278.