【问题标题】:File not found in getResource在 getResource 中找不到文件
【发布时间】:2017-08-13 12:39:31
【问题描述】:

我正在尝试加载资源文件夹中的 WS-security 证书,该证书已正确打包在我的 JAR 中。但是当我尝试加载它时,我得到了 FileNotFoundException。

我不能将我的证书放在 JAR 之外..

Caused by: org.apache.ws.security.components.crypto.CredentialException: Proxy file (vfs:/C:/Users/myuser/Redhat/jboss-eap-6.4/bin/content/myapp.ear/myapp.jar/CERT.PFX) not found.
    at org.apache.ws.security.components.crypto.Merlin.loadInputStream(Merlin.java:338) [wss4j-1.6.19.redhat-2.jar:1.6.19.redhat-2]
    at org.apache.ws.security.components.crypto.Merlin.loadProperties(Merlin.java:180) [wss4j-1.6.19.redhat-2.jar:1.6.19.redhat-2]
    at org.apache.ws.security.components.crypto.Merlin.<init>(Merlin.java:141) [wss4j-1.6.19.redhat-2.jar:1.6.19.redhat-2]
    at org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:117) [wss4j-1.6.19.redhat-2.jar:1.6.19.redhat-2]
    ... 71 more

Caused by: java.io.FileNotFoundException: vfs:/C:/Users/myuser/Redhat/jboss-eap-6.4/bin/content/myapp.ear/myapp.jar/CERT.PFX (The filename, directory name, or volume label syntax is incorrect)
    at java.io.FileInputStream.open0(Native Method) [rt.jar:1.8.0_102]
    at java.io.FileInputStream.open(FileInputStream.java:195) [rt.jar:1.8.0_102]
    at java.io.FileInputStream.<init>(FileInputStream.java:138) [rt.jar:1.8.0_102]
    at java.io.FileInputStream.<init>(FileInputStream.java:93) [rt.jar:1.8.0_102]
    at org.apache.ws.security.components.crypto.Merlin.loadInputStream(Merlin.java:333) [wss4j-1.6.19.redhat-2.jar:1.6.19.redhat-2]
    ... 74 more

Properties props = new Properties();
props.put("org.apache.ws.security.crypto.provider", "org.apache.ws.security.components.crypto.Merlin");
props.put("org.apache.ws.security.crypto.merlin.keystore.type", "PKCS12");
props.put("org.apache.ws.security.crypto.merlin.keystore.password", "passxxxx");
props.put("org.apache.ws.security.crypto.merlin.keystore.file", getClass().getResource("/CERT.PFX"));
props.put("org.apache.ws.security.crypto.merlin.keystore.alias", "aliasxxxx");

Map<String,Object> ctx = ((BindingProvider) iauthService).getRequestContext();

ctx.put("ws-security.signature.properties", props);

【问题讨论】:

    标签: java jboss cxf ws-security wss4j


    【解决方案1】:

    因此,您不能使用 FileInputStream 来读取打包在 JAR 中的文件 - 它不再是文件。 FileInputStream 仅适用于实际的磁盘文件。

    我最终从证书流创建了一个临时文件。 (How to convert InputStream to virtual File)

    然后将file.getPath() 传递到属性中。

    【讨论】:

      猜你喜欢
      • 2016-08-12
      • 1970-01-01
      • 1970-01-01
      • 2018-01-04
      • 2012-01-19
      • 1970-01-01
      • 2019-10-23
      • 2017-08-01
      • 1970-01-01
      相关资源
      最近更新 更多