【问题标题】:Is it possible call a properties file to instance a user and password in Apache CXF Blueprint for a Web Service?是否可以调用属性文件以在 Apache CXF 蓝图中为 Web 服务实例化用户和密码?
【发布时间】:2018-02-16 12:28:54
【问题描述】:

我对 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>

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

【问题讨论】:

  • 您使用的是 blueprint.xml 还是 spring.xml 文件?
  • 我正在使用 Blueprint.xml 上下文

标签: java maven web-services apache-karaf fuseesb


【解决方案1】:

好的,我用 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

【讨论】:

  • 我的建议差不多。
猜你喜欢
  • 2011-04-13
  • 2012-07-24
  • 2011-06-15
  • 1970-01-01
  • 2011-04-17
  • 1970-01-01
  • 2012-06-08
  • 1970-01-01
  • 2015-05-06
相关资源
最近更新 更多