PageRenderTime 62ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/alfresco/Service/WebService/AlfrescoWebService.php

https://bitbucket.org/kudutest/moodlegit
PHP | 111 lines | 64 code | 19 blank | 28 comment | 6 complexity | 135e467b02d5369e70e20bf293eb5237 MD5 | raw file
  1. <?php
  2. /*
  3. * Copyright (C) 2005-2010 Alfresco Software Limited.
  4. *
  5. * This file is part of Alfresco
  6. *
  7. * Alfresco is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Alfresco is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License
  18. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. class AlfrescoWebService extends SoapClient
  21. {
  22. private $securityExtNS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
  23. private $wsUtilityNS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
  24. private $passwordType = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText";
  25. private $ticket;
  26. public function __construct($wsdl, $options = array('trace' => true, 'exceptions' => true), $ticket = null)
  27. {
  28. // Store the current ticket
  29. $this->ticket = $ticket;
  30. // Call the base class
  31. parent::__construct($wsdl, $options);
  32. }
  33. public function __call($function_name, $arguments=array())
  34. {
  35. return $this->__soapCall($function_name, $arguments);
  36. }
  37. public function __soapCall($function_name, $arguments=array(), $options=array(), $input_headers=array(), &$output_headers=array())
  38. {
  39. if (isset($this->ticket))
  40. {
  41. // Automatically add a security header
  42. $input_headers[] = new SoapHeader($this->securityExtNS, "Security", null, 1);
  43. // Set the JSESSION cookie value
  44. $sessionId = Alfresco_Repository::getSessionId($this->ticket);
  45. if ($sessionId != null)
  46. {
  47. $this->__setCookie("JSESSIONID", $sessionId);
  48. }
  49. }
  50. return parent::__soapCall($function_name, $arguments, $options, $input_headers, $output_headers);
  51. }
  52. public function __doRequest($request, $location, $action, $version, $one_way = 0)
  53. {
  54. // If this request requires authentication we have to manually construct the
  55. // security headers.
  56. if (isset($this->ticket))
  57. {
  58. $dom = new DOMDocument("1.0");
  59. $dom->loadXML($request);
  60. $securityHeader = $dom->getElementsByTagName("Security");
  61. if ($securityHeader->length != 1)
  62. {
  63. throw new Exception("Expected length: 1, Received: " . $securityHeader->length . ". No Security Header, or more than one element called Security!");
  64. }
  65. $securityHeader = $securityHeader->item(0);
  66. // Construct Timestamp Header
  67. $timeStamp = $dom->createElementNS($this->wsUtilityNS, "Timestamp");
  68. $createdDate = date("Y-m-d\TH:i:s\Z", mktime(date("H")+24, date("i"), date("s"), date("m"), date("d"), date("Y")));
  69. $expiresDate = date("Y-m-d\TH:i:s\Z", mktime(date("H")+25, date("i"), date("s"), date("m"), date("d"), date("Y")));
  70. $created = new DOMElement("Created", $createdDate, $this->wsUtilityNS);
  71. $expires = new DOMElement("Expires", $expiresDate, $this->wsUtilityNS);
  72. $timeStamp->appendChild($created);
  73. $timeStamp->appendChild($expires);
  74. // Construct UsernameToken Header
  75. $userNameToken = $dom->createElementNS($this->securityExtNS, "UsernameToken");
  76. $userName = new DOMElement("Username", "username", $this->securityExtNS);
  77. $passWord = $dom->createElementNS($this->securityExtNS, "Password");
  78. $typeAttr = new DOMAttr("Type", $this->passwordType);
  79. $passWord->appendChild($typeAttr);
  80. $passWord->appendChild($dom->createTextNode($this->ticket));
  81. $userNameToken->appendChild($userName);
  82. $userNameToken->appendChild($passWord);
  83. // Construct Security Header
  84. $securityHeader->appendChild($timeStamp);
  85. $securityHeader->appendChild($userNameToken);
  86. // Save the XML Request
  87. $request = $dom->saveXML();
  88. }
  89. return parent::__doRequest($request, $location, $action, $version);
  90. }
  91. }
  92. ?>