Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
gregturn opened this issue Aug 24, 2011 · 2 comments
Assignees
Labels
Milestone

Comments

@gregturn
Copy link
Member

@gregturn gregturn commented Aug 24, 2011

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

@gregturn
Copy link
Member Author

@gregturn gregturn commented Oct 17, 2011

Arjen Poutsma commented

Fixed, thanks for the patch!

@gregturn
Copy link
Member Author

@gregturn gregturn commented May 4, 2012

Arjen Poutsma commented

Closing old issues

@gregturn gregturn closed this May 4, 2012
@gregturn gregturn added the type: bug label Sep 22, 2020
@gregturn gregturn added this to the 2.0.3 milestone Sep 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.