Auth
[ class tree: Auth ] [ index: Auth ] [ all elements ]

Source for file SOAP.php

Documentation is available at SOAP.php

  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2002 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Bruno Pedro <bpedro@co.sapo.pt>                             |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: SOAP.php,v 1.6 2003/09/08 11:24:05 yavo Exp $
  20. //
  21.  
  22. require_once "Auth/Container.php";
  23. require_once "PEAR.php";
  24. require_once 'SOAP/Client.php';
  25.  
  26. /**
  27.  * Storage driver for fetching login data from SOAP
  28.  *
  29.  * This class takes one parameter (options), where
  30.  * you specify the following fields: endpoint, namespace,
  31.  * method, encoding, usernamefield and passwordfield.
  32.  *
  33.  * You can use specify features of your SOAP service
  34.  * by providing its parameters in an associative manner by
  35.  * using the '_features' array through the options parameter.
  36.  *
  37.  * The 'matchpassword' option should be set to false if your
  38.  * webservice doesn't return (username,password) pairs, but
  39.  * instead returns error when the login is invalid.
  40.  *
  41.  * Example usage:
  42.  *
  43.  * <?php
  44.  *
  45.  * ...
  46.  *
  47.  * $options = array (
  48.  *             'endpoint' => 'http://your.soap.service/endpoint',
  49.  *             'namespace' => 'urn:/Your/Namespace',
  50.  *             'method' => 'get',
  51.  *             'encoding' => 'UTF-8',
  52.  *             'usernamefield' => 'login',
  53.  *             'passwordfield' => 'password',
  54.  *             'matchpasswords' => false,
  55.  *             '_features' => array (
  56.  *                             'example_feature' => 'example_value',
  57.  *                             'another_example'  => ''
  58.  *                             )
  59.  *             );
  60.  * $auth = new Auth('SOAP', $options, 'loginFunction');
  61.  * $auth->start();
  62.  *
  63.  * ...
  64.  *
  65.  * ?>
  66.  *
  67.  * @author   Bruno Pedro <bpedro@co.sapo.pt>
  68.  * @package  Auth
  69.  * @version  $Revision: 1.6 $
  70.  */
  71. {
  72.  
  73.     /**
  74.      * Required options for the class
  75.      * @var array 
  76.      * @access private
  77.      */
  78.     var $_requiredOptions = array('endpoint''namespace''method''encoding''usernamefield''passwordfield');
  79.  
  80.     /**
  81.      * Options for the class
  82.      * @var array 
  83.      * @access private
  84.      */
  85.     var $_options = array();
  86.  
  87.     /**
  88.      * Optional SOAP features
  89.      * @var array 
  90.      * @access private
  91.      */
  92.     var $_features = array();
  93.  
  94.     /**
  95.      * The SOAP response
  96.      * @var array 
  97.      * @access public
  98.      */
  99.      var $soapResponse = array();
  100.  
  101.     /**
  102.      * Constructor of the container class
  103.      *
  104.      * @param  $options, associative array with endpoint, namespace, method,
  105.      *                    usernamefield, passwordfield and optional features
  106.      */
  107.     function Auth_Container_SOAP($options)
  108.     {
  109.         $this->_options $options;
  110.         if (!isset($this->_options['matchpasswords'])) {
  111.             $this->_options['matchpasswords'= true;
  112.         }
  113.         if (!empty($this->_options['_features'])) {
  114.             $this->_features $this->_options['_features'];
  115.             unset($this->_options['_features']);
  116.         }
  117.     }
  118.  
  119.     /**
  120.      * Fetch data from SOAP service
  121.      *
  122.      * Requests the SOAP service for the given username/password
  123.      * combination.
  124.      *
  125.      * @param  string Username
  126.      * @param  string Password
  127.      * @return mixed Returns the SOAP response or false if something went wrong
  128.      */
  129.     function fetchData($username$password)
  130.     {
  131.         // check if all required options are set
  132.         if (array_intersect($this->_requiredOptionsarray_keys($this->_options)) != $this->_requiredOptions{
  133.             return false;
  134.         else {
  135.             // create a SOAP client and set encoding
  136.             $soapClient = new SOAP_Client($this->_options['endpoint']);
  137.             $soapClient->setEncoding($this->_options['encoding']);
  138.         }
  139.         // assign username and password fields
  140.         $usernameField = new SOAP_Value($this->_options['usernamefield'],'string'$username);
  141.         $passwordField = new SOAP_Value($this->_options['passwordfield'],'string'$password);
  142.         $SOAPParams = array($usernameField$passwordField);
  143.         // assign optional features
  144.         foreach ($this->_features as $fieldName => $fieldValue{
  145.             $SOAPParams[= new SOAP_Value($fieldName'string'$fieldValue);
  146.         }
  147.         // make SOAP call
  148.         $this->soapResponse = $soapClient->call(
  149.                                   $this->_options['method'],
  150.                                   $SOAPParams,
  151.                                   array('namespace' => $this->_options['namespace'])
  152.                                                );
  153.         if (!PEAR::isError($this->soapResponse)) {
  154.             if ($this->_options['matchpasswords']{
  155.                 // check if passwords match
  156.                 if ($password == $this->soapResponse->{$this->_options['passwordfield']}{
  157.                     return true;
  158.                 else {
  159.                     return false;
  160.                 }
  161.             else {
  162.                 return true;
  163.             }
  164.         else {
  165.             return false;
  166.         }
  167.     }
  168. }
  169. ?>

Documentation generated on Mon, 11 Mar 2019 13:52:33 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.