【问题标题】:How to read username and password from a properties file for WS-Security in Mule如何从 Mule 中 WS-Security 的属性文件中读取用户名和密码
【发布时间】:2014-09-18 15:59:51
【问题描述】:

我已经在 CXF 网络服务中实现了 WS-security,下面是 Mule 流程:-

<context:property-placeholder location="classpath:conf/DBConnectionProp.properties"/>
    <!-- Authentication security-->
     <mule-ss:security-manager>
            <mule-ss:delegate-security-provider name="memory-provider" delegate-ref="authenticationManager" />
        </mule-ss:security-manager>
        <spring:beans>
            <ss:authentication-manager alias="authenticationManager">
                <ss:authentication-provider>
                    <ss:user-service id="userService" >
                        <ss:user name="${username}" password="${password}" authorities="ROLE_ADMIN" />
                    </ss:user-service>
                </ss:authentication-provider>
            </ss:authentication-manager>
        </spring:beans>

    <cxf:ws-security name="inboundSecurityConfig">
    <cxf:mule-security-manager />
    <cxf:ws-config>
    <cxf:property key="action" value="UsernameToken" />
    </cxf:ws-config>
    </cxf:ws-security>

    <!-- Authentication security ends-->

    <flow name="securedSoapService">
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8090" path="designation" doc:name="HTTP">
    <cxf:jaxws-service serviceClass="com.getdesignation.test.services.schema.maindata.v1.GetDesignation">
    <cxf:ws-security ref="inboundSecurityConfig"/>
    </cxf:jaxws-service>
    </http:inbound-endpoint>
    <component class="com.getdesignation.vertu.services.schema.maindata.v1.Impl.GetDesignationImpl" />
    </flow>

现在的问题是,它没有从属性文件中读取用户名和密码的值.. 如果我尝试从属性文件 &lt;ss:user name="${username}" password="${password}" authorities="ROLE_ADMIN" /&gt; 中读取值,那么它会将整个值作为字符串读取,并导致以下异常为 invalid 用户名和密码:-

WARN  2014-09-18 21:23:41,426 [[SOAPSecurity2].connector.http.mule.default.receiver.02] org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor: 
org.apache.ws.security.WSSecurityException: The security token could not be authenticated or authorized
    at org.mule.module.cxf.support.MuleSecurityManagerValidator.validate(MuleSecurityManagerValidator.java:57)
    at org.apache.ws.security.processor.UsernameTokenProcessor.handleUsernameToken(UsernameTokenProcessor.java:153)
    at org.apache.ws.security.processor.UsernameTokenProcessor.handleToken(UsernameTokenProcessor.java:66)
    at org.apache.ws.security.WSSecurityEngine.processSecurityHeader(WSSecurityEngine.java:396)
    at org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor.handleMessage(WSS4JInInterceptor.java:281)
    at org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor.handleMessage(WSS4JInInterceptor.java:100)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:122)

但是如果删除 ${username} 和 ${password} 并直接提供用户名和密码,那么它运行正常.. 我不知道如何让它从属性文件中读取用户名和密码.. 请help .. 有没有办法实现从属性文件读取 ws-security ???

【问题讨论】:

  • “将整个值读取为字符串”是什么意思? usernamepassword 属性是否在 conf/DBConnectionProp.properties 中定义?我想不是因为它的名字,这个文件似乎包含用于数据库访问的属性,而不是用于保护端点的属性。
  • 是的大卫我已经定义了用户名=用户名密码=密码但是当我使用 ${username} 或 ${password} 时它仍然没有读取它
  • 嗯,好像没有加载属性文件。你能把ignore-resource-not-found="false" 加到context:property-placeholder 看看会发生什么吗?
  • 但是大卫我从属性文件中获取其他值..例如,如果我定义 myValue=abcd ..那么我可以使用 ${myValue} 在记录器中获取它
  • 那可能是ss:user 中的错误?

标签: web-services spring-security mule mule-studio ws-security


【解决方案1】:

尝试使用:

username1=username
password1=password

和:

<ss:user name="${username1}" password="${password1}" authorities="ROLE_ADMIN" />

因为与名称具有相同值的属性可能存在问题。

【讨论】:

    【解决方案2】:

    感谢大卫... 这是一个奇怪的问题,正如大卫所说的工作解决方案是:

    <ss:user name="${username1}" password="${password1}" authorities="ROLE_ADMIN" />
    

    我无法将密钥用作 用户名密码

    更新我发现这个错误是由于属性“userName”被Windows环境变量“USERNAME”覆盖。
    参考:-https://support.mulesoft.com/s/article/ka434000000TOoDAAW/Bad-credentials-error-when-configuring-the-Spring-Security-Manager-with-properties

    【讨论】:

      猜你喜欢
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-22
      • 1970-01-01
      • 2018-01-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多