【问题标题】:how to load the cxf wss4j crypto property file from external location other than the classpath如何从类路径以外的外部位置加载 cxf wss4j 加密属性文件
【发布时间】:2015-08-21 13:04:54
【问题描述】:

我正在尝试将签署 SOAP CXF 请求消息所需的 crypto.properties 文件外部化。 根据框架,它应该在类路径中有属性文件。 我无法从外部加载它。请帮助我,我已经尝试了很多技术。

我得到以下异常

org.apache.ws.security.WSSecurityException:一般安全错误(无法加载资源文件:

由于我们已经同步了我们的开发和生产环境代码库,因此将文件外部化是非常必要的

使用的CXF框架是2.6.10

【问题讨论】:

  • 框架是cxf 2.6.10
  • 哎呀,我也打了这个,不能固定在 CXF 上。这是 WSS4J 的限制,而 IMO 是严重的 CM/Infosec 限制。 WSHandlerConstants.SIG_PROP_FILE 的语义很烂。
  • 您可能应该添加更多关于您的运行时环境的信息。你是在应用服务器上运行它吗?

标签: java web-services cxf


【解决方案1】:

正如 Colm O hEigeartaigh 的回答中所述,可以使用最新版本的 CXF 和 WSS4J 从外部文件加载配置设置。但是,这仍然意味着需要将属性写入文件并再次加载它们。

您也可以在内存中构造一个 Properties 对象,并让 CXF 使用它。这也适用于较旧的 CXF 版本。这是通过扩展WSS4JInInterceptorWSS4JOutInterceptor,然后覆盖Crypto loadCryptoFromPropertiesFile(String propFilename, RequestData reqData) 方法并返回您自己的Crypto 对象来完成的,您可以使用CryptoFactory.getInstance(properties) 创建它。

比如:

Properties cxfProps = new Properties();
cxfProps.setProperty("org.apache.ws.security.crypto.provider", "org.apache.ws.security.components.crypto.Merlin");
cxfProps.setProperty("org.apache.ws.security.crypto.merlin.keystore.type", "jks");
cxfProps.setProperty("org.apache.ws.security.crypto.merlin.keystore.alias", "client");
cxfProps.setProperty("org.apache.ws.security.crypto.merlin.keystore.password", PASSWORD);
cxfProps.setProperty("org.apache.ws.security.crypto.merlin.keystore.file", "keystore.j2");

Crypto crypto = CryptoFactory.getInstance(cxfProps);

Map<String, Object> inProps = new HashMap<String, Object>();
Map<String, Object> outProps = new HashMap<String, Object>();

inProps.put(WSHandlerConstants.ACTION, "Signature");
inProps.put(WSHandlerConstants.SIG_PROP_FILE, "dummy_value"); // Only necessary to avoid NPE

outProps.put(WSHandlerConstants.ACTION, "Signature");
outProps.put(WSHandlerConstants.USER, "client");
outProps.put(WSHandlerConstants.SIG_PROP_FILE, "dummy_value"); // Only necessary to avoid NPE

WSS4JInInterceptor wssIn = new WSS4JInInterceptor(inProps) {
  @Override
  protected Crypto loadCryptoFromPropertiesFile(String propFilename, RequestData reqData)
      throws WSSecurityException {
    return crypto;
  }
};
WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps) {
  @Override
  protected Crypto loadCryptoFromPropertiesFile(String propFilename, RequestData reqData)
      throws WSSecurityException {
    return crypto;
  }
};

【讨论】:

    【解决方案2】:

    支持,请在此处查看我的评论:https://issues.apache.org/jira/browse/WSS-540

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-16
      • 2019-03-04
      • 1970-01-01
      • 2018-12-19
      • 2016-04-03
      • 1970-01-01
      • 1970-01-01
      • 2014-12-30
      相关资源
      最近更新 更多