1.server端配置server.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"
xmlns:util="http://www.springframework.org/schema/util"
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
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<bean id="myPasswordCallback" class="cxf.spring.ServerPasswordCallback" />
<jaxws:endpoint id="helloWorld" implementor="cxf.spring.HelloWorldImpl"
address="/HelloWorld">
<jaxws:inInterceptors>
<bean class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor">
<constructor-arg>
<map>
<entry key="action" value="UsernameToken" />
<entry key="passwordType" value="PasswordText" />
<entry key="passwordCallbackRef">
<ref bean="myPasswordCallback" />
</entry>
</map>
</constructor-arg>
</bean>
</jaxws:inInterceptors>
</jaxws:endpoint>
</beans>
ServerPasswordCallback.java文件内容如下:
package cxf.spring;
import java.io.IOException;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
import org.apache.ws.security.WSPasswordCallback;
public class ServerPasswordCallback implements CallbackHandler {
public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
if (pc.getIdentifier().equals("kevin")) {
pc.setPassword("asdfff");
}
}
}
2.client端配置文件内容client.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">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<bean id="myPasswordCallback" class="cxf.spring.ClientPasswordCallback" />
<jaxws:client id="helloWorld" serviceClass="cxf.spring.HelloWorld"
address="http://192.168.1.100:8080/mvn_struts2/webService/HelloWorld">
<jaxws:outInterceptors>
<bean class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">
<constructor-arg>
<map>
<entry key="action" value="UsernameToken" />
<entry key="user" value="kevin" />
<entry key="passwordType" value="PasswordText" />
<entry key="passwordCallbackRef">
<ref bean="myPasswordCallback" />
</entry>
</map>
</constructor-arg>
</bean>
</jaxws:outInterceptors>
</jaxws:client>
</beans>
ClientPasswordCallback.java内容如下:
package cxf.spring;
import java.io.IOException;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
import org.apache.ws.security.WSPasswordCallback;
public class ClientPasswordCallback implements CallbackHandler {
public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
pc.setPassword("asdfff");
}
}
分享到:
相关推荐
cxf配置的详情信息说明,与springMVC的集成,以及相关文档配置
cxf配置swagger2
Spring+cxf配置接口+mybatis配置
CXF配置.doc
java中CXF配置流程
spring-cxf日志记录配置
CXF restful的许多异常java.lang.NoClassDefFoundError: javax/ws/rs/MessageProcessingException.需要javax.ws.rs-api-2.0-m10.jar
Springboot整合cxf测试项目亲测可用,精简版的boot承载cxf框架的资源!
apache-cxf-2.2.10安装包和如何配置到环境变量的说明,放心使用
这文章中实例对应的java类代码和配置文件内容
文中讲解了CXF服务端的库文件,文件配置要求;客户端、服务端的访问示例;CXF的整合;拦截器的使用;等CXF常用的操作。
Springboot整合CXF发布Web service和客户端调用(用户和密码验证)打开及用
ssh+cxf整合发布webservice实例,详细解释配置过程,下载解压即可使用。
配置: trial-cxf-server.xml 其中配置了对传入请求的拦截器用以验证调用者身份 验证程序: WsServerAuthHandler. 这里只需要提供调用者应该使用的正确的口令. 是否和调用者实际传入的口令一致,由cxf完成. web.xml ...
Eclipse3.7下搭建CXF(方式1)
CXF整合spring,同时支持JSON和XML的CXF配置,支持自动转成实体类,其中的hibernate配置可以不用理会。如果还有不明白可以在留言里留下联系方式,大家可以一起讨论
Apache CXF配置REST服务,集成到Spring当中。
spring+struts+hibernate+cxf整合及单个cxf测试样例,详细介绍ssh+cxf配置过程,及执行顺序。
13.为CXF与Spring整合发布WebService添加拦截器进行权限控制
NULL 博文链接:https://a52071453.iteye.com/blog/1675822