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