如何在java,Spring / CXF for Web Service中启用TLS / SSL? [英] How to enable TLS/SSL in java, Spring / CXF for Web Service?

查看:138
本文介绍了如何在java,Spring / CXF for Web Service中启用TLS / SSL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Spring配置中定义了一个简单的WebService:

I have a simple WebService defined in Spring config:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cxf="http://cxf.apache.org/core"
xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:wsa="http://cxf.apache.org/ws/addressing"
xmlns:http="http://cxf.apache.org/transports/http/configuration"
xmlns:wsrm-policy="http://schemas.xmlsoap.org/ws/2005/02/rm/policy"
xmlns:wsrm-mgr="http://cxf.apache.org/ws/rm/manager"
xmlns:httpj="http://cxf.apache.org/transports/http-jetty/configuration"
xsi:schemaLocation="
    http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
    http://schemas.xmlsoap.org/ws/2005/02/rm/policy http://schemas.xmlsoap.org/ws/2005/02/rm/wsrm-policy.xsd
    http://cxf.apache.org/ws/rm/manager http://cxf.apache.org/schemas/configuration/wsrm-manager.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
    http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
    http://cxf.apache.org/transports/http-jetty/configuration http://cxf.apache.org/schemas/configuration/http-jetty.xsd">

<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-*.xml" />

<bean id="logInbound" class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
<bean id="logOutbound" class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>

<bean id="cxf" class="org.apache.cxf.bus.CXFBusImpl">
    <property name="inInterceptors">
        <list>
            <ref bean="logInbound"/>
        </list>
    </property>
    <property name="outInterceptors">
        <list>
            <ref bean="logOutbound"/>
        </list>
    </property>
    <property name="outFaultInterceptors">
        <list>
            <ref bean="logOutbound"/>
        </list>
    </property>
    <property name="inFaultInterceptors">
        <list>
            <ref bean="logInbound"/>
        </list>
    </property>
</bean>

<httpj:engine-factory bus="cxf">
    <httpj:engine port="9001">
        <httpj:threadingParameters minThreads="10" maxThreads="100" />
        <httpj:connector>
            <bean class="org.eclipse.jetty.server.bio.SocketConnector">
                <property name="port" value="9001" />
            </bean>
        </httpj:connector>
        <httpj:handlers>
            <bean class="org.eclipse.jetty.server.handler.DefaultHandler" />
        </httpj:handlers>
        <httpj:sessionSupport>true</httpj:sessionSupport>
    </httpj:engine>
</httpj:engine-factory>

<bean id="serviceFactory" class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean"
    scope="prototype">
    <property name="serviceConfigurations">
        <list>
            <bean class="org.apache.cxf.jaxws.support.JaxWsServiceConfiguration" />
            <bean
                class="org.apache.cxf.aegis.databinding.XFireCompatibilityServiceConfiguration" />
            <bean class="org.apache.cxf.service.factory.DefaultServiceConfiguration" />
        </list>
    </property>
</bean>

<bean id="eventWebService" class="org.myapp.EventWS">
    <property name="timeout" value="${timeoutWS}" />
</bean>

<jaxws:endpoint id="event" implementor="#eventWebService"
    address="${event.endpoint}">
    <jaxws:serviceFactory>
        <ref bean="serviceFactory" />
    </jaxws:serviceFactory>
</jaxws:endpoint>

它就像一个简单的WS at event.endpoint = http\:// localhost \:9001 / event

It works like a simple WS at event.endpoint=http\://localhost\:9001/event

但是现在,我想使用服务器私钥来保护与TLS的连接。
我知道如何使用SSLContext( http://download.oracle.com/javase/6/docs/api/javax/net/ssl/SSLContext.html ),但Spring对我来说是新鲜事。
我想我需要用另一种配置创建一个新的端点?或者使用另一个ServiceFactory?

But now, I want to secure that connection with TLS using server private key. I know how to do this using SSLContext ( http://download.oracle.com/javase/6/docs/api/javax/net/ssl/SSLContext.html ), but Spring is something new to me. I guess i need to create a new Endpoint with another configuration? or use another ServiceFactory ?

问候,
razor

Regards, razor

推荐答案

您必须使用启用SSL的连接器配置引擎出厂设置。也许这会有所帮助:
http://docs.codehaus.org / display / JETTY / How + to + configure + SSL

You must configure the engine factory with an SSL enabled connector. Maybe this helps: http://docs.codehaus.org/display/JETTY/How+to+configure+SSL

这篇关于如何在java,Spring / CXF for Web Service中启用TLS / SSL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆