source: branches/feature-module-update/html/test/kakinaka/pear/Auth/Container/SOAP5.php @ 15080

Revision 15080, 7.9 KB checked in by nanasess, 17 years ago (diff)

svn properties 設定

  • svn:mime-type - application/x-httpd-php; charset=UTF-8
  • svn:keywords - Id
  • Property svn:keywords set to Id
  • Property svn:mime-type set to application/x-httpd-php; charset=UTF-8
Line 
1<?php
2/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
3
4/**
5 * Storage driver for use against a SOAP service using PHP5 SoapClient
6 *
7 * PHP version 5
8 *
9 * LICENSE: This source file is subject to version 3.01 of the PHP license
10 * that is available through the world-wide-web at the following URI:
11 * http://www.php.net/license/3_01.txt.  If you did not receive a copy of
12 * the PHP License and are unable to obtain it through the web, please
13 * send a note to license@php.net so we can mail you a copy immediately.
14 *
15 * @category   Authentication
16 * @package    Auth
17 * @author     Based upon Auth_Container_SOAP by Bruno Pedro <bpedro@co.sapo.pt>
18 * @author     Marcel Oelke <puRe@rednoize.com>
19 * @author     Adam Ashley <aashley@php.net>
20 * @copyright  2001-2006 The PHP Group
21 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
22 * @version    CVS: $Id$
23 * @since      File available since Release 1.4.0
24 */
25
26/**
27 * Include Auth_Container base class
28 */
29require_once "Auth/Container.php";
30/**
31 * Include PEAR package for error handling
32 */
33require_once "PEAR.php";
34
35/**
36 * Storage driver for fetching login data from SOAP using the PHP5 Builtin SOAP
37 * functions. This is a modification of the SOAP Storage driver from Bruno Pedro
38 * thats using the PEAR SOAP Package.
39 *
40 * This class takes one parameter (options), where
41 * you specify the following fields:
42 *  * location and uri, or wsdl file
43 *  * method to call on the SOAP service
44 *  * usernamefield, the name of the parameter where the username is supplied
45 *  * passwordfield, the name of the parameter where the password is supplied
46 *  * matchpassword, whether to look for the password in the response from
47 *                   the function call or assume that no errors means user
48 *                   authenticated.
49 *
50 * See http://www.php.net/manual/en/ref.soap.php for further details
51 * on options for the PHP5 SoapClient which are passed through.
52 *
53 * Example usage without WSDL:
54 *
55 * <?php
56 *
57 * $options = array (
58 *       'wsdl'           => NULL,
59 *       'location'       => 'http://your.soap.service/endpoint',
60 *       'uri'            => 'urn:/Your/Namespace',
61 *       'method'         => 'checkAuth',       
62 *       'usernamefield'  => 'username',
63 *       'passwordfield'  => 'password',
64 *       'matchpasswords' => false,         
65 *       '_features' => array (
66 *           'extra_parameter'    => 'example_value',
67 *           'another_parameter'  => 'foobar'
68 *       )
69 *   );
70 *
71 * $auth = new Auth('SOAP5', $options);
72 * $auth->start();
73 *
74 * ?>
75 *
76 * Example usage with WSDL:
77 *
78 * <?php
79 *
80 * $options = array (
81 *       'wsdl'           => 'http://your.soap.service/wsdl',
82 *       'method'         => 'checkAuth',       
83 *       'usernamefield'  => 'username',
84 *       'passwordfield'  => 'password',
85 *       'matchpasswords' => false,         
86 *       '_features' => array (
87 *           'extra_parameter'    => 'example_value',
88 *           'another_parameter'  => 'foobar'
89 *       )
90 *   );
91 *
92 * $auth = new Auth('SOAP5', $options);
93 * $auth->start();
94 *
95 * ?>
96 *
97 * @category   Authentication
98 * @package    Auth
99 * @author     Based upon Auth_Container_SOAP by Bruno Pedro <bpedro@co.sapo.pt>
100 * @author     Marcel Oelke <puRe@rednoize.com>
101 * @author     Adam Ashley <aashley@php.net>
102 * @copyright  2001-2006 The PHP Group
103 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
104 * @version    Release: 1.4.2  File: $Revision: 8713 $
105 * @since      Class available since Release 1.4.0
106 */
107class Auth_Container_SOAP5 extends Auth_Container
108{
109
110    // {{{ properties
111
112    /**
113     * Required options for the class
114     * @var array
115     * @access private
116     */
117    var $_requiredOptions = array(
118            'location',
119            'uri',
120            'method',
121            'usernamefield',
122            'passwordfield',
123            'wsdl',
124            );
125
126    /**
127     * Options for the class
128     * @var array
129     * @access private
130     */
131    var $_options = array();
132
133    /**
134     * Optional SOAP features
135     * @var array
136     * @access private
137     */
138    var $_features = array();
139
140    /**
141     * The SOAP response
142     * @var array
143     * @access public
144     */
145    var $soapResponse = array();
146     
147    // }}}
148    // {{{ Auth_Container_SOAP5()
149
150    /**
151     * Constructor of the container class
152     *
153     * @param  $options, associative array with endpoint, namespace, method,
154     *                   usernamefield, passwordfield and optional features
155     */
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
173    /**
174     * Fetch data from SOAP service
175     *
176     * Requests the SOAP service for the given username/password
177     * combination.
178     *
179     * @param  string Username
180     * @param  string Password
181     * @return mixed Returns the SOAP response or false if something went wrong
182     */
183    function fetchData($username, $password)
184    {       
185        $result = $this->_validateOptions();
186        if (PEAR::isError($result))
187            return $result;
188
189        // create a SOAP client
190        $soapClient = new SoapClient($this->_options["wsdl"], $this->_options);
191       
192        $params = array();       
193        // first, assign the optional features
194        foreach ($this->_features as $fieldName => $fieldValue) {
195            $params[$fieldName] = $fieldValue;
196        }
197        // assign username and password ...
198        $params[$this->_options['usernamefield']] = $username;
199        $params[$this->_options['passwordfield']] = $password;               
200               
201        try {
202            $this->soapResponse = $soapClient->__soapCall($this->_options['method'], $params);
203                       
204            if ($this->_options['matchpasswords']) {
205                // check if passwords match
206                if ($password == $this->soapResponse[$this->_options['passwordfield']]) {
207                    return true;
208                } else {
209                    return false;
210                }
211            } else {               
212                return true;
213            }
214        } catch (SoapFault $e) {
215            return PEAR::raiseError("Error retrieving authentication data. Received SOAP Fault: ".$e->faultstring, $e->faultcode);
216        }       
217    }
218
219    // }}}
220    // {{{ _validateOptions()
221   
222    /**
223     * Validate that the options passed to the container class are enough for us to proceed
224     *
225     * @access private
226     * @param  array
227     */
228    function _validateOptions($array)
229    {
230        if (   (   is_null($this->options['wsdl'])
231                && is_null($this->options['location'])
232                && is_null($this->options['uri']))
233            || (   is_null($this->options['wsdl'])
234                && (   is_null($this->options['location'])
235                    || is_null($this->options['uri'])))) {
236            return PEAR::raiseError('Either a WSDL file or a location/uri pair must be specified.');
237        }
238        if (is_null($this->options['method'])) {
239            return PEAR::raiseError('A method to call on the soap service must be specified.');
240        }
241        return true;
242    }
243   
244    // }}}
245    // {{{ _setDefaults()
246
247    /**
248     * Set some default options
249     *
250     * @access private
251     * @return void
252     */
253    function _setDefaults()
254    {
255        $this->options['wsdl']           = null;
256        $this->options['location']       = null;
257        $this->options['uri']            = null;
258        $this->options['method']         = null;
259        $this->options['usernamefield']  = 'username';
260        $this->options['passwordfield']  = 'password';
261        $this->options['matchpasswords'] = true;
262    }
263
264    // }}}
265       
266}
267?>
Note: See TracBrowser for help on using the repository browser.