Subversion Repositories Applications.papyrus

Rev

Rev 1713 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1173 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
2150 mathias 22
 * @version    CVS: $Id: SOAP5.php,v 1.9 2007/07/02 08:25:41 aashley Exp $
1173 jp_milcent 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
1713 jp_milcent 41
 * you specify the following fields:
1173 jp_milcent 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',
1713 jp_milcent 61
 *       'method'         => 'checkAuth',
1173 jp_milcent 62
 *       'usernamefield'  => 'username',
63
 *       'passwordfield'  => 'password',
1713 jp_milcent 64
 *       'matchpasswords' => false,
1173 jp_milcent 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',
1713 jp_milcent 82
 *       'method'         => 'checkAuth',
1173 jp_milcent 83
 *       'usernamefield'  => 'username',
84
 *       'passwordfield'  => 'password',
1713 jp_milcent 85
 *       'matchpasswords' => false,
1173 jp_milcent 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
2150 mathias 104
 * @version    Release: 1.5.4  File: $Revision: 1.9 $
1173 jp_milcent 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(
1713 jp_milcent 118
            'location',
1173 jp_milcent 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();
1713 jp_milcent 146
 
1173 jp_milcent 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']);
1713 jp_milcent 167
        }
1173 jp_milcent 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)
1713 jp_milcent 184
    {
185
        $this->log('Auth_Container_SOAP5::fetchData() called.', AUTH_LOG_DEBUG);
1173 jp_milcent 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);
1713 jp_milcent 192
 
193
        $params = array();
1173 jp_milcent 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;
1713 jp_milcent 200
        $params[$this->_options['passwordfield']] = $password;
201
 
1173 jp_milcent 202
        try {
203
            $this->soapResponse = $soapClient->__soapCall($this->_options['method'], $params);
1713 jp_milcent 204
 
1173 jp_milcent 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
                }
1713 jp_milcent 212
            } else {
1173 jp_milcent 213
                return true;
214
            }
215
        } catch (SoapFault $e) {
216
            return PEAR::raiseError("Error retrieving authentication data. Received SOAP Fault: ".$e->faultstring, $e->faultcode);
1713 jp_milcent 217
        }
1173 jp_milcent 218
    }
219
 
220
    // }}}
221
    // {{{ _validateOptions()
1713 jp_milcent 222
 
1173 jp_milcent 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
     */
1713 jp_milcent 229
    function _validateOptions()
1173 jp_milcent 230
    {
1713 jp_milcent 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'])))) {
1173 jp_milcent 237
            return PEAR::raiseError('Either a WSDL file or a location/uri pair must be specified.');
238
        }
1713 jp_milcent 239
        if (is_null($this->_options['method'])) {
1173 jp_milcent 240
            return PEAR::raiseError('A method to call on the soap service must be specified.');
241
        }
242
        return true;
243
    }
1713 jp_milcent 244
 
1173 jp_milcent 245
    // }}}
246
    // {{{ _setDefaults()
247
 
248
    /**
249
     * Set some default options
250
     *
251
     * @access private
252
     * @return void
253
     */
254
    function _setDefaults()
255
    {
1713 jp_milcent 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;
1173 jp_milcent 263
    }
264
 
265
    // }}}
1713 jp_milcent 266
 
1173 jp_milcent 267
}
268
?>