gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:49:30 26 4
gpt4 key购买 nike

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

关于java - 是否可以调用属性文件以在 Apache CXF 蓝图中为 Web 服务实例化用户和密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46101907/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com