[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


 Description   

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.

org.springframework.ws.soap.security.wss4j.support.CryptoFactoryBean

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);	
}



 Comments   
Comment by Arjen Poutsma [ 17/Oct/11 ]

Fixed, thanks for the patch!

Comment by Arjen Poutsma [ 04/May/12 ]

Closing old issues

Generated at Sat Dec 16 16:45:55 UTC 2017 using JIRA 6.4.14#64029-sha1:ae256fe0fbb912241490ff1cecfb323ea0905ca5.