ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
SOAP5.php
Go to the documentation of this file.
1 <?php
2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
3 
29 require_once "Auth/Container.php";
33 require_once "PEAR.php";
34 
108 {
109 
110  // {{{ properties
111 
117  var $_requiredOptions = array(
118  'location',
119  'uri',
120  'method',
121  'usernamefield',
122  'passwordfield',
123  'wsdl',
124  );
125 
131  var $_options = array();
132 
138  var $_features = array();
139 
145  var $soapResponse = array();
146 
147  // }}}
148  // {{{ Auth_Container_SOAP5()
149 
156  function Auth_Container_SOAP5($options)
157  {
158  $this->_setDefaults();
159 
160  foreach ($options as $name => $value) {
161  $this->_options[$name] = $value;
162  }
163 
164  if (!empty($this->_options['_features'])) {
165  $this->_features = $this->_options['_features'];
166  unset($this->_options['_features']);
167  }
168  }
169 
170  // }}}
171  // {{{ fetchData()
172 
183  function fetchData($username, $password)
184  {
185  $this->log('Auth_Container_SOAP5::fetchData() called.', AUTH_LOG_DEBUG);
186  $result = $this->_validateOptions();
187  if (PEAR::isError($result))
188  return $result;
189 
190  // create a SOAP client
191  $soapClient = new SoapClient($this->_options["wsdl"], $this->_options);
192 
193  $params = array();
194  // first, assign the optional features
195  foreach ($this->_features as $fieldName => $fieldValue) {
196  $params[$fieldName] = $fieldValue;
197  }
198  // assign username and password ...
199  $params[$this->_options['usernamefield']] = $username;
200  $params[$this->_options['passwordfield']] = $password;
201 
202  try {
203  $this->soapResponse = $soapClient->__soapCall($this->_options['method'], $params);
204 
205  if ($this->_options['matchpasswords']) {
206  // check if passwords match
207  if ($password == $this->soapResponse[$this->_options['passwordfield']]) {
208  return true;
209  } else {
210  return false;
211  }
212  } else {
213  return true;
214  }
215  } catch (SoapFault $e) {
216  return PEAR::raiseError("Error retrieving authentication data. Received SOAP Fault: ".$e->faultstring, $e->faultcode);
217  }
218  }
219 
220  // }}}
221  // {{{ _validateOptions()
222 
229  function _validateOptions()
230  {
231  if ( ( is_null($this->_options['wsdl'])
232  && is_null($this->_options['location'])
233  && is_null($this->_options['uri']))
234  || ( is_null($this->_options['wsdl'])
235  && ( is_null($this->_options['location'])
236  || is_null($this->_options['uri'])))) {
237  return PEAR::raiseError('Either a WSDL file or a location/uri pair must be specified.');
238  }
239  if (is_null($this->_options['method'])) {
240  return PEAR::raiseError('A method to call on the soap service must be specified.');
241  }
242  return true;
243  }
244 
245  // }}}
246  // {{{ _setDefaults()
247 
254  function _setDefaults()
255  {
256  $this->_options['wsdl'] = null;
257  $this->_options['location'] = null;
258  $this->_options['uri'] = null;
259  $this->_options['method'] = null;
260  $this->_options['usernamefield'] = 'username';
261  $this->_options['passwordfield'] = 'password';
262  $this->_options['matchpasswords'] = true;
263  }
264 
265  // }}}
266 
267 }
268 ?>