是否可以调用属性文件以在 Apache CXF 蓝图中为 Web 服务实例化用户和密码?

Is it possible call a properties file to instance a user and password in Apache CXF Blueprint for a Web Service?

我对 Fuse 和 WebServices 比较陌生。
我用 BasicAuthAuthorizationInterceptor 做了一个 SOAP WebService,这是实际的上下文并且它正在工作:

<cxf:cxfEndpoint address="/SampleEp" id="insertSomethingToDB" serviceClass="com.example.sample_ep.SampleEp" wsdlURL="wsdl/SampleEP.wsdl">
    <cxf:inInterceptors>
        <ref component-id="securityInterceptor"/>
    </cxf:inInterceptors>
</cxf:cxfEndpoint>

<bean
    class="com.example.middleware.BasicAuthAuthorizationInterceptor" id="securityInterceptor">
    <property name="users">
        <map>
            <entry key="user" value="password"/>
        </map>
    </property>
</bean>

所以,为了增加安全性,我会尝试将用户放在项目外的属性文件中,这是我的想法:

<cxf:cxfEndpoint address="/SampleEp" id="insertSomethingToDB" serviceClass="com.example.sample_ep.SampleEp" wsdlURL="wsdl/SampleEP.wsdl">
    <cxf:inInterceptors>
        <ref component-id="securityInterceptor"/>
    </cxf:inInterceptors>
</cxf:cxfEndpoint>

<bean
    class="com.example.middleware.BasicAuthAuthorizationInterceptor" id="securityInterceptor">
    <property name="users">
        <map>
            <entry key="${cxf.user}" value="${cxf.password}"/>
        </map>
    </property>
</bean>

<bean> add some code to add a *.properties file outside the project </bean>

这可能吗? 还是我真的不擅长这个?

好的,我用 Jasypt、JAAS 尝试了一些东西并得到了解决方案:

<ext:property-placeholder>
    <ext:location>file:/this/is/your/path/to/your/propertie/file/cxf.properties
    </ext:location>
</ext:property-placeholder>

<cxf:cxfEndpoint address="/SampleEp" id="insertSomethingToDB"
    serviceClass="com.example.sample_ep.SampleEp" wsdlURL="wsdl/SampleEP.wsdl">
    <cxf:inInterceptors>
        <ref component-id="securityInterceptor" />
    </cxf:inInterceptors>
</cxf:cxfEndpoint>

<bean class="com.example.middleware.BasicAuthAuthorizationInterceptor"
    id="securityInterceptor">
    <property name="users">
        <map>
            <entry key="${cxf.user}" value="${cxf.password}" />
        </map>
    </property>
</bean>

只需添加到您的蓝图header:

xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"

瞧,它正在您的项目外使用安全 user/pass 验证 :D

最重要的是,属性文件需要这种格式:

#cxf.properties
cxf.user=administrator
cxf.password=password