Subversion Repositories Applications.papyrus

Rev

Rev 1987 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1987 Rev 1988
Line -... Line 1...
-
 
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
-
 
6
 *
-
 
7
 * PHP versions 4 and 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     Bruno Pedro <bpedro@co.sapo.pt>
-
 
18
 * @author     Adam Ashley <aashley@php.net>
-
 
19
 * @copyright  2001-2006 The PHP Group
-
 
20
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
-
 
21
 * @version    CVS: $Id: SOAP.php,v 1.3 2007-11-19 15:11:00 jp_milcent Exp $
-
 
22
 * @link       http://pear.php.net/package/Auth
-
 
23
 * @since      File available since Release 1.2.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
 * Include PEAR SOAP_Client
-
 
36
 */
-
 
37
require_once 'SOAP/Client.php';
-
 
38
 
-
 
39
/**
-
 
40
 * Storage driver for fetching login data from SOAP
-
 
41
 *
-
 
42
 * This class takes one parameter (options), where
-
 
43
 * you specify the following fields: endpoint, namespace,
-
 
44
 * method, encoding, usernamefield and passwordfield.
-
 
45
 *
-
 
46
 * You can use specify features of your SOAP service
-
 
47
 * by providing its parameters in an associative manner by
-
 
48
 * using the '_features' array through the options parameter.
-
 
49
 *
-
 
50
 * The 'matchpassword' option should be set to false if your
-
 
51
 * webservice doesn't return (username,password) pairs, but
-
 
52
 * instead returns error when the login is invalid.
-
 
53
 *
-
 
54
 * Example usage:
-
 
55
 *
-
 
56
 * <?php
-
 
57
 *
-
 
58
 * ...
-
 
59
 *
-
 
60
 * $options = array (
-
 
61
 *             'endpoint' => 'http://your.soap.service/endpoint',
-
 
62
 *             'namespace' => 'urn:/Your/Namespace',
-
 
63
 *             'method' => 'get',
-
 
64
 *             'encoding' => 'UTF-8',
-
 
65
 *             'usernamefield' => 'login',
-
 
66
 *             'passwordfield' => 'password',
-
 
67
 *             'matchpasswords' => false,
-
 
68
 *             '_features' => array (
-
 
69
 *                             'example_feature' => 'example_value',
-
 
70
 *                             'another_example'  => ''
-
 
71
 *                             )
-
 
72
 *             );
-
 
73
 * $auth = new Auth('SOAP', $options, 'loginFunction');
-
 
74
 * $auth->start();
-
 
75
 *
-
 
76
 * ...
-
 
77
 *
-
 
78
 * ?>
-
 
79
 *
-
 
80
 * @category   Authentication
-
 
81
 * @package    Auth
-
 
82
 * @author     Bruno Pedro <bpedro@co.sapo.pt>
-
 
83
 * @author     Adam Ashley <aashley@php.net>
-
 
84
 * @copyright  2001-2006 The PHP Group
-
 
85
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
-
 
86
 * @version    Release: 1.5.4  File: $Revision: 1.3 $
-
 
87
 * @link       http://pear.php.net/package/Auth
-
 
88
 * @since      Class available since Release 1.2.0
-
 
89
 */
-
 
90
class Auth_Container_SOAP extends Auth_Container
-
 
91
{
-
 
92
 
-
 
93
    // {{{ properties
-
 
94
 
-
 
95
    /**
-
 
96
     * Required options for the class
-
 
97
     * @var array
-
 
98
     * @access private
-
 
99
     */
-
 
100
    var $_requiredOptions = array(
-
 
101
            'endpoint',
-
 
102
            'namespace',
-
 
103
            'method',
-
 
104
            'encoding',
-
 
105
            'usernamefield',
-
 
106
            'passwordfield',
-
 
107
            );
-
 
108
 
-
 
109
    /**
-
 
110
     * Options for the class
-
 
111
     * @var array
-
 
112
     * @access private
-
 
113
     */
-
 
114
    var $_options = array();
-
 
115
 
-
 
116
    /**
-
 
117
     * Optional SOAP features
-
 
118
     * @var array
-
 
119
     * @access private
-
 
120
     */
-
 
121
    var $_features = array();
-
 
122
 
-
 
123
    /**
-
 
124
     * The SOAP response
-
 
125
     * @var array
-
 
126
     * @access public
-
 
127
     */
-
 
128
     var $soapResponse = array();
-
 
129
 
-
 
130
    /**
-
 
131
     * The SOAP client
-
 
132
     * @var mixed
-
 
133
     * @access public
-
 
134
     */
-
 
135
     var $soapClient = null;
-
 
136
 
-
 
137
    // }}}
-
 
138
    // {{{ Auth_Container_SOAP() [constructor]
-
 
139
 
-
 
140
    /**
-
 
141
     * Constructor of the container class
-
 
142
     *
-
 
143
     * @param  $options, associative array with endpoint, namespace, method,
-
 
144
     *                   usernamefield, passwordfield and optional features
-
 
145
     */
-
 
146
    function Auth_Container_SOAP($options)
-
 
147
    {
-
 
148
        $this->_options = $options;
-
 
149
        if (!isset($this->_options['matchpasswords'])) {
-
 
150
            $this->_options['matchpasswords'] = true;
-
 
151
        }
-
 
152
        if (!empty($this->_options['_features'])) {
-
 
153
            $this->_features = $this->_options['_features'];
-
 
154
            unset($this->_options['_features']);
-
 
155
        }
-
 
156
    }
-
 
157
 
-
 
158
    // }}}
-
 
159
    // {{{ fetchData()
-
 
160
 
-
 
161
    /**
-
 
162
     * Fetch data from SOAP service
-
 
163
     *
-
 
164
     * Requests the SOAP service for the given username/password
-
 
165
     * combination.
-
 
166
     *
-
 
167
     * @param  string Username
-
 
168
     * @param  string Password
-
 
169
     * @return mixed Returns the SOAP response or false if something went wrong
-
 
170
     */
-
 
171
    function fetchData($username, $password)
-
 
172
    {
-
 
173
        $this->log('Auth_Container_SOAP::fetchData() called.', AUTH_LOG_DEBUG);
-
 
174
        // check if all required options are set
-
 
175
        if (array_intersect($this->_requiredOptions, array_keys($this->_options)) != $this->_requiredOptions) {
-
 
176
            return false;
-
 
177
        } else {
-
 
178
            // create a SOAP client and set encoding
-
 
179
            $this->soapClient = new SOAP_Client($this->_options['endpoint']);
-
 
180
            $this->soapClient->setEncoding($this->_options['encoding']);
-
 
181
        }
-
 
182
 
-
 
183
        // set the trace option if requested
-
 
184
        if (isset($this->_options['trace'])) {
-
 
185
            $this->soapClient->__options['trace'] = true;
-
 
186
        }
-
 
187
 
-
 
188
        // set the timeout option if requested
-
 
189
        if (isset($this->_options['timeout'])) {
-
 
190
            $this->soapClient->__options['timeout'] = $this->_options['timeout'];
-
 
191
        }
-
 
192
 
-
 
193
        // assign username and password fields
-
 
194
        $usernameField = new SOAP_Value($this->_options['usernamefield'],'string', $username);
-
 
195
        $passwordField = new SOAP_Value($this->_options['passwordfield'],'string', $password);
-
 
196
        $SOAPParams = array($usernameField, $passwordField);
-
 
197
 
-
 
198
        // assign optional features
-
 
199
        foreach ($this->_features as $fieldName => $fieldValue) {
-
 
200
            $SOAPParams[] = new SOAP_Value($fieldName, 'string', $fieldValue);
-
 
201
        }
-
 
202
 
-
 
203
        // make SOAP call
-
 
204
        $this->soapResponse = $this->soapClient->call(
-
 
205
                $this->_options['method'],
-
 
206
                $SOAPParams,
-
 
207
                array('namespace' => $this->_options['namespace'])
-
 
208
                );
-
 
209
 
-
 
210
        if (!PEAR::isError($this->soapResponse)) {
-
 
211
            if ($this->_options['matchpasswords']) {
-
 
212
                // check if passwords match
-
 
213
                if ($password == $this->soapResponse->{$this->_options['passwordfield']}) {
-
 
214
                    return true;
-
 
215
                } else {
-
 
216
                    return false;
-
 
217
                }
-
 
218
            } else {
-
 
219
                return true;
-
 
220
            }
-
 
221
        } else {
-
 
222
            return false;
-
 
223
        }
-
 
224
    }
-
 
225
 
-
 
226
    // }}}
-
 
227
 
-
 
228
}
-
 
229
?>