Subversion Repositories Applications.papyrus

Rev

Rev 1173 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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