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

Source for file SOAP.php

Documentation is available at SOAP.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  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. // | [email protected] so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Bruno Pedro <[email protected]>                             |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: SOAP.php,v 1.8 2006/02/28 02:19:22 aashley 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 <[email protected]>
  68.  * @author   Adam Ashley <[email protected]>
  69.  * @package  Auth
  70.  * @version  $Revision: 1.8 $
  71.  */
  72. {
  73.  
  74.     // {{{ properties
  75.  
  76.     /**
  77.      * Required options for the class
  78.      * @var array 
  79.      * @access private
  80.      */
  81.     var $_requiredOptions = array(
  82.             'endpoint',
  83.             'namespace',
  84.             'method',
  85.             'encoding',
  86.             'usernamefield',
  87.             'passwordfield',
  88.             );
  89.  
  90.     /**
  91.      * Options for the class
  92.      * @var array 
  93.      * @access private
  94.      */
  95.     var $_options = array();
  96.  
  97.     /**
  98.      * Optional SOAP features
  99.      * @var array 
  100.      * @access private
  101.      */
  102.     var $_features = array();
  103.  
  104.     /**
  105.      * The SOAP response
  106.      * @var array 
  107.      * @access public
  108.      */
  109.      var $soapResponse = array();
  110.  
  111.     /**
  112.      * The SOAP client
  113.      * @var mixed 
  114.      * @access public
  115.      */
  116.      var $soapClient = null;
  117.  
  118.     // }}}
  119.  
  120.     // {{{ Auth_Container_SOAP() [constructor]
  121.  
  122.     /**
  123.      * Constructor of the container class
  124.      *
  125.      * @param  $options, associative array with endpoint, namespace, method,
  126.      *                    usernamefield, passwordfield and optional features
  127.      */
  128.     function Auth_Container_SOAP($options)
  129.     {
  130.         $this->_options $options;
  131.         if (!isset($this->_options['matchpasswords'])) {
  132.             $this->_options['matchpasswords'= true;
  133.         }
  134.         if (!empty($this->_options['_features'])) {
  135.             $this->_features $this->_options['_features'];
  136.             unset($this->_options['_features']);
  137.         }
  138.     }
  139.  
  140.     // }}}
  141.     // {{{ fetchData()
  142.  
  143.     /**
  144.      * Fetch data from SOAP service
  145.      *
  146.      * Requests the SOAP service for the given username/password
  147.      * combination.
  148.      *
  149.      * @param  string Username
  150.      * @param  string Password
  151.      * @return mixed Returns the SOAP response or false if something went wrong
  152.      */
  153.     function fetchData($username$password)
  154.     {
  155.         // check if all required options are set
  156.         if (array_intersect($this->_requiredOptionsarray_keys($this->_options)) != $this->_requiredOptions{
  157.             return false;
  158.         else {
  159.             // create a SOAP client and set encoding
  160.             $this->soapClient = new SOAP_Client($this->_options['endpoint']);
  161.             $this->soapClient->setEncoding($this->_options['encoding']);
  162.         }
  163.  
  164.         // set the trace option if requested
  165.         if (isset($this->_options['trace'])) {
  166.             $this->soapClient->__options['trace'= true;
  167.         }
  168.  
  169.         // set the timeout option if requested
  170.         if (isset($this->_options['timeout'])) {
  171.             $this->soapClient->__options['timeout'$this->_options['timeout'];
  172.         }
  173.  
  174.         // assign username and password fields
  175.         $usernameField = new SOAP_Value($this->_options['usernamefield'],'string'$username);
  176.         $passwordField = new SOAP_Value($this->_options['passwordfield'],'string'$password);
  177.         $SOAPParams = array($usernameField$passwordField);
  178.  
  179.         // assign optional features
  180.         foreach ($this->_features as $fieldName => $fieldValue{
  181.             $SOAPParams[= new SOAP_Value($fieldName'string'$fieldValue);
  182.         }
  183.  
  184.         // make SOAP call
  185.         $this->soapResponse = $this->soapClient->call(
  186.                 $this->_options['method'],
  187.                 $SOAPParams,
  188.                 array('namespace' => $this->_options['namespace'])
  189.                 );
  190.  
  191.         if (!PEAR::isError($this->soapResponse)) {
  192.             if ($this->_options['matchpasswords']{
  193.                 // check if passwords match
  194.                 if ($password == $this->soapResponse->{$this->_options['passwordfield']}{
  195.                     return true;
  196.                 else {
  197.                     return false;
  198.                 }
  199.             else {
  200.                 return true;
  201.             }
  202.         else {
  203.             return false;
  204.         }
  205.     }
  206.  
  207.     // }}}
  208.  
  209. }
  210. ?>

Documentation generated on Mon, 11 Mar 2019 14:37:17 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.