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.7 2005/02/16 09:06:47 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.7 $
  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.      * The SOAP client
  103.      * @var mixed 
  104.      * @access public
  105.      */
  106.      var $soapClient = null;
  107.  
  108.     /**
  109.      * Constructor of the container class
  110.      *
  111.      * @param  $options, associative array with endpoint, namespace, method,
  112.      *                    usernamefield, passwordfield and optional features
  113.      */
  114.     function Auth_Container_SOAP($options)
  115.     {
  116.         $this->_options $options;
  117.         if (!isset($this->_options['matchpasswords'])) {
  118.             $this->_options['matchpasswords'= true;
  119.         }
  120.         if (!empty($this->_options['_features'])) {
  121.             $this->_features $this->_options['_features'];
  122.             unset($this->_options['_features']);
  123.         }
  124.     }
  125.  
  126.     /**
  127.      * Fetch data from SOAP service
  128.      *
  129.      * Requests the SOAP service for the given username/password
  130.      * combination.
  131.      *
  132.      * @param  string Username
  133.      * @param  string Password
  134.      * @return mixed Returns the SOAP response or false if something went wrong
  135.      */
  136.     function fetchData($username$password)
  137.     {
  138.         // check if all required options are set
  139.         if (array_intersect($this->_requiredOptionsarray_keys($this->_options)) != $this->_requiredOptions{
  140.             return false;
  141.         else {
  142.             // create a SOAP client and set encoding
  143.             $this->soapClient = new SOAP_Client($this->_options['endpoint']);
  144.             $this->soapClient->setEncoding($this->_options['encoding']);
  145.         }
  146.         // set the trace option if requested
  147.         if (isset($this->_options['trace'])) {
  148.             $this->soapClient->__options['trace'= true;
  149.         }
  150.         // set the timeout option if requested
  151.         if (isset($this->_options['timeout'])) {
  152.             $this->soapClient->__options['timeout'$this->_options['timeout'];
  153.         }
  154.         // assign username and password fields
  155.         $usernameField = new SOAP_Value($this->_options['usernamefield'],'string'$username);
  156.         $passwordField = new SOAP_Value($this->_options['passwordfield'],'string'$password);
  157.         $SOAPParams = array($usernameField$passwordField);
  158.         // assign optional features
  159.         foreach ($this->_features as $fieldName => $fieldValue{
  160.             $SOAPParams[= new SOAP_Value($fieldName'string'$fieldValue);
  161.         }
  162.         // make SOAP call
  163.         $this->soapResponse = $this->soapClient->call(
  164.                                   $this->_options['method'],
  165.                                   $SOAPParams,
  166.                                   array('namespace' => $this->_options['namespace'])
  167.                                                );
  168.         if (!PEAR::isError($this->soapResponse)) {
  169.             if ($this->_options['matchpasswords']{
  170.                 // check if passwords match
  171.                 if ($password == $this->soapResponse->{$this->_options['passwordfield']}{
  172.                     return true;
  173.                 else {
  174.                     return false;
  175.                 }
  176.             else {
  177.                 return true;
  178.             }
  179.         else {
  180.             return false;
  181.         }
  182.     }
  183. }
  184. ?>

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