`
wangwengcn
  • 浏览: 175145 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

4.CXF安全访问之单向SSL或者双向SSL(三)

    博客分类:
  • CXF
阅读更多

还是使用上一篇文章中生成的四个证书文件,以Tomcat 为运行环境来部署支持SSL的CXF应用。

首先在Tomcat的conf目录中找到server.xml文件,需要在该文件中加上SSL配置,如下

 

<Connector SSLEnabled="true" 
					acceptCount="100" 
					algorithm="SunX509" 
					disableUploadTimeout="true" 
					enableLookups="false" 
					maxHttpHeaderSize="8192" 
					maxSpareThreads="75" 
					maxThreads="150" 
					minSpareThreads="25" 
					port="8443" 
					scheme="https" 
					secure="true" 
					sslProtocol="TLS"
					clientAuth="true" 
					keystoreFile="conf/server-keystore.jks" 
					keystorePass="myPassword" 
					truststoreFile="conf/server-truststore.jks" 
					truststorePass="myPassword" 
					truststoreType="jks"/>

 其中,keystoreFile是服务器私钥的jks文件,keystorePass是私钥jks的密码,如果部署的是单向认证的SSL,那么只配置这两项就足够了。

如果要部署双向SSL认证,那么请继续将truststoreFile,truststorePass,truststoreType配置上,truststoreFile是储存客户端公钥证书的文件。

并将上面涉及到的两个jks文件放入到conf目录。此时服务端配置就好了。

 

接着是客户端配置,请看spring的配置文件,如下:

 

<?xml version="1.0" encoding="UTF-8"?>
<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:sec="http://cxf.apache.org/configuration/security" xmlns:http="http://cxf.apache.org/transports/http/configuration"
	xsi:schemaLocation="
		http://cxf.apache.org/configuration/security
		http://cxf.apache.org/schemas/configuration/security.xsd
		http://cxf.apache.org/transports/http/configuration
		http://cxf.apache.org/schemas/configuration/http-conf.xsd
		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:client id="helloClient"
		serviceClass="com.demo.cxf.helloword.HelloWord"
		address="https://localhost:8443/web_service/services/HelloWorld">
	</jaxws:client>

	<http:conduit name="*.http-conduit">
		<http:tlsClientParameters disableCNCheck="true">
			<!-- 服务端公钥 -->
			<sec:trustManagers>
				<sec:keyStore type="JKS" password="myPassword"
					file="client-truststore.jks" />
			</sec:trustManagers>
			<!-- 客户端私钥 -->
            <sec:keyManagers keyPassword="myPassword">
                <sec:keyStore type="JKS" password="myPassword"
                    file="client-keystore.jks" />
            </sec:keyManagers>
			<sec:cipherSuitesFilter>
				<!-- these filters ensure that a ciphersuite with export-suitable or 
					null encryption is used, but exclude anonymous Diffie-Hellman key change 
					as this is vulnerable to man-in-the-middle attacks -->
				<sec:include>.*_EXPORT_.*</sec:include>
				<sec:include>.*_EXPORT1024_.*</sec:include>
				<sec:include>.*_WITH_DES_.*</sec:include>
				<sec:include>.*_WITH_NULL_.*</sec:include>
				<sec:exclude>.*_DH_anon_.*</sec:exclude>
			</sec:cipherSuitesFilter>
		</http:tlsClientParameters>
	</http:conduit>
</beans>

 同上面,如果只要单向认证,请删除sec:keyManagers客户端私钥配置即可。

 

client端调用代码同Hello World示例代码:

 

ApplicationContext context = new ClassPathXmlApplicationContext("cxf/cxf-client-ssl.xml");
		HelloWord helloWord = (HelloWord)context.getBean("helloClient");
		System.out.println(helloWord.sayHello("Bruce"));

 

附上完成代码。

 

分享到:
评论
2 楼 xujialei2007 2013-12-13  
  <!--APR library loader. Documentation at /docs/apr.html
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />-->
1 楼 sthyuhao 2013-07-11  
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
我这边握手失败了,请问怎样才能解决问题!

相关推荐

    2.CXF安全访问之Http Basic Auth(一)

    同时,`org.apache.cxf.interceptor.security.BasicAuthInterceptor`拦截器处理了实际的身份验证过程,它会检查收到的请求是否包含正确的认证信息。 工具方面,CXF提供了多种工具帮助开发者管理和调试服务,如CXF的...

    3.CXF安全访问之SIGN_ENC(二)

    【标题】:“3.CXF安全访问之SIGN_ENC(二)” 在本文中,我们将深入探讨Apache CXF框架中实现的安全访问机制,特别是SIG_N_ENC,这是一个结合了签名(Signature)和加密(Encryption)的安全策略。CXF是一个开源的...

    org.apache.cxf.spring.remoting.Jsr181HandlerMapping.jar

    org.apache.cxf.spring.remoting.Jsr181HandlerMapping.jar

    CXF实现SSL安全验证

    ### CXF实现SSL安全验证 在现代网络应用中,安全通信是至关重要的。Apache CXF 是一个开源项目,提供了一套强大的工具和服务框架,用于构建和开发基于标准的服务(如 Web Services)。本文将详细介绍如何使用 CXF ...

    apache-cxf-2.4.6.zip

    4. **丰富的协议栈**:CXF支持各种WS-*协议,如WS-Security、WS-Addressing、WS-Policy等,提供了安全、可靠的消息传递能力。 5. **多种绑定和传输机制**:除了HTTP和HTTPS,CXF还支持JMS、XMPP等传输协议,可以...

    cxf的jar包.rar

    利用Apache CXF开发webservice接口需要用到的jar集合 cxf-core-3.0.15.jar cxf-rt-bindings-soap-3.0.15.jar cxf-rt-bindings-xml-3.0.15.jar cxf-rt-databinding-jaxb-3.0.15.jar cxf-rt-frontend-jaxws-3.0.15.jar...

    TipTec.Developing.Web.Services.with.Apache.CXF.and.Axis2.Jan.2010.rar

    标题中的“TipTec.Developing.Web.Services.with.Apache.CXF.and.Axis2.Jan.2010”表明这是一份关于使用Apache CXF和Axis2开发Web服务的教程资料,发布于2010年1月。Apache CXF和Axis2是两个流行的Java框架,用于...

    CXF之二(上传及下载附件)

    CXF提供了`org.apache.cxf.jaxrs.ext.multipart.MultipartProvider`类,它可以解析Multipart请求并将文件内容转化为可操作的对象。 3. **处理文件上传**: 在服务端的实现类中,我们可以读取`InputStream`或`Part`...

    PacktPub.Apache.CXF.Web.Service.Development.Dec.2009.rar

    这个压缩包文件"PacktPub.Apache.CXF.Web.Service.Development.Dec.2009.rar"包含了关于使用Apache CXF进行Web服务开发的详细教程,可能出自Packt Publishing在2009年12月出版的一本书。该资源很可能提供了深入的...

    cxf框架包 apache-cxf-3.4.3.tar.gz

    可以通过Maven或Gradle依赖管理工具引入,或者将CXF的JAR文件添加到项目的类路径中。 **7. 使用示例** - 创建服务接口和实现 - 使用CXF工具生成客户端代码 - 配置服务发布和消费 - 调试和测试服务 **8. 扩展与集成...

    02.CXF功能概述_CXF发展历史和使用CXF开发WebService服务器端

    【标题】"02.CXF功能概述_CXF发展历史和使用CXF开发WebService服务器端"主要探讨了Apache CXF框架在Web服务领域的应用及其发展历程,同时也涵盖了如何利用CXF来构建一个高效的WebService服务器端。 Apache CXF是一...

    apache cxf_jar包

    4. **cxf-common-utilities-2.5.10.jar**: CXF通用工具包,提供了在CXF框架中广泛使用的各种实用程序类,如XML解析、类型转换等。 5. **cxf-rt-transports-http-2.7.12.jar**: HTTP传输模块,负责处理HTTP/S协议的...

    apache-cxf-2.7.5所有jar都在

    在实际使用中,开发者可能还需要配置CXF的相关XML配置文件(如cxf.xml或cxf-servlet.xml),以定制服务行为和设置。此外,通过Maven或Gradle等构建工具,可以更方便地管理和引入CXF的依赖。 总之,Apache CXF 2.7.5...

    08.CXF拦截器的理论以及如何为CXF的客户端和服务器端添加拦截器

    - `org.apache.cxf.interceptor.ClientInterceptor` 和 `org.apache.cxf.interceptor.ServerInterceptor`:分别用于客户端和服务端。 - `org.apache.cxf.phase.PhaseInterceptor`:通用接口,适用于任何拦截器。 ...

    14.CXF与Spring整合的第二种方式_让JavaEE应用依赖第三方WebService

    例如,我们可以通过`&lt;bean id="cxf" class="org.apache.cxf.frontend.ServerFactoryBean"&gt;`来创建一个Bus实例,并设置相关的属性,如服务地址、端口等。 2. **定义Web服务接口和实现**:在Java中,我们可以定义一个...

    cxf最少依赖jar包

    - 对于需要安全性的应用,如SSL/TLS支持,可能需要`geronimo-ssl-builder.jar`,`neethi.jar`(用于WSDL政策)等安全相关的JAR包。 8. **国际化与本地化**: - `cxf-rt-i18n.jar`包含了CXF的国际化资源,如果项目不...

Global site tag (gtag.js) - Google Analytics