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