簡體   English   中英

是否可以調用屬性文件在 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>

只需添加到您的藍圖標題:

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

瞧,它正在您的項目之外使用安全的用戶/通行證驗證:D

最重要的是,屬性文件需要這種格式:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM