179f39653SAndreas Gohr<?php 2*1078ec26SAndreas Gohr 3*1078ec26SAndreas Gohruse dokuwiki\plugin\pureldap\classes\ADClient; 4*1078ec26SAndreas Gohruse dokuwiki\plugin\pureldap\classes\Client; 5*1078ec26SAndreas Gohr 679f39653SAndreas Gohr/** 779f39653SAndreas Gohr * DokuWiki Plugin pureldap (Auth Component) 879f39653SAndreas Gohr * 979f39653SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 1079f39653SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1179f39653SAndreas Gohr */ 1279f39653SAndreas Gohrclass auth_plugin_pureldap extends DokuWiki_Auth_Plugin 1379f39653SAndreas Gohr{ 14*1078ec26SAndreas Gohr /** @var Client */ 15*1078ec26SAndreas Gohr protected $client; 1679f39653SAndreas Gohr 1779f39653SAndreas Gohr /** 1879f39653SAndreas Gohr * Constructor. 1979f39653SAndreas Gohr */ 2079f39653SAndreas Gohr public function __construct() 2179f39653SAndreas Gohr { 22*1078ec26SAndreas Gohr global $conf; 2379f39653SAndreas Gohr parent::__construct(); // for compatibility 2479f39653SAndreas Gohr 2579f39653SAndreas Gohr // FIXME set capabilities accordingly 2679f39653SAndreas Gohr //$this->cando['addUser'] = false; // can Users be created? 2779f39653SAndreas Gohr //$this->cando['delUser'] = false; // can Users be deleted? 2879f39653SAndreas Gohr //$this->cando['modLogin'] = false; // can login names be changed? 2979f39653SAndreas Gohr //$this->cando['modPass'] = false; // can passwords be changed? 3079f39653SAndreas Gohr //$this->cando['modName'] = false; // can real names be changed? 3179f39653SAndreas Gohr //$this->cando['modMail'] = false; // can emails be changed? 3279f39653SAndreas Gohr //$this->cando['modGroups'] = false; // can groups be changed? 3379f39653SAndreas Gohr //$this->cando['getUsers'] = false; // can a (filtered) list of users be retrieved? 3479f39653SAndreas Gohr //$this->cando['getUserCount']= false; // can the number of users be retrieved? 3579f39653SAndreas Gohr //$this->cando['getGroups'] = false; // can a list of available groups be retrieved? 3679f39653SAndreas Gohr //$this->cando['external'] = false; // does the module do external auth checking? 3779f39653SAndreas Gohr //$this->cando['logout'] = true; // can the user logout again? (eg. not possible with HTTP auth) 3879f39653SAndreas Gohr 39*1078ec26SAndreas Gohr // prepare the base client 40*1078ec26SAndreas Gohr $this->loadConfig(); 41*1078ec26SAndreas Gohr $this->conf['admin_password'] = conf_decodeString($this->conf['admin_password']); 42*1078ec26SAndreas Gohr $this->conf['defaultgroup'] = $conf['defaultgroup']; 43*1078ec26SAndreas Gohr 44*1078ec26SAndreas Gohr $this->client = new ADClient($this->conf); // FIXME decide class on config 4579f39653SAndreas Gohr $this->success = true; 4679f39653SAndreas Gohr } 4779f39653SAndreas Gohr 4879f39653SAndreas Gohr 4979f39653SAndreas Gohr /** 5079f39653SAndreas Gohr * Log off the current user [ OPTIONAL ] 5179f39653SAndreas Gohr */ 5279f39653SAndreas Gohr // public function logOff() 5379f39653SAndreas Gohr // { 5479f39653SAndreas Gohr // } 5579f39653SAndreas Gohr 5679f39653SAndreas Gohr /** 5779f39653SAndreas Gohr * Do all authentication [ OPTIONAL ] 5879f39653SAndreas Gohr * 5979f39653SAndreas Gohr * @param string $user Username 6079f39653SAndreas Gohr * @param string $pass Cleartext Password 6179f39653SAndreas Gohr * @param bool $sticky Cookie should not expire 6279f39653SAndreas Gohr * 6379f39653SAndreas Gohr * @return bool true on successful auth 6479f39653SAndreas Gohr */ 6579f39653SAndreas Gohr //public function trustExternal($user, $pass, $sticky = false) 6679f39653SAndreas Gohr //{ 6779f39653SAndreas Gohr /* some example: 6879f39653SAndreas Gohr 6979f39653SAndreas Gohr global $USERINFO; 7079f39653SAndreas Gohr global $conf; 7179f39653SAndreas Gohr $sticky ? $sticky = true : $sticky = false; //sanity check 7279f39653SAndreas Gohr 7379f39653SAndreas Gohr // do the checking here 7479f39653SAndreas Gohr 7579f39653SAndreas Gohr // set the globals if authed 7679f39653SAndreas Gohr $USERINFO['name'] = 'FIXME'; 7779f39653SAndreas Gohr $USERINFO['mail'] = 'FIXME'; 7879f39653SAndreas Gohr $USERINFO['grps'] = array('FIXME'); 7979f39653SAndreas Gohr $_SERVER['REMOTE_USER'] = $user; 8079f39653SAndreas Gohr $_SESSION[DOKU_COOKIE]['auth']['user'] = $user; 8179f39653SAndreas Gohr $_SESSION[DOKU_COOKIE]['auth']['pass'] = $pass; 8279f39653SAndreas Gohr $_SESSION[DOKU_COOKIE]['auth']['info'] = $USERINFO; 8379f39653SAndreas Gohr return true; 8479f39653SAndreas Gohr 8579f39653SAndreas Gohr */ 8679f39653SAndreas Gohr //} 8779f39653SAndreas Gohr 88*1078ec26SAndreas Gohr /** @inheritDoc */ 8979f39653SAndreas Gohr public function checkPass($user, $pass) 9079f39653SAndreas Gohr { 91*1078ec26SAndreas Gohr // use a separate client from the default one, because this is not a superuser bind 92*1078ec26SAndreas Gohr $client = new ADClient($this->conf); // FIXME decide class on config 93*1078ec26SAndreas Gohr return $client->authenticate($user, $pass); 9479f39653SAndreas Gohr } 9579f39653SAndreas Gohr 96*1078ec26SAndreas Gohr /** @inheritDoc */ 9779f39653SAndreas Gohr public function getUserData($user, $requireGroups = true) 9879f39653SAndreas Gohr { 99*1078ec26SAndreas Gohr $info = $this->client->getUser($user); 100*1078ec26SAndreas Gohr return $info ?: false; 10179f39653SAndreas Gohr } 10279f39653SAndreas Gohr 10379f39653SAndreas Gohr /** 10479f39653SAndreas Gohr * Create a new User [implement only where required/possible] 10579f39653SAndreas Gohr * 10679f39653SAndreas Gohr * Returns false if the user already exists, null when an error 10779f39653SAndreas Gohr * occurred and true if everything went well. 10879f39653SAndreas Gohr * 10979f39653SAndreas Gohr * The new user HAS TO be added to the default group by this 11079f39653SAndreas Gohr * function! 11179f39653SAndreas Gohr * 11279f39653SAndreas Gohr * Set addUser capability when implemented 11379f39653SAndreas Gohr * 11479f39653SAndreas Gohr * @param string $user 11579f39653SAndreas Gohr * @param string $pass 11679f39653SAndreas Gohr * @param string $name 11779f39653SAndreas Gohr * @param string $mail 11879f39653SAndreas Gohr * @param null|array $grps 11979f39653SAndreas Gohr * 12079f39653SAndreas Gohr * @return bool|null 12179f39653SAndreas Gohr */ 12279f39653SAndreas Gohr //public function createUser($user, $pass, $name, $mail, $grps = null) 12379f39653SAndreas Gohr //{ 12479f39653SAndreas Gohr // FIXME implement 12579f39653SAndreas Gohr // return null; 12679f39653SAndreas Gohr //} 12779f39653SAndreas Gohr 12879f39653SAndreas Gohr /** 12979f39653SAndreas Gohr * Modify user data [implement only where required/possible] 13079f39653SAndreas Gohr * 13179f39653SAndreas Gohr * Set the mod* capabilities according to the implemented features 13279f39653SAndreas Gohr * 13379f39653SAndreas Gohr * @param string $user nick of the user to be changed 13479f39653SAndreas Gohr * @param array $changes array of field/value pairs to be changed (password will be clear text) 13579f39653SAndreas Gohr * 13679f39653SAndreas Gohr * @return bool 13779f39653SAndreas Gohr */ 13879f39653SAndreas Gohr //public function modifyUser($user, $changes) 13979f39653SAndreas Gohr //{ 14079f39653SAndreas Gohr // FIXME implement 14179f39653SAndreas Gohr // return false; 14279f39653SAndreas Gohr //} 14379f39653SAndreas Gohr 14479f39653SAndreas Gohr /** 14579f39653SAndreas Gohr * Delete one or more users [implement only where required/possible] 14679f39653SAndreas Gohr * 14779f39653SAndreas Gohr * Set delUser capability when implemented 14879f39653SAndreas Gohr * 14979f39653SAndreas Gohr * @param array $users 15079f39653SAndreas Gohr * 15179f39653SAndreas Gohr * @return int number of users deleted 15279f39653SAndreas Gohr */ 15379f39653SAndreas Gohr //public function deleteUsers($users) 15479f39653SAndreas Gohr //{ 15579f39653SAndreas Gohr // FIXME implement 15679f39653SAndreas Gohr // return false; 15779f39653SAndreas Gohr //} 15879f39653SAndreas Gohr 15979f39653SAndreas Gohr /** 16079f39653SAndreas Gohr * Bulk retrieval of user data [implement only where required/possible] 16179f39653SAndreas Gohr * 16279f39653SAndreas Gohr * Set getUsers capability when implemented 16379f39653SAndreas Gohr * 16479f39653SAndreas Gohr * @param int $start index of first user to be returned 16579f39653SAndreas Gohr * @param int $limit max number of users to be returned, 0 for unlimited 16679f39653SAndreas Gohr * @param array $filter array of field/pattern pairs, null for no filter 16779f39653SAndreas Gohr * 16879f39653SAndreas Gohr * @return array list of userinfo (refer getUserData for internal userinfo details) 16979f39653SAndreas Gohr */ 17079f39653SAndreas Gohr //public function retrieveUsers($start = 0, $limit = 0, $filter = null) 17179f39653SAndreas Gohr //{ 17279f39653SAndreas Gohr // FIXME implement 17379f39653SAndreas Gohr // return array(); 17479f39653SAndreas Gohr //} 17579f39653SAndreas Gohr 17679f39653SAndreas Gohr /** 17779f39653SAndreas Gohr * Return a count of the number of user which meet $filter criteria 17879f39653SAndreas Gohr * [should be implemented whenever retrieveUsers is implemented] 17979f39653SAndreas Gohr * 18079f39653SAndreas Gohr * Set getUserCount capability when implemented 18179f39653SAndreas Gohr * 18279f39653SAndreas Gohr * @param array $filter array of field/pattern pairs, empty array for no filter 18379f39653SAndreas Gohr * 18479f39653SAndreas Gohr * @return int 18579f39653SAndreas Gohr */ 18679f39653SAndreas Gohr //public function getUserCount($filter = array()) 18779f39653SAndreas Gohr //{ 18879f39653SAndreas Gohr // FIXME implement 18979f39653SAndreas Gohr // return 0; 19079f39653SAndreas Gohr //} 19179f39653SAndreas Gohr 19279f39653SAndreas Gohr /** 19379f39653SAndreas Gohr * Define a group [implement only where required/possible] 19479f39653SAndreas Gohr * 19579f39653SAndreas Gohr * Set addGroup capability when implemented 19679f39653SAndreas Gohr * 19779f39653SAndreas Gohr * @param string $group 19879f39653SAndreas Gohr * 19979f39653SAndreas Gohr * @return bool 20079f39653SAndreas Gohr */ 20179f39653SAndreas Gohr //public function addGroup($group) 20279f39653SAndreas Gohr //{ 20379f39653SAndreas Gohr // FIXME implement 20479f39653SAndreas Gohr // return false; 20579f39653SAndreas Gohr //} 20679f39653SAndreas Gohr 20779f39653SAndreas Gohr /** 20879f39653SAndreas Gohr * Retrieve groups [implement only where required/possible] 20979f39653SAndreas Gohr * 21079f39653SAndreas Gohr * Set getGroups capability when implemented 21179f39653SAndreas Gohr * 21279f39653SAndreas Gohr * @param int $start 21379f39653SAndreas Gohr * @param int $limit 21479f39653SAndreas Gohr * 21579f39653SAndreas Gohr * @return array 21679f39653SAndreas Gohr */ 21779f39653SAndreas Gohr //public function retrieveGroups($start = 0, $limit = 0) 21879f39653SAndreas Gohr //{ 21979f39653SAndreas Gohr // FIXME implement 22079f39653SAndreas Gohr // return array(); 22179f39653SAndreas Gohr //} 22279f39653SAndreas Gohr 22379f39653SAndreas Gohr /** 22479f39653SAndreas Gohr * Return case sensitivity of the backend 22579f39653SAndreas Gohr * 22679f39653SAndreas Gohr * When your backend is caseinsensitive (eg. you can login with USER and 22779f39653SAndreas Gohr * user) then you need to overwrite this method and return false 22879f39653SAndreas Gohr * 22979f39653SAndreas Gohr * @return bool 23079f39653SAndreas Gohr */ 23179f39653SAndreas Gohr public function isCaseSensitive() 23279f39653SAndreas Gohr { 23379f39653SAndreas Gohr return true; 23479f39653SAndreas Gohr } 23579f39653SAndreas Gohr 23679f39653SAndreas Gohr /** 23779f39653SAndreas Gohr * Sanitize a given username 23879f39653SAndreas Gohr * 23979f39653SAndreas Gohr * This function is applied to any user name that is given to 24079f39653SAndreas Gohr * the backend and should also be applied to any user name within 24179f39653SAndreas Gohr * the backend before returning it somewhere. 24279f39653SAndreas Gohr * 24379f39653SAndreas Gohr * This should be used to enforce username restrictions. 24479f39653SAndreas Gohr * 24579f39653SAndreas Gohr * @param string $user username 24679f39653SAndreas Gohr * @return string the cleaned username 24779f39653SAndreas Gohr */ 24879f39653SAndreas Gohr public function cleanUser($user) 24979f39653SAndreas Gohr { 25079f39653SAndreas Gohr return $user; 25179f39653SAndreas Gohr } 25279f39653SAndreas Gohr 25379f39653SAndreas Gohr /** 25479f39653SAndreas Gohr * Sanitize a given groupname 25579f39653SAndreas Gohr * 25679f39653SAndreas Gohr * This function is applied to any groupname that is given to 25779f39653SAndreas Gohr * the backend and should also be applied to any groupname within 25879f39653SAndreas Gohr * the backend before returning it somewhere. 25979f39653SAndreas Gohr * 26079f39653SAndreas Gohr * This should be used to enforce groupname restrictions. 26179f39653SAndreas Gohr * 26279f39653SAndreas Gohr * Groupnames are to be passed without a leading '@' here. 26379f39653SAndreas Gohr * 26479f39653SAndreas Gohr * @param string $group groupname 26579f39653SAndreas Gohr * 26679f39653SAndreas Gohr * @return string the cleaned groupname 26779f39653SAndreas Gohr */ 26879f39653SAndreas Gohr public function cleanGroup($group) 26979f39653SAndreas Gohr { 27079f39653SAndreas Gohr return $group; 27179f39653SAndreas Gohr } 27279f39653SAndreas Gohr 27379f39653SAndreas Gohr /** 27479f39653SAndreas Gohr * Check Session Cache validity [implement only where required/possible] 27579f39653SAndreas Gohr * 27679f39653SAndreas Gohr * DokuWiki caches user info in the user's session for the timespan defined 27779f39653SAndreas Gohr * in $conf['auth_security_timeout']. 27879f39653SAndreas Gohr * 27979f39653SAndreas Gohr * This makes sure slow authentication backends do not slow down DokuWiki. 28079f39653SAndreas Gohr * This also means that changes to the user database will not be reflected 28179f39653SAndreas Gohr * on currently logged in users. 28279f39653SAndreas Gohr * 28379f39653SAndreas Gohr * To accommodate for this, the user manager plugin will touch a reference 28479f39653SAndreas Gohr * file whenever a change is submitted. This function compares the filetime 28579f39653SAndreas Gohr * of this reference file with the time stored in the session. 28679f39653SAndreas Gohr * 28779f39653SAndreas Gohr * This reference file mechanism does not reflect changes done directly in 28879f39653SAndreas Gohr * the backend's database through other means than the user manager plugin. 28979f39653SAndreas Gohr * 29079f39653SAndreas Gohr * Fast backends might want to return always false, to force rechecks on 29179f39653SAndreas Gohr * each page load. Others might want to use their own checking here. If 29279f39653SAndreas Gohr * unsure, do not override. 29379f39653SAndreas Gohr * 29479f39653SAndreas Gohr * @param string $user - The username 29579f39653SAndreas Gohr * 29679f39653SAndreas Gohr * @return bool 29779f39653SAndreas Gohr */ 298*1078ec26SAndreas Gohr public function useSessionCache($user) 299*1078ec26SAndreas Gohr { 300*1078ec26SAndreas Gohr return false; 301*1078ec26SAndreas Gohr } 30279f39653SAndreas Gohr} 30379f39653SAndreas Gohr 304