gpt4 book ai didi

java - Apache CXF + Spring : Simple Certificate Authentication

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:26:47 24 4
gpt4 key购买 nike

我已经开始使用 Spring 学习 Apache CXF。首先,我创建了一个简单的客户端/服务器模型:see here

现在我正在尝试使用简单的证书身份验证。这样我就更改了配置文件(用于服务器和客户端):cxf-servlet.xml:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

<jaxws:endpoint
id="helloWorld"
implementor="service.HelloWorldImpl"
address="/HelloWorld">

<jaxws:features>
<bean class="org.apache.cxf.feature.LoggingFeature"/>
</jaxws:features>
<jaxws:inInterceptors>
<bean class="org.apache.cxf.binding.soap.saaj.SAAJInInterceptor"/>
<ref bean="WSS4JInInterceptor"/>
</jaxws:inInterceptors>
</jaxws:endpoint>

<bean id="WSS4JInInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor">
<constructor-arg>
<map>
<entry key="action" value="Signature"/>
<entry key="passwordCallbackRef">
<ref bean="passwordCallback"/>
</entry>
<entry key="signaturePropFile" value="server_sign.properties"/>
</map>
</constructor-arg>
</bean>
<bean id="passwordCallback" class="service.PasswordCallbackHandler" />

server_sign.properties:

org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
org.apache.ws.security.crypto.merlin.keystore.type=jks
org.apache.ws.security.crypto.merlin.keystore.password=keyStorePassword
org.apache.ws.security.crypto.merlin.file=publicstore.jks

cxf-client-servlet.xml:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schema/jaxws.xsd">

<bean id="client" class="service.HelloWorld" factory-bean="clientFactory" factory-method="create"/>

<bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<property name="serviceClass" value="service.HelloWorld"/>
<property name="address" value="http://localhost:8080/services/HelloWorld"/>
<property name="outInterceptors">
<list>
<bean class="org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor"/>
<ref bean="WSS4JOutInterceptor"/>
</list>
</property>
</bean>

<bean id="WSS4JOutInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">
<property name="properties">
<map>
<entry key="action" value="Signature"/>
<entry key="user" value="ws-client" />
<entry key="passwordCallbackRef">
<ref bean="passwordCallback"/>
</entry>
<entry key="signaturePropFile" value="client_sign.properties"/>
</map>
</property>
</bean>

<bean id="passwordCallback" class="client.PasswordCallbackHandler" />

客户端运行良好。它使用它的 PasswordCallbackHandler。问题是服务器似乎没有使用它的 PasswordCallbackHandler。我已经在 Debug模式下运行服务器,但它不会进入此类。任何人都可以解释一下我做错了什么吗?

提前致谢。

进度:

  1. 如果您尝试提供来自用户的请求,而该证书不在服务器的 keystore 中,则会引发错误(“没有找到用户 ws-client1 的证书用于签名”)

  2. 来自 the resource : "正如您在上面的 jbossws-cxf.xml 文件中看到的,还配置了一个 keystore 密码回调处理程序;而属性文件中有 keystore 的密码,这个回调处理程序用于为每个 key 设置密码(它有以匹配在商店中导入每个 key 时使用的 key )。”

最佳答案

好吧,在对 wss4j 的源代码进行一些研究之后,我意识到,在签名操作的情况下,WSS4JInInterceptor 中没有回调处理程序(仅)。

关于java - Apache CXF + Spring : Simple Certificate Authentication,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9035520/

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