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