Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1712 jp_milcent 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: SOAP5.php,v 1.1.4.2 2007-11-19 14:54:05 jp_milcent Exp $
23
 * @since      File available since Release 1.4.0
24
 */
25
 
26
/**
27
 * Include Auth_Container base class
28
 */
29
require_once "Auth/Container.php";
30
/**
31
 * Include PEAR package for error handling
32
 */
33
require_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.5.4  File: $Revision: 1.1.4.2 $
105
 * @since      Class available since Release 1.4.0
106
 */
107
class 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
        $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
 
223
    /**
224
     * Validate that the options passed to the container class are enough for us to proceed
225
     *
226
     * @access private
227
     * @param  array
228
     */
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
 
248
    /**
249
     * Set some default options
250
     *
251
     * @access private
252
     * @return void
253
     */
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
?>