我需要使用一个具有ws-security用户名令牌的soap服务。下面是我的代码和错误。
<?xml version="1.0" encoding="UTF-8"?>
<api context="/Service" name="ServiceA-Service" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<header name="To" scope="default" value="https://Service/Service.svc"/>
<property name="Username" scope="axis2" type="STRING" value="MYUSER"/>
<property name="Password" scope="axis2" type="STRING" value="MYPASSWORD"/>
<send>
<endpoint>
<wsdl port="CustomBinding_Service" service="Service" uri="workingSFD.xml">
<enableSec policy="conf:myresources/NewResource.xml"/>
</wsdl>
</endpoint>
</send>
</inSequence>
<outSequence>
<respond/>
</outSequence>
<faultSequence/>
</resource>
</api>
但是在从邮递员发送以下请求时:
<soapenv:Envelope>
<soapenv:Header/>
<soapenv:Body>
<arg1>asdsa</arg1>
</soapenv:Body>
</soapenv:Envelope>
它向我显示了以下错误:
Missing wsse:Security header in request {org.apache.axis2.engine.AxisEngine}
我正在使用WSO2用户名令牌的默认策略。
答案 0 :(得分:0)
您必须将用户名和密码设置为客户端选项,而不是axis2属性。您可以参考此以获得详细说明-http://xacmlinfo.org/2014/03/25/how-to-esb-invoking-username-token-secured-backend-service/
以下是类介体的简化版本,用于设置用户名和密码。
public class UTTokenBuilder extends AbstractMediator{
@Override
public boolean mediate(MessageContext messageContext) {
try {
org.apache.axis2.context.MessageContext context = ((Axis2MessageContext) messageContext)
.getAxis2MessageContext();
context.getOptions().setUserName("admin");
context.getOptions().setPassword("admin");
return true;
} catch (SynapseException e) {
throw e;
} catch (Exception e) {
throw new SynapseException("Error while building UT Token");
}
}
}