1*79f39653SAndreas Gohr<?php 2*79f39653SAndreas Gohr/** 3*79f39653SAndreas Gohr * DokuWiki Plugin pureldap (Auth Component) 4*79f39653SAndreas Gohr * 5*79f39653SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6*79f39653SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 7*79f39653SAndreas Gohr */ 8*79f39653SAndreas Gohr 9*79f39653SAndreas Gohr// must be run within Dokuwiki 10*79f39653SAndreas Gohrif (!defined('DOKU_INC')) { 11*79f39653SAndreas Gohr die(); 12*79f39653SAndreas Gohr} 13*79f39653SAndreas Gohr 14*79f39653SAndreas Gohrclass auth_plugin_pureldap extends DokuWiki_Auth_Plugin 15*79f39653SAndreas Gohr{ 16*79f39653SAndreas Gohr 17*79f39653SAndreas Gohr 18*79f39653SAndreas Gohr /** 19*79f39653SAndreas Gohr * Constructor. 20*79f39653SAndreas Gohr */ 21*79f39653SAndreas Gohr public function __construct() 22*79f39653SAndreas Gohr { 23*79f39653SAndreas Gohr parent::__construct(); // for compatibility 24*79f39653SAndreas Gohr 25*79f39653SAndreas Gohr // FIXME set capabilities accordingly 26*79f39653SAndreas Gohr //$this->cando['addUser'] = false; // can Users be created? 27*79f39653SAndreas Gohr //$this->cando['delUser'] = false; // can Users be deleted? 28*79f39653SAndreas Gohr //$this->cando['modLogin'] = false; // can login names be changed? 29*79f39653SAndreas Gohr //$this->cando['modPass'] = false; // can passwords be changed? 30*79f39653SAndreas Gohr //$this->cando['modName'] = false; // can real names be changed? 31*79f39653SAndreas Gohr //$this->cando['modMail'] = false; // can emails be changed? 32*79f39653SAndreas Gohr //$this->cando['modGroups'] = false; // can groups be changed? 33*79f39653SAndreas Gohr //$this->cando['getUsers'] = false; // can a (filtered) list of users be retrieved? 34*79f39653SAndreas Gohr //$this->cando['getUserCount']= false; // can the number of users be retrieved? 35*79f39653SAndreas Gohr //$this->cando['getGroups'] = false; // can a list of available groups be retrieved? 36*79f39653SAndreas Gohr //$this->cando['external'] = false; // does the module do external auth checking? 37*79f39653SAndreas Gohr //$this->cando['logout'] = true; // can the user logout again? (eg. not possible with HTTP auth) 38*79f39653SAndreas Gohr 39*79f39653SAndreas Gohr // FIXME intialize your auth system and set success to true, if successful 40*79f39653SAndreas Gohr $this->success = true; 41*79f39653SAndreas Gohr } 42*79f39653SAndreas Gohr 43*79f39653SAndreas Gohr 44*79f39653SAndreas Gohr /** 45*79f39653SAndreas Gohr * Log off the current user [ OPTIONAL ] 46*79f39653SAndreas Gohr */ 47*79f39653SAndreas Gohr // public function logOff() 48*79f39653SAndreas Gohr // { 49*79f39653SAndreas Gohr // } 50*79f39653SAndreas Gohr 51*79f39653SAndreas Gohr /** 52*79f39653SAndreas Gohr * Do all authentication [ OPTIONAL ] 53*79f39653SAndreas Gohr * 54*79f39653SAndreas Gohr * @param string $user Username 55*79f39653SAndreas Gohr * @param string $pass Cleartext Password 56*79f39653SAndreas Gohr * @param bool $sticky Cookie should not expire 57*79f39653SAndreas Gohr * 58*79f39653SAndreas Gohr * @return bool true on successful auth 59*79f39653SAndreas Gohr */ 60*79f39653SAndreas Gohr //public function trustExternal($user, $pass, $sticky = false) 61*79f39653SAndreas Gohr //{ 62*79f39653SAndreas Gohr /* some example: 63*79f39653SAndreas Gohr 64*79f39653SAndreas Gohr global $USERINFO; 65*79f39653SAndreas Gohr global $conf; 66*79f39653SAndreas Gohr $sticky ? $sticky = true : $sticky = false; //sanity check 67*79f39653SAndreas Gohr 68*79f39653SAndreas Gohr // do the checking here 69*79f39653SAndreas Gohr 70*79f39653SAndreas Gohr // set the globals if authed 71*79f39653SAndreas Gohr $USERINFO['name'] = 'FIXME'; 72*79f39653SAndreas Gohr $USERINFO['mail'] = 'FIXME'; 73*79f39653SAndreas Gohr $USERINFO['grps'] = array('FIXME'); 74*79f39653SAndreas Gohr $_SERVER['REMOTE_USER'] = $user; 75*79f39653SAndreas Gohr $_SESSION[DOKU_COOKIE]['auth']['user'] = $user; 76*79f39653SAndreas Gohr $_SESSION[DOKU_COOKIE]['auth']['pass'] = $pass; 77*79f39653SAndreas Gohr $_SESSION[DOKU_COOKIE]['auth']['info'] = $USERINFO; 78*79f39653SAndreas Gohr return true; 79*79f39653SAndreas Gohr 80*79f39653SAndreas Gohr */ 81*79f39653SAndreas Gohr //} 82*79f39653SAndreas Gohr 83*79f39653SAndreas Gohr /** 84*79f39653SAndreas Gohr * Check user+password 85*79f39653SAndreas Gohr * 86*79f39653SAndreas Gohr * May be ommited if trustExternal is used. 87*79f39653SAndreas Gohr * 88*79f39653SAndreas Gohr * @param string $user the user name 89*79f39653SAndreas Gohr * @param string $pass the clear text password 90*79f39653SAndreas Gohr * 91*79f39653SAndreas Gohr * @return bool 92*79f39653SAndreas Gohr */ 93*79f39653SAndreas Gohr public function checkPass($user, $pass) 94*79f39653SAndreas Gohr { 95*79f39653SAndreas Gohr // FIXME implement password check 96*79f39653SAndreas Gohr return false; // return true if okay 97*79f39653SAndreas Gohr } 98*79f39653SAndreas Gohr 99*79f39653SAndreas Gohr /** 100*79f39653SAndreas Gohr * Return user info 101*79f39653SAndreas Gohr * 102*79f39653SAndreas Gohr * Returns info about the given user needs to contain 103*79f39653SAndreas Gohr * at least these fields: 104*79f39653SAndreas Gohr * 105*79f39653SAndreas Gohr * name string full name of the user 106*79f39653SAndreas Gohr * mail string email addres of the user 107*79f39653SAndreas Gohr * grps array list of groups the user is in 108*79f39653SAndreas Gohr * 109*79f39653SAndreas Gohr * @param string $user the user name 110*79f39653SAndreas Gohr * @param bool $requireGroups whether or not the returned data must include groups 111*79f39653SAndreas Gohr * 112*79f39653SAndreas Gohr * @return array containing user data or false 113*79f39653SAndreas Gohr */ 114*79f39653SAndreas Gohr public function getUserData($user, $requireGroups=true) 115*79f39653SAndreas Gohr { 116*79f39653SAndreas Gohr // FIXME implement 117*79f39653SAndreas Gohr return false; 118*79f39653SAndreas Gohr } 119*79f39653SAndreas Gohr 120*79f39653SAndreas Gohr /** 121*79f39653SAndreas Gohr * Create a new User [implement only where required/possible] 122*79f39653SAndreas Gohr * 123*79f39653SAndreas Gohr * Returns false if the user already exists, null when an error 124*79f39653SAndreas Gohr * occurred and true if everything went well. 125*79f39653SAndreas Gohr * 126*79f39653SAndreas Gohr * The new user HAS TO be added to the default group by this 127*79f39653SAndreas Gohr * function! 128*79f39653SAndreas Gohr * 129*79f39653SAndreas Gohr * Set addUser capability when implemented 130*79f39653SAndreas Gohr * 131*79f39653SAndreas Gohr * @param string $user 132*79f39653SAndreas Gohr * @param string $pass 133*79f39653SAndreas Gohr * @param string $name 134*79f39653SAndreas Gohr * @param string $mail 135*79f39653SAndreas Gohr * @param null|array $grps 136*79f39653SAndreas Gohr * 137*79f39653SAndreas Gohr * @return bool|null 138*79f39653SAndreas Gohr */ 139*79f39653SAndreas Gohr //public function createUser($user, $pass, $name, $mail, $grps = null) 140*79f39653SAndreas Gohr //{ 141*79f39653SAndreas Gohr // FIXME implement 142*79f39653SAndreas Gohr // return null; 143*79f39653SAndreas Gohr //} 144*79f39653SAndreas Gohr 145*79f39653SAndreas Gohr /** 146*79f39653SAndreas Gohr * Modify user data [implement only where required/possible] 147*79f39653SAndreas Gohr * 148*79f39653SAndreas Gohr * Set the mod* capabilities according to the implemented features 149*79f39653SAndreas Gohr * 150*79f39653SAndreas Gohr * @param string $user nick of the user to be changed 151*79f39653SAndreas Gohr * @param array $changes array of field/value pairs to be changed (password will be clear text) 152*79f39653SAndreas Gohr * 153*79f39653SAndreas Gohr * @return bool 154*79f39653SAndreas Gohr */ 155*79f39653SAndreas Gohr //public function modifyUser($user, $changes) 156*79f39653SAndreas Gohr //{ 157*79f39653SAndreas Gohr // FIXME implement 158*79f39653SAndreas Gohr // return false; 159*79f39653SAndreas Gohr //} 160*79f39653SAndreas Gohr 161*79f39653SAndreas Gohr /** 162*79f39653SAndreas Gohr * Delete one or more users [implement only where required/possible] 163*79f39653SAndreas Gohr * 164*79f39653SAndreas Gohr * Set delUser capability when implemented 165*79f39653SAndreas Gohr * 166*79f39653SAndreas Gohr * @param array $users 167*79f39653SAndreas Gohr * 168*79f39653SAndreas Gohr * @return int number of users deleted 169*79f39653SAndreas Gohr */ 170*79f39653SAndreas Gohr //public function deleteUsers($users) 171*79f39653SAndreas Gohr //{ 172*79f39653SAndreas Gohr // FIXME implement 173*79f39653SAndreas Gohr // return false; 174*79f39653SAndreas Gohr //} 175*79f39653SAndreas Gohr 176*79f39653SAndreas Gohr /** 177*79f39653SAndreas Gohr * Bulk retrieval of user data [implement only where required/possible] 178*79f39653SAndreas Gohr * 179*79f39653SAndreas Gohr * Set getUsers capability when implemented 180*79f39653SAndreas Gohr * 181*79f39653SAndreas Gohr * @param int $start index of first user to be returned 182*79f39653SAndreas Gohr * @param int $limit max number of users to be returned, 0 for unlimited 183*79f39653SAndreas Gohr * @param array $filter array of field/pattern pairs, null for no filter 184*79f39653SAndreas Gohr * 185*79f39653SAndreas Gohr * @return array list of userinfo (refer getUserData for internal userinfo details) 186*79f39653SAndreas Gohr */ 187*79f39653SAndreas Gohr //public function retrieveUsers($start = 0, $limit = 0, $filter = null) 188*79f39653SAndreas Gohr //{ 189*79f39653SAndreas Gohr // FIXME implement 190*79f39653SAndreas Gohr // return array(); 191*79f39653SAndreas Gohr //} 192*79f39653SAndreas Gohr 193*79f39653SAndreas Gohr /** 194*79f39653SAndreas Gohr * Return a count of the number of user which meet $filter criteria 195*79f39653SAndreas Gohr * [should be implemented whenever retrieveUsers is implemented] 196*79f39653SAndreas Gohr * 197*79f39653SAndreas Gohr * Set getUserCount capability when implemented 198*79f39653SAndreas Gohr * 199*79f39653SAndreas Gohr * @param array $filter array of field/pattern pairs, empty array for no filter 200*79f39653SAndreas Gohr * 201*79f39653SAndreas Gohr * @return int 202*79f39653SAndreas Gohr */ 203*79f39653SAndreas Gohr //public function getUserCount($filter = array()) 204*79f39653SAndreas Gohr //{ 205*79f39653SAndreas Gohr // FIXME implement 206*79f39653SAndreas Gohr // return 0; 207*79f39653SAndreas Gohr //} 208*79f39653SAndreas Gohr 209*79f39653SAndreas Gohr /** 210*79f39653SAndreas Gohr * Define a group [implement only where required/possible] 211*79f39653SAndreas Gohr * 212*79f39653SAndreas Gohr * Set addGroup capability when implemented 213*79f39653SAndreas Gohr * 214*79f39653SAndreas Gohr * @param string $group 215*79f39653SAndreas Gohr * 216*79f39653SAndreas Gohr * @return bool 217*79f39653SAndreas Gohr */ 218*79f39653SAndreas Gohr //public function addGroup($group) 219*79f39653SAndreas Gohr //{ 220*79f39653SAndreas Gohr // FIXME implement 221*79f39653SAndreas Gohr // return false; 222*79f39653SAndreas Gohr //} 223*79f39653SAndreas Gohr 224*79f39653SAndreas Gohr /** 225*79f39653SAndreas Gohr * Retrieve groups [implement only where required/possible] 226*79f39653SAndreas Gohr * 227*79f39653SAndreas Gohr * Set getGroups capability when implemented 228*79f39653SAndreas Gohr * 229*79f39653SAndreas Gohr * @param int $start 230*79f39653SAndreas Gohr * @param int $limit 231*79f39653SAndreas Gohr * 232*79f39653SAndreas Gohr * @return array 233*79f39653SAndreas Gohr */ 234*79f39653SAndreas Gohr //public function retrieveGroups($start = 0, $limit = 0) 235*79f39653SAndreas Gohr //{ 236*79f39653SAndreas Gohr // FIXME implement 237*79f39653SAndreas Gohr // return array(); 238*79f39653SAndreas Gohr //} 239*79f39653SAndreas Gohr 240*79f39653SAndreas Gohr /** 241*79f39653SAndreas Gohr * Return case sensitivity of the backend 242*79f39653SAndreas Gohr * 243*79f39653SAndreas Gohr * When your backend is caseinsensitive (eg. you can login with USER and 244*79f39653SAndreas Gohr * user) then you need to overwrite this method and return false 245*79f39653SAndreas Gohr * 246*79f39653SAndreas Gohr * @return bool 247*79f39653SAndreas Gohr */ 248*79f39653SAndreas Gohr public function isCaseSensitive() 249*79f39653SAndreas Gohr { 250*79f39653SAndreas Gohr return true; 251*79f39653SAndreas Gohr } 252*79f39653SAndreas Gohr 253*79f39653SAndreas Gohr /** 254*79f39653SAndreas Gohr * Sanitize a given username 255*79f39653SAndreas Gohr * 256*79f39653SAndreas Gohr * This function is applied to any user name that is given to 257*79f39653SAndreas Gohr * the backend and should also be applied to any user name within 258*79f39653SAndreas Gohr * the backend before returning it somewhere. 259*79f39653SAndreas Gohr * 260*79f39653SAndreas Gohr * This should be used to enforce username restrictions. 261*79f39653SAndreas Gohr * 262*79f39653SAndreas Gohr * @param string $user username 263*79f39653SAndreas Gohr * @return string the cleaned username 264*79f39653SAndreas Gohr */ 265*79f39653SAndreas Gohr public function cleanUser($user) 266*79f39653SAndreas Gohr { 267*79f39653SAndreas Gohr return $user; 268*79f39653SAndreas Gohr } 269*79f39653SAndreas Gohr 270*79f39653SAndreas Gohr /** 271*79f39653SAndreas Gohr * Sanitize a given groupname 272*79f39653SAndreas Gohr * 273*79f39653SAndreas Gohr * This function is applied to any groupname that is given to 274*79f39653SAndreas Gohr * the backend and should also be applied to any groupname within 275*79f39653SAndreas Gohr * the backend before returning it somewhere. 276*79f39653SAndreas Gohr * 277*79f39653SAndreas Gohr * This should be used to enforce groupname restrictions. 278*79f39653SAndreas Gohr * 279*79f39653SAndreas Gohr * Groupnames are to be passed without a leading '@' here. 280*79f39653SAndreas Gohr * 281*79f39653SAndreas Gohr * @param string $group groupname 282*79f39653SAndreas Gohr * 283*79f39653SAndreas Gohr * @return string the cleaned groupname 284*79f39653SAndreas Gohr */ 285*79f39653SAndreas Gohr public function cleanGroup($group) 286*79f39653SAndreas Gohr { 287*79f39653SAndreas Gohr return $group; 288*79f39653SAndreas Gohr } 289*79f39653SAndreas Gohr 290*79f39653SAndreas Gohr /** 291*79f39653SAndreas Gohr * Check Session Cache validity [implement only where required/possible] 292*79f39653SAndreas Gohr * 293*79f39653SAndreas Gohr * DokuWiki caches user info in the user's session for the timespan defined 294*79f39653SAndreas Gohr * in $conf['auth_security_timeout']. 295*79f39653SAndreas Gohr * 296*79f39653SAndreas Gohr * This makes sure slow authentication backends do not slow down DokuWiki. 297*79f39653SAndreas Gohr * This also means that changes to the user database will not be reflected 298*79f39653SAndreas Gohr * on currently logged in users. 299*79f39653SAndreas Gohr * 300*79f39653SAndreas Gohr * To accommodate for this, the user manager plugin will touch a reference 301*79f39653SAndreas Gohr * file whenever a change is submitted. This function compares the filetime 302*79f39653SAndreas Gohr * of this reference file with the time stored in the session. 303*79f39653SAndreas Gohr * 304*79f39653SAndreas Gohr * This reference file mechanism does not reflect changes done directly in 305*79f39653SAndreas Gohr * the backend's database through other means than the user manager plugin. 306*79f39653SAndreas Gohr * 307*79f39653SAndreas Gohr * Fast backends might want to return always false, to force rechecks on 308*79f39653SAndreas Gohr * each page load. Others might want to use their own checking here. If 309*79f39653SAndreas Gohr * unsure, do not override. 310*79f39653SAndreas Gohr * 311*79f39653SAndreas Gohr * @param string $user - The username 312*79f39653SAndreas Gohr * 313*79f39653SAndreas Gohr * @return bool 314*79f39653SAndreas Gohr */ 315*79f39653SAndreas Gohr //public function useSessionCache($user) 316*79f39653SAndreas Gohr //{ 317*79f39653SAndreas Gohr // FIXME implement 318*79f39653SAndreas Gohr //} 319*79f39653SAndreas Gohr} 320*79f39653SAndreas Gohr 321