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