2014-01-13 56 views
1

我是SOAP API的新手。肥皂API +設置安全標題作爲迴應

我已經實現了一部分,我需要在請求中傳遞WS-Security頭,並根據我們傳遞頭的參數在Soap Server中實現安全性。

現在我的要求是發送相同的肥皂頭響應,我們通過。

是否可以實現?

如果是,然後指導我正確的方向。

回答

2

我已經想出瞭如何發送安全標頭作爲迴應。

讓我們舉個例子吧。我從我的肥皂客戶端撥打NotifyTransportRequest。 通過調用客戶端我傳遞下面使用上述代碼的標題。

//Setting Security Header - Start 
$authHeader = new stdClass(); 
$authHeader->UsernameToken->Username = "user"; 
$authHeader->UsernameToken->Password = "password"; 
$authHeader->Timestamp->Created = "2013-12-31T07:15:41.135Z"; 
$authHeader->Timestamp->Expires = "2013-12-31T07:16:41.135Z"; 
$Headers[] = new SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-  wssecurity-secext-1.0.xsd', 'Security', $authHeader,TRUE); 
// Setting Security Header - End 

// Setting Security Header for Authentication - Start. 
$Client->__setSoapHeaders($Headers); 
// Setting Security Header for Authentication - End. 

由該代碼是通過以下安全報頭中的SOAP請求。

<s:Header> 
    <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
    <u:Timestamp u:Id="_0"> 
     <u:Created>2014-01-16T12:39:31.050Z</u:Created> 
     <u:Expires>2014-01-16T12:40:31.050Z</u:Expires> 
    </u:Timestamp> 
    <o:UsernameToken u:Id="uuid-6065f07d-c852-45c7-8df4-ef9b566b9536-1"> 
     <o:Username>user</o:Username> 
     <o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</o:Password> 
     </o:UsernameToken> 
    </o:Security> 
</s:Header> 

現在,當我從SOAP頭返回,我需要通過下面的代碼返回的東西了。

$headerStart = strtotime(date('Y-m-d H:i:s')) - (1*60); 
    $headerEnd = strtotime(date('Y-m-d H:i:s')) + (1*60); 

    $authHeader = new stdClass(); 
    $authHeader->UsernameToken->Username = "user"; 
    $authHeader->UsernameToken->Password = "password"; 
    $authHeader->Timestamp->Created = gmdate('Y-m-d\TH:i:s.u\Z', $headerStart); 
    $authHeader->Timestamp->Expires = gmdate('Y-m-d\TH:i:s.u\Z', $headerEnd); 
    $Header = new SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', 'Security', $authHeader, false); 

    $GLOBALS['server']->addSoapHeader($Header); 

它會在響應中添加Soap Header。

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:ns2="https://67.231.18.69/~verttest/dispatch/soap/medivan.wsdl"> 
     <SOAP-ENV:Header> 
     <ns1:Security> 
      <UsernameToken> 
       <Username>user</Username> 
       <Password>password</Password> 
      </UsernameToken> 
      <Timestamp> 
       <Created>2014-01-16T12:40:28.000000Z</Created> 
       <Expires>2014-01-16T12:42:28.000000Z</Expires> 
      </Timestamp> 
     </ns1:Security> 
    </SOAP-ENV:Header> 
    <SOAP-ENV:Body> 
      . 
      . 
      . 
    </SOAP-ENV:Body> 
    </SOAP-ENV:Envelope>