|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 /* 00004 * Copyright (C) 2005 Alfresco, Inc. 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 00020 * As a special exception to the terms and conditions of version 2.0 of 00021 * the GPL, you may redistribute this Program in connection with Free/Libre 00022 * and Open Source Software ("FLOSS") applications as described in Alfresco's 00023 * FLOSS exception. You should have recieved a copy of the text describing 00024 * the FLOSS exception, and it is also available here: 00025 * http://www.alfresco.com/legal/licensing" 00026 */ 00027 00028 class AlfrescoWebService extends SoapClient 00029 { 00030 private $securityExtNS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"; 00031 private $wsUtilityNS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"; 00032 private $passwordType = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"; 00033 00034 private $ticket; 00035 00036 public function __construct($wsdl, $options = array('trace' => true, 'exceptions' => true), $ticket = null) 00037 { 00038 // Store the current ticket 00039 $this->ticket = $ticket; 00040 00041 // Call the base class 00042 parent::__construct($wsdl, $options); 00043 } 00044 00045 public function __call($function_name, $arguments=array()) 00046 { 00047 return $this->__soapCall($function_name, $arguments); 00048 } 00049 00050 public function __soapCall($function_name, $arguments=array(), $options=array(), $input_headers=array(), $output_headers=array()) 00051 { 00052 if (isset($this->ticket)) 00053 { 00054 // Automatically add a security header 00055 $input_headers[] = new SoapHeader($this->securityExtNS, "Security", null, 1); 00056 00057 // Set the JSESSION cookie value 00058 // change by moodle 00059 $sessionId = Alfresco_Repository::getSessionId($this->ticket); 00060 if ($sessionId != null) 00061 { 00062 $this->__setCookie("JSESSIONID", $sessionId); 00063 } 00064 } 00065 00066 return parent::__soapCall($function_name, $arguments, $options, $input_headers, $output_headers); 00067 } 00068 00069 public function __doRequest($request, $location, $action, $version) 00070 { 00071 // If this request requires authentication we have to manually construct the 00072 // security headers. 00073 if (isset($this->ticket)) 00074 { 00075 $dom = new DOMDocument("1.0"); 00076 $dom->loadXML($request); 00077 00078 $securityHeader = $dom->getElementsByTagName("Security"); 00079 00080 if ($securityHeader->length != 1) 00081 { 00082 throw new Exception("Expected length: 1, Received: " . $securityHeader->length . ". No Security Header, or more than one element called Security!"); 00083 } 00084 00085 $securityHeader = $securityHeader->item(0); 00086 00087 // Construct Timestamp Header 00088 $timeStamp = $dom->createElementNS($this->wsUtilityNS, "Timestamp"); 00089 $createdDate = date("Y-m-d\TH:i:s\Z", mktime(date("H")+24, date("i"), date("s"), date("m"), date("d"), date("Y"))); 00090 $expiresDate = date("Y-m-d\TH:i:s\Z", mktime(date("H")+25, date("i"), date("s"), date("m"), date("d"), date("Y"))); 00091 $created = new DOMElement("Created", $createdDate, $this->wsUtilityNS); 00092 $expires = new DOMElement("Expires", $expiresDate, $this->wsUtilityNS); 00093 $timeStamp->appendChild($created); 00094 $timeStamp->appendChild($expires); 00095 00096 // Construct UsernameToken Header 00097 $userNameToken = $dom->createElementNS($this->securityExtNS, "UsernameToken"); 00098 $userName = new DOMElement("Username", "username", $this->securityExtNS); 00099 $passWord = $dom->createElementNS($this->securityExtNS, "Password"); 00100 $typeAttr = new DOMAttr("Type", $this->passwordType); 00101 $passWord->appendChild($typeAttr); 00102 $passWord->appendChild($dom->createTextNode($this->ticket)); 00103 $userNameToken->appendChild($userName); 00104 $userNameToken->appendChild($passWord); 00105 00106 // Construct Security Header 00107 $securityHeader->appendChild($timeStamp); 00108 $securityHeader->appendChild($userNameToken); 00109 00110 // Save the XML Request 00111 $request = $dom->saveXML(); 00112 } 00113 00114 return parent::__doRequest($request, $location, $action, $version); 00115 } 00116 } 00117 00118 ?>