Subversion Repositories Applications.papyrus

Rev

Rev 1173 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1173 Rev 1713
Line 17... Line 17...
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
 */
Line 25... Line 25...
25
 
25
 
26
/**
26
/**
Line 36... Line 36...
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
Line 56... Line 56...
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
 *   );
Line 77... Line 77...
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
 *   );
Line 99... Line 99...
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
{
Line 113... Line 113...
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',
Line 141... Line 141...
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()
Line 149... Line 149...
149
 
149
 
150
    /**
150
    /**
Line 162... Line 162...
162
        }
162
        }
Line 163... Line 163...
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
        }
Line 168... Line 168...
168
    }
168
    }
169
 
169
 
Line 179... Line 179...
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;
Line 188... Line 189...
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
        }
Line 217... Line 218...
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
 
Line 244... Line 245...
244
    // }}}
245
    // }}}
245
    // {{{ _setDefaults()
246
    // {{{ _setDefaults()
Line 250... Line 251...
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
    }
Line 263... Line 264...
263
 
264
 
264
    // }}}
265
    // }}}
265
        
266
 
266
}
267
}