~ubuntu-branches/ubuntu/saucy/horde3/saucy

« back to all changes in this revision

Viewing changes to lib/Horde/Auth/application.php

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2005-05-04 23:08:08 UTC
  • Revision ID: james.westby@ubuntu.com-20050504230808-p4hf3hk28o3v7wir
Tags: upstream-3.0.4
ImportĀ upstreamĀ versionĀ 3.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * The Auth_application class provides a wrapper around
 
4
 * application-provided Horde authentication which fits inside the
 
5
 * Horde Auth:: API.
 
6
 *
 
7
 * Required parameters:
 
8
 * ====================
 
9
 *   'app'  --  The application which is providing authentication.
 
10
 *
 
11
 *
 
12
 * $Horde: framework/Auth/Auth/application.php,v 1.27.10.5 2005/01/19 15:05:03 jan Exp $
 
13
 *
 
14
 * Copyright 2002-2005 Chuck Hagenbuch <chuck@horde.org>
 
15
 *
 
16
 * See the enclosed file COPYING for license information (LGPL). If you
 
17
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 
18
 *
 
19
 * @author  Chuck Hagenbuch <chuck@horde.org>
 
20
 * @since   Horde 3.0
 
21
 * @package Horde_Auth
 
22
 */
 
23
class Auth_application extends Auth {
 
24
 
 
25
    /**
 
26
     * An array of capabilities, so that the driver can report which
 
27
     * operations it supports and which it doesn't.
 
28
     *
 
29
     * @var array $capabilities
 
30
     */
 
31
    var $capabilities = array('add'           => false,
 
32
                              'update'        => false,
 
33
                              'resetpassword' => false,
 
34
                              'remove'        => false,
 
35
                              'list'          => false,
 
36
                              'transparent'   => false);
 
37
 
 
38
    /**
 
39
     * Constructs a new Application authentication object.
 
40
     *
 
41
     * @access public
 
42
     *
 
43
     * @param optional array $params  A hash containing connection parameters.
 
44
     */
 
45
    function Auth_application($params = array())
 
46
    {
 
47
        $this->_setParams($params);
 
48
    }
 
49
 
 
50
    /**
 
51
     * Queries the current Auth object to find out if it supports the given
 
52
     * capability.
 
53
     *
 
54
     * @access public
 
55
     *
 
56
     * @param string $capability  The capability to test for.
 
57
     *
 
58
     * @return boolean  Whether or not the capability is supported.
 
59
     */
 
60
    function hasCapability($capability)
 
61
    {
 
62
        static $loaded = array();
 
63
 
 
64
        $methods = array('list' => 'userList',
 
65
                         'add' => 'addUser',
 
66
                         'update' => 'updateUser',
 
67
                         'remove' => 'removeUser');
 
68
 
 
69
        if (empty($loaded[$capability]) && isset($methods[$capability])) {
 
70
            $this->capabilities[$capability] = $GLOBALS['registry']->hasMethod($methods[$capability], $this->_params['app']);
 
71
            $loaded[$capability] = true;
 
72
        }
 
73
 
 
74
        return !empty($this->capabilities[$capability]);
 
75
    }
 
76
 
 
77
    /**
 
78
     * Set connection parameters.
 
79
     *
 
80
     * @access private
 
81
     *
 
82
     * @param array $params  A hash containing connection parameters.
 
83
     */
 
84
    function _setParams($params)
 
85
    {
 
86
        Horde::assertDriverConfig($params, 'auth',
 
87
                                  array('app'),
 
88
                                  'authentication application');
 
89
 
 
90
        if (empty($GLOBALS['registry']->applications[$params['app']])) {
 
91
            Horde::fatal($params['app'] . ' is not configured in the Horde Registry.', __FILE__, __LINE__);
 
92
        }
 
93
 
 
94
        $this->_params = $params;
 
95
    }
 
96
 
 
97
    /**
 
98
     * Find out if a set of login credentials are valid.
 
99
     *
 
100
     * @access private
 
101
     *
 
102
     * @param string $userId      The userId to check.
 
103
     * @param array $credentials  The credentials to use.
 
104
     *
 
105
     * @return boolean  Whether or not the credentials are valid.
 
106
     */
 
107
    function _authenticate($userId, $credentials)
 
108
    {
 
109
        if (!$GLOBALS['registry']->hasMethod('authenticate', $this->_params['app'])) {
 
110
            Horde::fatal($this->_params['app'] . ' does not provide an authenticate() method.', __FILE__, __LINE__);
 
111
        }
 
112
        return $GLOBALS['registry']->callByPackage($this->_params['app'], 'authenticate',
 
113
                                                   array('userId' => $userId,
 
114
                                                         'credentials' => $credentials,
 
115
                                                         'params' => $this->_params));
 
116
    }
 
117
 
 
118
    /**
 
119
     * Return the URI of the login screen for this authentication
 
120
     * method.
 
121
     *
 
122
     * @access public
 
123
     *
 
124
     * @param optional string $app  The application to use.
 
125
     * @param optional string $url  The URL to redirect to after login.
 
126
     *
 
127
     * @return string  The login screen URI.
 
128
     */
 
129
    function _getLoginScreen($app = 'horde', $url = '')
 
130
    {
 
131
        return parent::_getLoginScreen($this->_params['app'], $url);
 
132
    }
 
133
 
 
134
    /**
 
135
     * List all users in the system.
 
136
     *
 
137
     * @access public
 
138
     *
 
139
     * @return mixed  The array of userIds, or a PEAR_Error object on failure.
 
140
     */
 
141
    function listUsers()
 
142
    {
 
143
        if ($this->hasCapability('list')) {
 
144
            return $GLOBALS['registry']->callByPackage($this->_params['app'], 'userList');
 
145
        } else {
 
146
            return PEAR::raiseError('unsupported');
 
147
        }
 
148
    }
 
149
 
 
150
    /**
 
151
     * Add a set of authentication credentials.
 
152
     *
 
153
     * @access public
 
154
     *
 
155
     * @param string $userId      The userId to add.
 
156
     * @param array $credentials  The credentials to use.
 
157
     *
 
158
     * @return mixed  True on success or a PEAR_Error object on failure.
 
159
     */
 
160
    function addUser($userId, $credentials)
 
161
    {
 
162
        if ($this->hasCapability('add')) {
 
163
            return $GLOBALS['registry']->callByPackage($this->_params['app'], 'addUser', array($userId, $credentials));
 
164
        } else {
 
165
            return PEAR::raiseError('unsupported');
 
166
        }
 
167
    }
 
168
 
 
169
    /**
 
170
     * Update a set of authentication credentials.
 
171
     *
 
172
     * @access public
 
173
     *
 
174
     * @param string $oldID       The old userId.
 
175
     * @param string $newID       The new userId.
 
176
     * @param array $credentials  The new credentials
 
177
     *
 
178
     * @return mixed  True on success or a PEAR_Error object on failure.
 
179
     */
 
180
    function updateUser($oldID, $newID, $credentials)
 
181
    {
 
182
        if ($this->hasCapability('update')) {
 
183
            return $GLOBALS['registry']->callByPackage($this->_params['app'], 'updateUser', array($oldID, $newID, $credentials));
 
184
        } else {
 
185
            return PEAR::raiseError('unsupported');
 
186
        }
 
187
    }
 
188
 
 
189
    /**
 
190
     * Delete a set of authentication credentials.
 
191
     *
 
192
     * @access public
 
193
     *
 
194
     * @param string $userId  The userId to delete.
 
195
     *
 
196
     * @return mixed  True on success or a PEAR_Error object on failure.
 
197
     */
 
198
    function removeUser($userId)
 
199
    {
 
200
        if ($this->hasCapability('remove')) {
 
201
            $result = $GLOBALS['registry']->callByPackage($this->_params['app'], 'removeUser', array($userId));
 
202
        } else {
 
203
            return PEAR::raiseError('unsupported');
 
204
        }
 
205
        if (is_a($result, 'PEAR_Error')) {
 
206
            return $result;
 
207
        }
 
208
 
 
209
        return $this->removeUserData($userId);
 
210
    }
 
211
 
 
212
}