Skip to content

CryptoFactoryBean keystore location can't resolve ClassPathResource where resource is located in a jar [SWS-726] #706

@gregturn

Description

@gregturn

Kyle Cronin opened SWS-726 and commented

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

Affects: 2.0.2

Referenced from: commits 93063cf

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions