Uploaded image for project: 'Spring Web Services'
  1. Spring Web Services
  2. SWS-726

CryptoFactoryBean keystore location can't resolve ClassPathResource where resource is located in a jar

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0.2
    • Fix Version/s: 2.0.3
    • Component/s: Security
    • Labels:
      None

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

        Attachments

          Activity

            People

            • Assignee:
              arjen.poutsma Arjen Poutsma
              Reporter:
              kyle.cronin Kyle Cronin
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - Not Specified
                Not Specified
                Logged:
                Time Spent - 14m
                14m