xref: /dokuwiki/inc/Extension/AuthPlugin.php (revision 81e99965a7aab42532a9b5313c6c64b8272c436c)
1e1d9dcc8SAndreas Gohr<?php
2e1d9dcc8SAndreas Gohr
3e1d9dcc8SAndreas Gohrnamespace dokuwiki\Extension;
4e1d9dcc8SAndreas Gohr
5e1d9dcc8SAndreas Gohr/**
6e1d9dcc8SAndreas Gohr * Auth Plugin Prototype
7e1d9dcc8SAndreas Gohr *
8e1d9dcc8SAndreas Gohr * allows to authenticate users in a plugin
9e1d9dcc8SAndreas Gohr *
10e1d9dcc8SAndreas Gohr * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
11e1d9dcc8SAndreas Gohr * @author     Chris Smith <chris@jalakai.co.uk>
12e1d9dcc8SAndreas Gohr * @author     Jan Schumann <js@jschumann-it.com>
13e1d9dcc8SAndreas Gohr */
14e1d9dcc8SAndreas Gohrabstract class AuthPlugin extends Plugin
15e1d9dcc8SAndreas Gohr{
16e1d9dcc8SAndreas Gohr    public $success = true;
17e1d9dcc8SAndreas Gohr
18e1d9dcc8SAndreas Gohr    /**
19e1d9dcc8SAndreas Gohr     * Possible things an auth backend module may be able to
20e1d9dcc8SAndreas Gohr     * do. The things a backend can do need to be set to true
21e1d9dcc8SAndreas Gohr     * in the constructor.
22e1d9dcc8SAndreas Gohr     */
23e1d9dcc8SAndreas Gohr    protected $cando = array(
24e1d9dcc8SAndreas Gohr        'addUser' => false, // can Users be created?
25e1d9dcc8SAndreas Gohr        'delUser' => false, // can Users be deleted?
26e1d9dcc8SAndreas Gohr        'modLogin' => false, // can login names be changed?
27e1d9dcc8SAndreas Gohr        'modPass' => false, // can passwords be changed?
28e1d9dcc8SAndreas Gohr        'modName' => false, // can real names be changed?
29e1d9dcc8SAndreas Gohr        'modMail' => false, // can emails be changed?
30e1d9dcc8SAndreas Gohr        'modGroups' => false, // can groups be changed?
31e1d9dcc8SAndreas Gohr        'getUsers' => false, // can a (filtered) list of users be retrieved?
32e1d9dcc8SAndreas Gohr        'getUserCount' => false, // can the number of users be retrieved?
33e1d9dcc8SAndreas Gohr        'getGroups' => false, // can a list of available groups be retrieved?
34e1d9dcc8SAndreas Gohr        'external' => false, // does the module do external auth checking?
35e1d9dcc8SAndreas Gohr        'logout' => true, // can the user logout again? (eg. not possible with HTTP auth)
36e1d9dcc8SAndreas Gohr    );
37e1d9dcc8SAndreas Gohr
38e1d9dcc8SAndreas Gohr    /**
39e1d9dcc8SAndreas Gohr     * Constructor.
40e1d9dcc8SAndreas Gohr     *
41e1d9dcc8SAndreas Gohr     * Carry out sanity checks to ensure the object is
42e1d9dcc8SAndreas Gohr     * able to operate. Set capabilities in $this->cando
43e1d9dcc8SAndreas Gohr     * array here
44e1d9dcc8SAndreas Gohr     *
45e1d9dcc8SAndreas Gohr     * For future compatibility, sub classes should always include a call
46e1d9dcc8SAndreas Gohr     * to parent::__constructor() in their constructors!
47e1d9dcc8SAndreas Gohr     *
48e1d9dcc8SAndreas Gohr     * Set $this->success to false if checks fail
49e1d9dcc8SAndreas Gohr     *
50e1d9dcc8SAndreas Gohr     * @author  Christopher Smith <chris@jalakai.co.uk>
51e1d9dcc8SAndreas Gohr     */
52e1d9dcc8SAndreas Gohr    public function __construct()
53e1d9dcc8SAndreas Gohr    {
54e1d9dcc8SAndreas Gohr        // the base class constructor does nothing, derived class
55e1d9dcc8SAndreas Gohr        // constructors do the real work
56e1d9dcc8SAndreas Gohr    }
57e1d9dcc8SAndreas Gohr
58e1d9dcc8SAndreas Gohr    /**
59e1d9dcc8SAndreas Gohr     * Available Capabilities. [ DO NOT OVERRIDE ]
60e1d9dcc8SAndreas Gohr     *
61e1d9dcc8SAndreas Gohr     * For introspection/debugging
62e1d9dcc8SAndreas Gohr     *
63e1d9dcc8SAndreas Gohr     * @author  Christopher Smith <chris@jalakai.co.uk>
64e1d9dcc8SAndreas Gohr     * @return  array
65e1d9dcc8SAndreas Gohr     */
66e1d9dcc8SAndreas Gohr    public function getCapabilities()
67e1d9dcc8SAndreas Gohr    {
68e1d9dcc8SAndreas Gohr        return array_keys($this->cando);
69e1d9dcc8SAndreas Gohr    }
70e1d9dcc8SAndreas Gohr
71e1d9dcc8SAndreas Gohr    /**
72e1d9dcc8SAndreas Gohr     * Capability check. [ DO NOT OVERRIDE ]
73e1d9dcc8SAndreas Gohr     *
74e1d9dcc8SAndreas Gohr     * Checks the capabilities set in the $this->cando array and
75e1d9dcc8SAndreas Gohr     * some pseudo capabilities (shortcutting access to multiple
76e1d9dcc8SAndreas Gohr     * ones)
77e1d9dcc8SAndreas Gohr     *
78e1d9dcc8SAndreas Gohr     * ususal capabilities start with lowercase letter
79e1d9dcc8SAndreas Gohr     * shortcut capabilities start with uppercase letter
80e1d9dcc8SAndreas Gohr     *
81e1d9dcc8SAndreas Gohr     * @author  Andreas Gohr <andi@splitbrain.org>
82e1d9dcc8SAndreas Gohr     * @param   string $cap the capability to check
83e1d9dcc8SAndreas Gohr     * @return  bool
84e1d9dcc8SAndreas Gohr     */
85e1d9dcc8SAndreas Gohr    public function canDo($cap)
86e1d9dcc8SAndreas Gohr    {
87e1d9dcc8SAndreas Gohr        switch ($cap) {
88e1d9dcc8SAndreas Gohr            case 'Profile':
89e1d9dcc8SAndreas Gohr                // can at least one of the user's properties be changed?
90e1d9dcc8SAndreas Gohr                return ($this->cando['modPass'] ||
91e1d9dcc8SAndreas Gohr                    $this->cando['modName'] ||
92e1d9dcc8SAndreas Gohr                    $this->cando['modMail']);
93e1d9dcc8SAndreas Gohr                break;
94e1d9dcc8SAndreas Gohr            case 'UserMod':
95e1d9dcc8SAndreas Gohr                // can at least anything be changed?
96e1d9dcc8SAndreas Gohr                return ($this->cando['modPass'] ||
97e1d9dcc8SAndreas Gohr                    $this->cando['modName'] ||
98e1d9dcc8SAndreas Gohr                    $this->cando['modMail'] ||
99e1d9dcc8SAndreas Gohr                    $this->cando['modLogin'] ||
100e1d9dcc8SAndreas Gohr                    $this->cando['modGroups'] ||
101e1d9dcc8SAndreas Gohr                    $this->cando['modMail']);
102e1d9dcc8SAndreas Gohr                break;
103e1d9dcc8SAndreas Gohr            default:
104e1d9dcc8SAndreas Gohr                // print a helping message for developers
105e1d9dcc8SAndreas Gohr                if (!isset($this->cando[$cap])) {
106e1d9dcc8SAndreas Gohr                    msg("Check for unknown capability '$cap' - Do you use an outdated Plugin?", -1);
107e1d9dcc8SAndreas Gohr                }
108e1d9dcc8SAndreas Gohr                return $this->cando[$cap];
109e1d9dcc8SAndreas Gohr        }
110e1d9dcc8SAndreas Gohr    }
111e1d9dcc8SAndreas Gohr
112e1d9dcc8SAndreas Gohr    /**
113e1d9dcc8SAndreas Gohr     * Trigger the AUTH_USERDATA_CHANGE event and call the modification function. [ DO NOT OVERRIDE ]
114e1d9dcc8SAndreas Gohr     *
115e1d9dcc8SAndreas Gohr     * You should use this function instead of calling createUser, modifyUser or
116e1d9dcc8SAndreas Gohr     * deleteUsers directly. The event handlers can prevent the modification, for
117e1d9dcc8SAndreas Gohr     * example for enforcing a user name schema.
118e1d9dcc8SAndreas Gohr     *
119e1d9dcc8SAndreas Gohr     * @author Gabriel Birke <birke@d-scribe.de>
120e1d9dcc8SAndreas Gohr     * @param string $type Modification type ('create', 'modify', 'delete')
121e1d9dcc8SAndreas Gohr     * @param array $params Parameters for the createUser, modifyUser or deleteUsers method.
122e1d9dcc8SAndreas Gohr     *                       The content of this array depends on the modification type
123e1d9dcc8SAndreas Gohr     * @return bool|null|int Result from the modification function or false if an event handler has canceled the action
124e1d9dcc8SAndreas Gohr     */
125e1d9dcc8SAndreas Gohr    public function triggerUserMod($type, $params)
126e1d9dcc8SAndreas Gohr    {
127e1d9dcc8SAndreas Gohr        $validTypes = array(
128e1d9dcc8SAndreas Gohr            'create' => 'createUser',
129e1d9dcc8SAndreas Gohr            'modify' => 'modifyUser',
130e1d9dcc8SAndreas Gohr            'delete' => 'deleteUsers',
131e1d9dcc8SAndreas Gohr        );
132e1d9dcc8SAndreas Gohr        if (empty($validTypes[$type])) {
133e1d9dcc8SAndreas Gohr            return false;
134e1d9dcc8SAndreas Gohr        }
135e1d9dcc8SAndreas Gohr
136e1d9dcc8SAndreas Gohr        $result = false;
137e1d9dcc8SAndreas Gohr        $eventdata = array('type' => $type, 'params' => $params, 'modification_result' => null);
138e1d9dcc8SAndreas Gohr        $evt = new Event('AUTH_USER_CHANGE', $eventdata);
139e1d9dcc8SAndreas Gohr        if ($evt->advise_before(true)) {
140e1d9dcc8SAndreas Gohr            $result = call_user_func_array(array($this, $validTypes[$type]), $evt->data['params']);
141e1d9dcc8SAndreas Gohr            $evt->data['modification_result'] = $result;
142e1d9dcc8SAndreas Gohr        }
143e1d9dcc8SAndreas Gohr        $evt->advise_after();
144e1d9dcc8SAndreas Gohr        unset($evt);
145e1d9dcc8SAndreas Gohr        return $result;
146e1d9dcc8SAndreas Gohr    }
147e1d9dcc8SAndreas Gohr
148e1d9dcc8SAndreas Gohr    /**
149e1d9dcc8SAndreas Gohr     * Log off the current user [ OPTIONAL ]
150e1d9dcc8SAndreas Gohr     *
151e1d9dcc8SAndreas Gohr     * Is run in addition to the ususal logoff method. Should
152e1d9dcc8SAndreas Gohr     * only be needed when trustExternal is implemented.
153e1d9dcc8SAndreas Gohr     *
154e1d9dcc8SAndreas Gohr     * @see     auth_logoff()
155e1d9dcc8SAndreas Gohr     * @author  Andreas Gohr <andi@splitbrain.org>
156e1d9dcc8SAndreas Gohr     */
157e1d9dcc8SAndreas Gohr    public function logOff()
158e1d9dcc8SAndreas Gohr    {
159e1d9dcc8SAndreas Gohr    }
160e1d9dcc8SAndreas Gohr
161e1d9dcc8SAndreas Gohr    /**
162e1d9dcc8SAndreas Gohr     * Do all authentication [ OPTIONAL ]
163e1d9dcc8SAndreas Gohr     *
164e1d9dcc8SAndreas Gohr     * Set $this->cando['external'] = true when implemented
165e1d9dcc8SAndreas Gohr     *
166e1d9dcc8SAndreas Gohr     * If this function is implemented it will be used to
167e1d9dcc8SAndreas Gohr     * authenticate a user - all other DokuWiki internals
168*81e99965SPhy     * will not be used for authenticating (except this
169*81e99965SPhy     * function returns null, in which case, DokuWiki will
170*81e99965SPhy     * still run auth_login as a fallback, which may call
171*81e99965SPhy     * checkPass()). If this function is not returning null,
172*81e99965SPhy     * implementing checkPass() is not needed here anymore.
173e1d9dcc8SAndreas Gohr     *
174e1d9dcc8SAndreas Gohr     * The function can be used to authenticate against third
175e1d9dcc8SAndreas Gohr     * party cookies or Apache auth mechanisms and replaces
176e1d9dcc8SAndreas Gohr     * the auth_login() function
177e1d9dcc8SAndreas Gohr     *
178e1d9dcc8SAndreas Gohr     * The function will be called with or without a set
179e1d9dcc8SAndreas Gohr     * username. If the Username is given it was called
180e1d9dcc8SAndreas Gohr     * from the login form and the given credentials might
181e1d9dcc8SAndreas Gohr     * need to be checked. If no username was given it
182e1d9dcc8SAndreas Gohr     * the function needs to check if the user is logged in
183e1d9dcc8SAndreas Gohr     * by other means (cookie, environment).
184e1d9dcc8SAndreas Gohr     *
185e1d9dcc8SAndreas Gohr     * The function needs to set some globals needed by
186e1d9dcc8SAndreas Gohr     * DokuWiki like auth_login() does.
187e1d9dcc8SAndreas Gohr     *
188e1d9dcc8SAndreas Gohr     * @see     auth_login()
189e1d9dcc8SAndreas Gohr     * @author  Andreas Gohr <andi@splitbrain.org>
190e1d9dcc8SAndreas Gohr     *
191e1d9dcc8SAndreas Gohr     * @param   string $user Username
192e1d9dcc8SAndreas Gohr     * @param   string $pass Cleartext Password
193e1d9dcc8SAndreas Gohr     * @param   bool $sticky Cookie should not expire
194*81e99965SPhy     * @return  bool         true on successful auth,
195*81e99965SPhy     *                       null on unknown result (fallback to checkPass)
196e1d9dcc8SAndreas Gohr     */
197e1d9dcc8SAndreas Gohr    public function trustExternal($user, $pass, $sticky = false)
198e1d9dcc8SAndreas Gohr    {
199e1d9dcc8SAndreas Gohr        /* some example:
200e1d9dcc8SAndreas Gohr
201e1d9dcc8SAndreas Gohr        global $USERINFO;
202e1d9dcc8SAndreas Gohr        global $conf;
203e1d9dcc8SAndreas Gohr        $sticky ? $sticky = true : $sticky = false; //sanity check
204e1d9dcc8SAndreas Gohr
205e1d9dcc8SAndreas Gohr        // do the checking here
206e1d9dcc8SAndreas Gohr
207e1d9dcc8SAndreas Gohr        // set the globals if authed
208e1d9dcc8SAndreas Gohr        $USERINFO['name'] = 'FIXME';
209e1d9dcc8SAndreas Gohr        $USERINFO['mail'] = 'FIXME';
210e1d9dcc8SAndreas Gohr        $USERINFO['grps'] = array('FIXME');
211e1d9dcc8SAndreas Gohr        $_SERVER['REMOTE_USER'] = $user;
212e1d9dcc8SAndreas Gohr        $_SESSION[DOKU_COOKIE]['auth']['user'] = $user;
213e1d9dcc8SAndreas Gohr        $_SESSION[DOKU_COOKIE]['auth']['pass'] = $pass;
214e1d9dcc8SAndreas Gohr        $_SESSION[DOKU_COOKIE]['auth']['info'] = $USERINFO;
215e1d9dcc8SAndreas Gohr        return true;
216e1d9dcc8SAndreas Gohr
217e1d9dcc8SAndreas Gohr        */
218e1d9dcc8SAndreas Gohr    }
219e1d9dcc8SAndreas Gohr
220e1d9dcc8SAndreas Gohr    /**
221e1d9dcc8SAndreas Gohr     * Check user+password [ MUST BE OVERRIDDEN ]
222e1d9dcc8SAndreas Gohr     *
223e1d9dcc8SAndreas Gohr     * Checks if the given user exists and the given
224e1d9dcc8SAndreas Gohr     * plaintext password is correct
225e1d9dcc8SAndreas Gohr     *
226e1d9dcc8SAndreas Gohr     * May be ommited if trustExternal is used.
227e1d9dcc8SAndreas Gohr     *
228e1d9dcc8SAndreas Gohr     * @author  Andreas Gohr <andi@splitbrain.org>
229e1d9dcc8SAndreas Gohr     * @param   string $user the user name
230e1d9dcc8SAndreas Gohr     * @param   string $pass the clear text password
231e1d9dcc8SAndreas Gohr     * @return  bool
232e1d9dcc8SAndreas Gohr     */
233e1d9dcc8SAndreas Gohr    public function checkPass($user, $pass)
234e1d9dcc8SAndreas Gohr    {
235e1d9dcc8SAndreas Gohr        msg("no valid authorisation system in use", -1);
236e1d9dcc8SAndreas Gohr        return false;
237e1d9dcc8SAndreas Gohr    }
238e1d9dcc8SAndreas Gohr
239e1d9dcc8SAndreas Gohr    /**
240e1d9dcc8SAndreas Gohr     * Return user info [ MUST BE OVERRIDDEN ]
241e1d9dcc8SAndreas Gohr     *
242e1d9dcc8SAndreas Gohr     * Returns info about the given user needs to contain
243e1d9dcc8SAndreas Gohr     * at least these fields:
244e1d9dcc8SAndreas Gohr     *
245e1d9dcc8SAndreas Gohr     * name string  full name of the user
246e1d9dcc8SAndreas Gohr     * mail string  email address of the user
247e1d9dcc8SAndreas Gohr     * grps array   list of groups the user is in
248e1d9dcc8SAndreas Gohr     *
249e1d9dcc8SAndreas Gohr     * @author  Andreas Gohr <andi@splitbrain.org>
250e1d9dcc8SAndreas Gohr     * @param   string $user the user name
251e1d9dcc8SAndreas Gohr     * @param   bool $requireGroups whether or not the returned data must include groups
252e1d9dcc8SAndreas Gohr     * @return  false|array containing user data or false
253e1d9dcc8SAndreas Gohr     */
254e1d9dcc8SAndreas Gohr    public function getUserData($user, $requireGroups = true)
255e1d9dcc8SAndreas Gohr    {
256e1d9dcc8SAndreas Gohr        if (!$this->cando['external']) msg("no valid authorisation system in use", -1);
257e1d9dcc8SAndreas Gohr        return false;
258e1d9dcc8SAndreas Gohr    }
259e1d9dcc8SAndreas Gohr
260e1d9dcc8SAndreas Gohr    /**
261e1d9dcc8SAndreas Gohr     * Create a new User [implement only where required/possible]
262e1d9dcc8SAndreas Gohr     *
263e1d9dcc8SAndreas Gohr     * Returns false if the user already exists, null when an error
264e1d9dcc8SAndreas Gohr     * occurred and true if everything went well.
265e1d9dcc8SAndreas Gohr     *
266e1d9dcc8SAndreas Gohr     * The new user HAS TO be added to the default group by this
267e1d9dcc8SAndreas Gohr     * function!
268e1d9dcc8SAndreas Gohr     *
269e1d9dcc8SAndreas Gohr     * Set addUser capability when implemented
270e1d9dcc8SAndreas Gohr     *
271e1d9dcc8SAndreas Gohr     * @author  Andreas Gohr <andi@splitbrain.org>
272e1d9dcc8SAndreas Gohr     * @param  string $user
273e1d9dcc8SAndreas Gohr     * @param  string $pass
274e1d9dcc8SAndreas Gohr     * @param  string $name
275e1d9dcc8SAndreas Gohr     * @param  string $mail
276e1d9dcc8SAndreas Gohr     * @param  null|array $grps
277e1d9dcc8SAndreas Gohr     * @return bool|null
278e1d9dcc8SAndreas Gohr     */
279e1d9dcc8SAndreas Gohr    public function createUser($user, $pass, $name, $mail, $grps = null)
280e1d9dcc8SAndreas Gohr    {
281e1d9dcc8SAndreas Gohr        msg("authorisation method does not allow creation of new users", -1);
282e1d9dcc8SAndreas Gohr        return null;
283e1d9dcc8SAndreas Gohr    }
284e1d9dcc8SAndreas Gohr
285e1d9dcc8SAndreas Gohr    /**
286e1d9dcc8SAndreas Gohr     * Modify user data [implement only where required/possible]
287e1d9dcc8SAndreas Gohr     *
288e1d9dcc8SAndreas Gohr     * Set the mod* capabilities according to the implemented features
289e1d9dcc8SAndreas Gohr     *
290e1d9dcc8SAndreas Gohr     * @author  Chris Smith <chris@jalakai.co.uk>
291e1d9dcc8SAndreas Gohr     * @param   string $user nick of the user to be changed
292e1d9dcc8SAndreas Gohr     * @param   array $changes array of field/value pairs to be changed (password will be clear text)
293e1d9dcc8SAndreas Gohr     * @return  bool
294e1d9dcc8SAndreas Gohr     */
295e1d9dcc8SAndreas Gohr    public function modifyUser($user, $changes)
296e1d9dcc8SAndreas Gohr    {
297e1d9dcc8SAndreas Gohr        msg("authorisation method does not allow modifying of user data", -1);
298e1d9dcc8SAndreas Gohr        return false;
299e1d9dcc8SAndreas Gohr    }
300e1d9dcc8SAndreas Gohr
301e1d9dcc8SAndreas Gohr    /**
302e1d9dcc8SAndreas Gohr     * Delete one or more users [implement only where required/possible]
303e1d9dcc8SAndreas Gohr     *
304e1d9dcc8SAndreas Gohr     * Set delUser capability when implemented
305e1d9dcc8SAndreas Gohr     *
306e1d9dcc8SAndreas Gohr     * @author  Chris Smith <chris@jalakai.co.uk>
307e1d9dcc8SAndreas Gohr     * @param   array $users
308e1d9dcc8SAndreas Gohr     * @return  int    number of users deleted
309e1d9dcc8SAndreas Gohr     */
310e1d9dcc8SAndreas Gohr    public function deleteUsers($users)
311e1d9dcc8SAndreas Gohr    {
312e1d9dcc8SAndreas Gohr        msg("authorisation method does not allow deleting of users", -1);
313e1d9dcc8SAndreas Gohr        return 0;
314e1d9dcc8SAndreas Gohr    }
315e1d9dcc8SAndreas Gohr
316e1d9dcc8SAndreas Gohr    /**
317e1d9dcc8SAndreas Gohr     * Return a count of the number of user which meet $filter criteria
318e1d9dcc8SAndreas Gohr     * [should be implemented whenever retrieveUsers is implemented]
319e1d9dcc8SAndreas Gohr     *
320e1d9dcc8SAndreas Gohr     * Set getUserCount capability when implemented
321e1d9dcc8SAndreas Gohr     *
322e1d9dcc8SAndreas Gohr     * @author Chris Smith <chris@jalakai.co.uk>
323e1d9dcc8SAndreas Gohr     * @param  array $filter array of field/pattern pairs, empty array for no filter
324e1d9dcc8SAndreas Gohr     * @return int
325e1d9dcc8SAndreas Gohr     */
326e1d9dcc8SAndreas Gohr    public function getUserCount($filter = array())
327e1d9dcc8SAndreas Gohr    {
328e1d9dcc8SAndreas Gohr        msg("authorisation method does not provide user counts", -1);
329e1d9dcc8SAndreas Gohr        return 0;
330e1d9dcc8SAndreas Gohr    }
331e1d9dcc8SAndreas Gohr
332e1d9dcc8SAndreas Gohr    /**
333e1d9dcc8SAndreas Gohr     * Bulk retrieval of user data [implement only where required/possible]
334e1d9dcc8SAndreas Gohr     *
335e1d9dcc8SAndreas Gohr     * Set getUsers capability when implemented
336e1d9dcc8SAndreas Gohr     *
337e1d9dcc8SAndreas Gohr     * @author  Chris Smith <chris@jalakai.co.uk>
338e1d9dcc8SAndreas Gohr     * @param   int $start index of first user to be returned
339e1d9dcc8SAndreas Gohr     * @param   int $limit max number of users to be returned, 0 for unlimited
340e1d9dcc8SAndreas Gohr     * @param   array $filter array of field/pattern pairs, null for no filter
341e1d9dcc8SAndreas Gohr     * @return  array list of userinfo (refer getUserData for internal userinfo details)
342e1d9dcc8SAndreas Gohr     */
343e1d9dcc8SAndreas Gohr    public function retrieveUsers($start = 0, $limit = 0, $filter = null)
344e1d9dcc8SAndreas Gohr    {
345e1d9dcc8SAndreas Gohr        msg("authorisation method does not support mass retrieval of user data", -1);
346e1d9dcc8SAndreas Gohr        return array();
347e1d9dcc8SAndreas Gohr    }
348e1d9dcc8SAndreas Gohr
349e1d9dcc8SAndreas Gohr    /**
350e1d9dcc8SAndreas Gohr     * Define a group [implement only where required/possible]
351e1d9dcc8SAndreas Gohr     *
352e1d9dcc8SAndreas Gohr     * Set addGroup capability when implemented
353e1d9dcc8SAndreas Gohr     *
354e1d9dcc8SAndreas Gohr     * @author  Chris Smith <chris@jalakai.co.uk>
355e1d9dcc8SAndreas Gohr     * @param   string $group
356e1d9dcc8SAndreas Gohr     * @return  bool
357e1d9dcc8SAndreas Gohr     */
358e1d9dcc8SAndreas Gohr    public function addGroup($group)
359e1d9dcc8SAndreas Gohr    {
360e1d9dcc8SAndreas Gohr        msg("authorisation method does not support independent group creation", -1);
361e1d9dcc8SAndreas Gohr        return false;
362e1d9dcc8SAndreas Gohr    }
363e1d9dcc8SAndreas Gohr
364e1d9dcc8SAndreas Gohr    /**
365e1d9dcc8SAndreas Gohr     * Retrieve groups [implement only where required/possible]
366e1d9dcc8SAndreas Gohr     *
367e1d9dcc8SAndreas Gohr     * Set getGroups capability when implemented
368e1d9dcc8SAndreas Gohr     *
369e1d9dcc8SAndreas Gohr     * @author  Chris Smith <chris@jalakai.co.uk>
370e1d9dcc8SAndreas Gohr     * @param   int $start
371e1d9dcc8SAndreas Gohr     * @param   int $limit
372e1d9dcc8SAndreas Gohr     * @return  array
373e1d9dcc8SAndreas Gohr     */
374e1d9dcc8SAndreas Gohr    public function retrieveGroups($start = 0, $limit = 0)
375e1d9dcc8SAndreas Gohr    {
376e1d9dcc8SAndreas Gohr        msg("authorisation method does not support group list retrieval", -1);
377e1d9dcc8SAndreas Gohr        return array();
378e1d9dcc8SAndreas Gohr    }
379e1d9dcc8SAndreas Gohr
380e1d9dcc8SAndreas Gohr    /**
381e1d9dcc8SAndreas Gohr     * Return case sensitivity of the backend [OPTIONAL]
382e1d9dcc8SAndreas Gohr     *
383e1d9dcc8SAndreas Gohr     * When your backend is caseinsensitive (eg. you can login with USER and
384e1d9dcc8SAndreas Gohr     * user) then you need to overwrite this method and return false
385e1d9dcc8SAndreas Gohr     *
386e1d9dcc8SAndreas Gohr     * @return bool
387e1d9dcc8SAndreas Gohr     */
388e1d9dcc8SAndreas Gohr    public function isCaseSensitive()
389e1d9dcc8SAndreas Gohr    {
390e1d9dcc8SAndreas Gohr        return true;
391e1d9dcc8SAndreas Gohr    }
392e1d9dcc8SAndreas Gohr
393e1d9dcc8SAndreas Gohr    /**
394e1d9dcc8SAndreas Gohr     * Sanitize a given username [OPTIONAL]
395e1d9dcc8SAndreas Gohr     *
396e1d9dcc8SAndreas Gohr     * This function is applied to any user name that is given to
397e1d9dcc8SAndreas Gohr     * the backend and should also be applied to any user name within
398e1d9dcc8SAndreas Gohr     * the backend before returning it somewhere.
399e1d9dcc8SAndreas Gohr     *
400e1d9dcc8SAndreas Gohr     * This should be used to enforce username restrictions.
401e1d9dcc8SAndreas Gohr     *
402e1d9dcc8SAndreas Gohr     * @author Andreas Gohr <andi@splitbrain.org>
403e1d9dcc8SAndreas Gohr     * @param string $user username
404e1d9dcc8SAndreas Gohr     * @return string the cleaned username
405e1d9dcc8SAndreas Gohr     */
406e1d9dcc8SAndreas Gohr    public function cleanUser($user)
407e1d9dcc8SAndreas Gohr    {
408e1d9dcc8SAndreas Gohr        return $user;
409e1d9dcc8SAndreas Gohr    }
410e1d9dcc8SAndreas Gohr
411e1d9dcc8SAndreas Gohr    /**
412e1d9dcc8SAndreas Gohr     * Sanitize a given groupname [OPTIONAL]
413e1d9dcc8SAndreas Gohr     *
414e1d9dcc8SAndreas Gohr     * This function is applied to any groupname that is given to
415e1d9dcc8SAndreas Gohr     * the backend and should also be applied to any groupname within
416e1d9dcc8SAndreas Gohr     * the backend before returning it somewhere.
417e1d9dcc8SAndreas Gohr     *
418e1d9dcc8SAndreas Gohr     * This should be used to enforce groupname restrictions.
419e1d9dcc8SAndreas Gohr     *
420e1d9dcc8SAndreas Gohr     * Groupnames are to be passed without a leading '@' here.
421e1d9dcc8SAndreas Gohr     *
422e1d9dcc8SAndreas Gohr     * @author Andreas Gohr <andi@splitbrain.org>
423e1d9dcc8SAndreas Gohr     * @param  string $group groupname
424e1d9dcc8SAndreas Gohr     * @return string the cleaned groupname
425e1d9dcc8SAndreas Gohr     */
426e1d9dcc8SAndreas Gohr    public function cleanGroup($group)
427e1d9dcc8SAndreas Gohr    {
428e1d9dcc8SAndreas Gohr        return $group;
429e1d9dcc8SAndreas Gohr    }
430e1d9dcc8SAndreas Gohr
431e1d9dcc8SAndreas Gohr    /**
432e1d9dcc8SAndreas Gohr     * Check Session Cache validity [implement only where required/possible]
433e1d9dcc8SAndreas Gohr     *
434e1d9dcc8SAndreas Gohr     * DokuWiki caches user info in the user's session for the timespan defined
435e1d9dcc8SAndreas Gohr     * in $conf['auth_security_timeout'].
436e1d9dcc8SAndreas Gohr     *
437e1d9dcc8SAndreas Gohr     * This makes sure slow authentication backends do not slow down DokuWiki.
438e1d9dcc8SAndreas Gohr     * This also means that changes to the user database will not be reflected
439e1d9dcc8SAndreas Gohr     * on currently logged in users.
440e1d9dcc8SAndreas Gohr     *
441e1d9dcc8SAndreas Gohr     * To accommodate for this, the user manager plugin will touch a reference
442e1d9dcc8SAndreas Gohr     * file whenever a change is submitted. This function compares the filetime
443e1d9dcc8SAndreas Gohr     * of this reference file with the time stored in the session.
444e1d9dcc8SAndreas Gohr     *
445e1d9dcc8SAndreas Gohr     * This reference file mechanism does not reflect changes done directly in
446e1d9dcc8SAndreas Gohr     * the backend's database through other means than the user manager plugin.
447e1d9dcc8SAndreas Gohr     *
448e1d9dcc8SAndreas Gohr     * Fast backends might want to return always false, to force rechecks on
449e1d9dcc8SAndreas Gohr     * each page load. Others might want to use their own checking here. If
450e1d9dcc8SAndreas Gohr     * unsure, do not override.
451e1d9dcc8SAndreas Gohr     *
452e1d9dcc8SAndreas Gohr     * @param  string $user - The username
453e1d9dcc8SAndreas Gohr     * @author Andreas Gohr <andi@splitbrain.org>
454e1d9dcc8SAndreas Gohr     * @return bool
455e1d9dcc8SAndreas Gohr     */
456e1d9dcc8SAndreas Gohr    public function useSessionCache($user)
457e1d9dcc8SAndreas Gohr    {
458e1d9dcc8SAndreas Gohr        global $conf;
459e1d9dcc8SAndreas Gohr        return ($_SESSION[DOKU_COOKIE]['auth']['time'] >= @filemtime($conf['cachedir'] . '/sessionpurge'));
460e1d9dcc8SAndreas Gohr    }
461e1d9dcc8SAndreas Gohr}
462