gpt4 book ai didi

web-services - 无法在 Web 服务中使用 CXF 启用 WS-SecurityPolice

转载 作者:行者123 更新时间:2023-11-28 22:25:12 26 4
gpt4 key购买 nike


这是我使用 CXF 和 Web 服务的第一个项目,使用 Tomcat 作为 servlet 容器,也是我在 StackOverflow 中的第一个问题,所以请耐心等待我....;-)
我正在使用:

  • Tomcat 9(独立并与 Eclipse 集成)。
  • CXF (3.2.0)
  • JDK 1.8
  • Windows 7

**问题:**WS-SecurityPolicy 未启用/未在服务器端工作。

WS-SecurityPolicy 在 Web 服务的 wsdl 文件中实现,该策略似乎工作正常,因为在客户端,SOAP 输出消息正文已签名。
我卡住的问题是在服务器端,响应中没有应用任何策略。
我遇到的第一个问题是 SOAP header “必须理解=1”,服务器无法识别安全 header 并引发异常。
我怀疑 Web 服务没有应用该策略,然后为了避免 header 异常,我放置了一个不执行任何操作的处理程序。
现在服务器响应 SOAP 消息,但以清晰的形式(未签名,没有 BinarySecurityTolen 和其他东西),我怀疑是真的,策略不起作用。
我认为问题是 CXF 文件配置错误...
Web服务的cxf bean配置在Tomcat启动时加载。


信息:创建服务{ http://ole/wsTransaccion }来自 WSDL 的 WsTransaccionService:wsdl/wsTransaccion.wsdl
....
....
信息:从 ServletContext 资源加载 XML bean 定义 [/WEB-INF/cxf-wsTransaccion.xml]

cxf-wsTransaccion.xml 文件包含:

http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd ">

 <bean id="myPasswordCallback"
class="implementacion.ServerKeystorePasswordCallback" />

<jaxws:endpoint xmlns:tns="http://ole/wsTransaccion" id="wsTransaccion"
implementor="implementacion.WsTransaccionImpl"
wsdlLocation="wsdl/wsTransaccion,wsdl" endpointName="tns:WsTransaccionPort"
serviceName="tns:WsTransaccionService" address="/WsTransaccionPort">
<jaxws:features>
<bean class="org.apache.cxf.feature.LoggingFeature" />
</jaxws:features>

<jaxws:properties>
<entry key="security.callback-handler">
<ref bean="myPasswordCallback"/>
</entry>
<entry key="security.encryption.properties" value="keystore.properties"/>
<entry key="security.signature.properties" value="keystore.properties"/>
<entry key="ws-security.encryption.username" value="useReqSigCert"/>
</jaxws:properties>

</jaxws:endpoint>


我认为问题可能出在文件 keystore.properties 的位置,尽管如果不存在则不会抛出异常(如 java.io.FileNotFoundException)..
我看到的所有示例都是 Maven 的项目,但这不是 MAVEN 项目,所以我没有放置属性文件和 keystore 的文件夹“resources”。
我不知道 keystore.properties 的正确位置,我认为必须在类路径中,然后我将它与 keystore 一起放在一个名为 resources 的包中。

keystore.properties的内容:

>org.apache.wss4j.crypto.provider=org.apache.ws.security.components.crypto.Merlin
>org.apache.wss4j.crypto.merlin.keystore.file=server.p12
>org.apache.wss4j.crypto.merlin.keystore.type=PKCS12
>org.apache.wss4j.crypto.merlin.keystore.alias=server
>org.apache.wss4j.crypto.merlin.keystore.password=xxxxxx<br/>

另一种可能性是 org.apache.wss4j.crypto.merlin.keystore.file=server.p12 也不在正确的位置,尽管与 keystore.properties 在同一个地方

如有任何建议,我们将不胜感激。非常感谢!!!

最佳答案

问题出在这里:

Tomcat 控制台:
“警告:资源类路径:./resources/policyBinding.xml 未在类加载器中找到。”

尽管 policyBinding.xml 在类路径中,但由于接口(interface)中的以下注释而未正确加载网络服务:

@Policy(uri = "./resources policyBinding.xml",placement=Policy.Placement.DEFAULT)

感谢阿尔弗雷多 (WS-Security Policy node not being generated in Apache CXF with Spring and custom context file) 我找到了正确的语法:
@Policy(uri = "classpath:policyBinding.xml",placement=Policy.Placement.DEFAULT)

关于web-services - 无法在 Web 服务中使用 CXF 启用 WS-SecurityPolice,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48349005/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com