java - Apache WSS4J 无法初始化

标签 java apache spring-boot security wss4j

我正在尝试让 Apache WSS4J 库来验证 Spring Boot Web 服务中的 BinarySecurityToken。我们可以正常启动服务,但是当我们发送 SOAP 请求时,我们收到以下错误:

No message with ID "invalidSAMLsecurity" found in resource bundle "org/apache/xml/security/resource/xmlsecurity"; nested exception is org.apache.wss4j.common.ext.WSSecurityException: No message with ID "invalidSAMLsecurity" found in resource bundle "org/apache/xml/security/resource/xmlsecurity"

现在,根据我的理解,当您尚未调用 WSSec.init() 方法时,就会发生这种情况。但是,Apache WSS4J 中唯一的 WSSec 类位于 org.apache.wss4j.stax 包中,并且使用 Maven 下载 WSS4J 2.2.3 似乎并没有给出您可以访问 stax 包。

我相当确定我只是在错误的地方查找,但当前的 Apache WSS4J API 适用于 2.3.0-SNAPSHOT,所以我什至不确定我的版本是否适用我正在使用可以访问这些包的权限,但我似乎找不到 2.2.3 版本的 API。

我确信这只是找到正确的初始化的问题,我只是不确定这些初始化将在哪里配置。

最佳答案

为了能够使用 header 中存在的 binarySecurityToken 验证已签名的 xml - 您需要确保使用

对 xml 进行签名

"WSHandlerConstants.SIG_KEY_ID" = "DirectReference"

 List<WSSecurityEngineResult> res = engine.processSecurityHeader(signedDoc, null, null, crypto); 

signedDoc - 作为文档的 SOAP 信封

使用此方法来验证签名。另外,设置一个 Crypto 实例,如下所示。

Crypto crypto = CryptoFactory.getInstance("validator.properties");

尝试以下 Maven 依赖项(这是我拥有的一个工作示例)

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <version>2.1.5.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.apache.wss4j</groupId>
        <type>pom</type>
        <artifactId>wss4j</artifactId>
        <version>2.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.wss4j</groupId>
        <artifactId>wss4j-ws-security-dom</artifactId>
        <version>2.0.0</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.4</version>
        <type>jar</type>
    </dependency>

    <dependency>
        <groupId>org.apache.axis</groupId>
        <artifactId>axis</artifactId>
        <version>1.4</version>
    </dependency>

    <dependency>
        <groupId>org.apache.ws.security</groupId>
        <artifactId>wss4j</artifactId>
        <version>1.6.19</version>
    </dependency>

    <dependency>
        <groupId>org.apache.wss4j</groupId>
        <artifactId>wss4j-ws-security-common</artifactId>
        <version>2.0.2</version>
    </dependency>

关于java - Apache WSS4J 无法初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56793663/

相关文章:

elasticsearch - 通过应用弹性查询从嵌套字段中获取数据

spring - 是否可以在 spring boot 中使用 @Transactional 和 kotlin 协程?

java - JAXB 解码不起作用

java - 从 cmd 运行 JavaFX

java - 仅为特定用户向标签添加属性

java - 自定义@Annotation以在运行时报告 boolean 值

python - Apache 套接字没有关闭?

apache - 我已成功使用 mod_jk 将 apache 连接到 tomcat,但未执行 jsp,而是将它们显示为纯文本文件

java - 我无法访问 Apache Tomcat 管理器?

java - AuthorizationServerConfigurerAdapter 与 WebSecurityConfigurerAdapter 之间的区别