【问题标题】:Configure SOAP header with Strongloop Loopback SOAP connector使用 Strongloop Loopback SOAP 连接器配置 SOAP 标头
【发布时间】:2016-02-18 22:01:36
【问题描述】:

我正在尝试通过使用 Loopback SOAP 连接器的 SOAP 标头元素连接到实现其 WS 安全性的 SOAP Web 服务。

不幸的是,有关如何配置连接器的 soap 标头选项的文档很少。

如果您能帮助说明应如何构造soap 标头以使Web 服务成功进行身份验证,我们将不胜感激。

var loopback = require('loopback');
var path = require('path');

var app = module.exports = loopback();

app.set('restApiRoot', '/api');

var myHeader =  {
      Security:
      {      
        UsernameToken:{      
          Username: "Staging Integration Store 3",
          Password: "WSAUFbw6"
        } 
      }
    };

var ds = loopback.createDataSource('soap',
  {
    connector: require('../index'),
/*    security: {
    scheme: 'wsse',
    created: null,
    username: "Staging Integration Store 3",
    password: "WSAUFbw6",
    passwordType: 'PasswordText'
    
    }, */
    soapHeaders: [{
    element: myHeader, // The XML element in JSON object format
    prefix: 'wsse', // The XML namespace prefix for the header
    namespace: 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd' // The XML namespace URI for the header
    }],
    remotingEnabled: true,
    // wsdl: 'https://staging.payu.co.za/service/PayUAPI?wsdl' // The url to WSDL
    wsdl: path.join(__dirname, './PayUAPI.wsdl')
  });

// Unfortunately, the methods from the connector are mixed in asynchronously
// This is a hack to wait for the methods to be injected
ds.once('connected', function () {

  // Create the model
  // var WeatherService = ds.createModel('WeatherService', {});
  var RedirectPaymentService = ds.createModel('RedirectPaymentService', {});

  // Refine the methods
  RedirectPaymentService.payments = function (api,safekey,transactiontype,additionalInfo,customer,basket,cb) {

    RedirectPaymentService.setTransaction({Api: api,Safekey: safekey,TransactionType: transactiontype,AdditionalInformation: additionalInfo,Customer: customer,Basket: basket}, function (err, response) {
      console.log('SetTransaction: %j', response);
      var result = (!err && response.return.successful.localCompare("true") == 0) ?        
        response.return.payuReference : response.return.resultMessage;
      cb(err, result);
    });
  };

回复:

SetTransaction: {"statusCode":500,"body":"<soap:Envelope xmlns:soap=\"http://sch
emas.xmlsoap.org/soap/envelope/\"><soap:Body><soap:Fault><faultcode xmlns:ns1=\"
http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xs
d\">ns1:InvalidSecurityToken</faultcode><faultstring>An invalid security token w
as provided (An error happened processing a Username Token)</faultstring></soap:
Fault></soap:Body></soap:Envelope>","headers":{"date":"Tue, 17 Nov 2015 12:15:17
 GMT","server":"Apache/2.4.12 (Win64) OpenSSL/1.0.2a mod_jk/1.2.40","x-distribut
ed-by":"AHC","content-length":"388","connection":"close","content-type":"text/xm
l;charset=UTF-8"},"request":{"uri":{"protocol":"https:","slashes":true,"auth":nu
ll,"host":"staging.payu.co.za","port":443,"hostname":"staging.payu.co.za","hash"
:null,"search":null,"query":null,"pathname":"/service/PayUAPI","path":"/service/
PayUAPI","href":"https://staging.payu.co.za/service/PayUAPI"},"method":"POST","h
eaders":{"User-Agent":"loopback-connector-soap/2.3.0","Accept":"text/html,applic
ation/xhtml+xml,application/xml,text/xml;q=0.9,*/*;q=0.8","Accept-Encoding":"non
e","Accept-Charset":"utf-8","Connection":"close","Host":"staging.payu.co.za","Co
ntent-Length":1128,"Content-Type":"text/xml; charset=utf-8","SOAPAction":"\"\""}
}}
events.js:141

谢谢

【问题讨论】:

    标签: loopbackjs


    【解决方案1】:

    在 datasources.json 中设置安全性是可行的,但您可能不想在那里保存用户名和密码。 有几个选择: 1)您可以使用添加一个可以从 config.json 中提取并嵌入到 datasources.json 中的变量 像这样:“安全”:$ {安全}。 变量安全性在 config.env.json 中定义。

    2) 在模型中,例如,如果你有一个 Product 模型,那么你可以使用类似的东西: Product.datasources.settings.security = {'scheme':'WS', 'username':'abc'....}

    【讨论】:

      【解决方案2】:

      如果提供了相关数据,我设法通过使用连接器的安全选项来解决此问题,该选项创建相关的 SOAP 安全标头。

          security: {
          scheme: 'WS',
          username: "Staging Integration Store 3",
          password: "WSAUFbw6",
          passwordType: 'PasswordText'
          
          },

      XML 转换

      <soap:Header>
      <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
          <wsu:Timestamp wsu:Id="Timestamp-2015-11-20T08:00:46Z">
              <wsu:Created>2015-11-20T08:00:46Z</wsu:Created>
              <wsu:Expires>2015-11-20T08:10:46Z</wsu:Expires>
          </wsu:Timestamp>
          <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="SecurityToken-2015-11-20T08:00:46Z">
              <wsse:Username>Staging Integration Store 3</wsse:Username>
              <wsse:Password>WSAUFbw6</wsse:Password>
              <wsu:Created>2015-11-20T08:00:46Z</wsu:Created>
          </wsse:UsernameToken>
      </wsse:Security>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-06-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多