xref: /plugin/authchained/auth.php (revision fca3c6d7b14013593d8ba013bd90ee114e374545)
186e0f1b9SPhilipp Neuser<?php
286e0f1b9SPhilipp Neuser// must be run within Dokuwiki
386e0f1b9SPhilipp Neuserif(!defined('DOKU_INC')) die();
486e0f1b9SPhilipp Neuser
586e0f1b9SPhilipp Neuser/**
686e0f1b9SPhilipp Neuser* Chained authentication backend
786e0f1b9SPhilipp Neuser*
886e0f1b9SPhilipp Neuser* @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
9d9c5261fSeinhirn* @author     Philipp Neuser <pneuser@physik.fu-berlin.de>
10d9c5261fSeinhirn* @author     Christian Marg <marg@rz.tu-clausthal.de>
11d9c5261fSeinhirn*
12d9c5261fSeinhirn* Based on "Chained authentication backend"
13d9c5261fSeinhirn* by Grant Gardner <grant@lastweekend.com.au>
14d9c5261fSeinhirn* see https://www.dokuwiki.org/auth:ggauth
15d9c5261fSeinhirn*
1686e0f1b9SPhilipp Neuser*/
1786e0f1b9SPhilipp Neuserclass auth_plugin_authchained extends DokuWiki_Auth_Plugin {
1886e0f1b9SPhilipp Neuser    public $success = true;
1932fe206aSeinhirn    //array with authentication plugins
2086e0f1b9SPhilipp Neuser    protected $chained_plugins = array();
2186e0f1b9SPhilipp Neuser    protected $chained_auth = NULL;
22d9c5261fSeinhirn    protected $usermanager_auth = NULL;
2386e0f1b9SPhilipp Neuser
2486e0f1b9SPhilipp Neuser    /**
2586e0f1b9SPhilipp Neuser    * Constructor.
2686e0f1b9SPhilipp Neuser    *
2786e0f1b9SPhilipp Neuser    * Loads all configured plugins or the authentication plugin of the
2886e0f1b9SPhilipp Neuser    * logged in user.
2986e0f1b9SPhilipp Neuser    *
3086e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
31d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
3286e0f1b9SPhilipp Neuser    */
3386e0f1b9SPhilipp Neuser    public function __construct() {
3486e0f1b9SPhilipp Neuser        global $conf;
3586e0f1b9SPhilipp Neuser        // call parent
3686e0f1b9SPhilipp Neuser        #      parent::__constructor();
3786e0f1b9SPhilipp Neuser
3832fe206aSeinhirn        //check if there is already an authentication plugin selected
399e84dbfbSPhilipp Neuser        if(     isset($_SESSION[DOKU_COOKIE]['plugin']['authchained']['module']) &&
4032fe206aSeinhirn                !empty($_SESSION[DOKU_COOKIE]['plugin']['authchained']['module']) ) {
4132fe206aSeinhirn
42d9c5261fSeinhirn            //get previously selected authentication plugin
43d9c5261fSeinhirn            $this->chained_auth =& plugin_load('auth',$_SESSION[DOKU_COOKIE]['plugin']['authchained']['module']);
44d9c5261fSeinhirn            if ( is_null($this->chained_auth) || !$this->chained_auth->success ) {
45d9c5261fSeinhirn                $this->success = false;
46d9c5261fSeinhirn            }
4712767e67SEmmanuel Collignon        }
4812767e67SEmmanuel Collignon
4986e0f1b9SPhilipp Neuser        //get authentication plugins
50d9c5261fSeinhirn        if($this->getConf('authtypes')){
51d9c5261fSeinhirn            foreach(explode(":",$this->getConf('authtypes')) as $tmp_plugin){
52d9c5261fSeinhirn                $tmp_class =& plugin_load('auth',$tmp_plugin);
53d9c5261fSeinhirn
54d9c5261fSeinhirn                if ( !is_null($tmp_class) || $tmp_class->success ) {
5586e0f1b9SPhilipp Neuser                    $tmp_module = array($tmp_plugin,$tmp_class);
5686e0f1b9SPhilipp Neuser                    array_push($this->chained_plugins, $tmp_module);
57d9c5261fSeinhirn                } else {
58d9c5261fSeinhirn                    msg("Problem constructing $tmp_plugin",-1);
59d9c5261fSeinhirn                    $this->success = false;
60d9c5261fSeinhirn                }
6186e0f1b9SPhilipp Neuser            }
6286e0f1b9SPhilipp Neuser        } else {
6386e0f1b9SPhilipp Neuser            $success = false;
6486e0f1b9SPhilipp Neuser        }
65d9c5261fSeinhirn
66d9c5261fSeinhirn        // If defined, instantiate usermanager authtype.
67d9c5261fSeinhirn        // No need to check for duplicates, "plugin_load" does that for us.
68d9c5261fSeinhirn        if($this->getConf('usermanager_authtype')){
69d9c5261fSeinhirn            $this->usermanager_auth =& plugin_load('auth',$this->getConf('usermanager_authtype'));
70d9c5261fSeinhirn            if(is_null($this->usermanager_auth) || !$this->usermanager_auth->success ) {
71d9c5261fSeinhirn                    msg("Problem constructing usermanager authtype: ".$this->getConf('usermanager_authtype'),-1);
72d9c5261fSeinhirn                    $this->success = false;
73d9c5261fSeinhirn            }
74d9c5261fSeinhirn        } else {
75d9c5261fSeinhirn            $this->usermanager_auth =& $this->chained_auth;
76d9c5261fSeinhirn        }
77d9c5261fSeinhirn
7886e0f1b9SPhilipp Neuser        //debug
7986e0f1b9SPhilipp Neuser        //      print_r($chained_plugins);
8086e0f1b9SPhilipp Neuser    }
8186e0f1b9SPhilipp Neuser
8286e0f1b9SPhilipp Neuser    /**
8386e0f1b9SPhilipp Neuser    * Forwards the authentication to configured authplugins.
8486e0f1b9SPhilipp Neuser    * Returns true, if the usermanager authtype has the capability and no user
8586e0f1b9SPhilipp Neuser    * is logged in.
8686e0f1b9SPhilipp Neuser    *
8786e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
88d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
8986e0f1b9SPhilipp Neuser    * @param   string $cap the capability to check
9086e0f1b9SPhilipp Neuser    * @return  bool
9186e0f1b9SPhilipp Neuser    */
9286e0f1b9SPhilipp Neuser    public function canDo($cap) {
93d9c5261fSeinhirn        global $ACT;
94c368b833SPhilipp Neuser        #      print_r($cap);
9532fe206aSeinhirn        if(is_null($this->chained_auth)) {
96d9c5261fSeinhirn            if (!is_null($this->usermanager_auth)) {
97d9c5261fSeinhirn                return $this->usermanager_auth->canDo($cap);
9832fe206aSeinhirn            } else {
99d9c5261fSeinhirn                return parent::canDo($cap);
100d9c5261fSeinhirn            }
101d9c5261fSeinhirn        } else {
102d9c5261fSeinhirn            switch($cap) {
103d9c5261fSeinhirn                case 'Profile':
104d9c5261fSeinhirn                case 'logoff':
105d9c5261fSeinhirn                    //Depends on current user.
106d9c5261fSeinhirn                    return $this->chained_auth->canDo($cap);
107d9c5261fSeinhirn                case 'UserMod':
108d9c5261fSeinhirn                case 'addUser':
109d9c5261fSeinhirn                case 'delUser':
110d9c5261fSeinhirn                case 'getUsers':
111d9c5261fSeinhirn                case 'getUserCount':
112d9c5261fSeinhirn                case 'getGroups':
113d9c5261fSeinhirn                    //Depends on the auth for use with user manager
114d9c5261fSeinhirn                    return $this->usermanager_auth->canDo($cap);
115d9c5261fSeinhirn                case 'modPass':
116d9c5261fSeinhirn                case 'modName':
117d9c5261fSeinhirn                case 'modLogin':
118d9c5261fSeinhirn                case 'modGroups':
119d9c5261fSeinhirn                case 'modMail':
120d9c5261fSeinhirn                    /**
121d9c5261fSeinhirn                    * Use request attributes to guess whether we are in the Profile or UserManager
122d9c5261fSeinhirn                    * and return the appropriate auth capabilities
123d9c5261fSeinhirn                    */
124d9c5261fSeinhirn                    if ($ACT == "admin" && $_REQUEST['page']=="usermanager") {
125d9c5261fSeinhirn                        return $this->usermanager_auth->canDo($cap);
126d9c5261fSeinhirn                    } else {
127d9c5261fSeinhirn                        // assume we want profile info.
12886e0f1b9SPhilipp Neuser                        return $this->chained_auth->canDo($cap);
12986e0f1b9SPhilipp Neuser                    }
130d9c5261fSeinhirn// I don't know how to handle "external" in this context yet.
131d9c5261fSeinhirn// Is it in any way sensible to mix regular auth with external auth?
132d9c5261fSeinhirn//                case 'external':
133d9c5261fSeinhirn//                    //We are external if one of the chains is valid for external use
134d9c5261fSeinhirn//                    return $this->trustExternal($_REQUEST['u'],$_REQUEST['p'],$_REQUEST['r']);
135d9c5261fSeinhirn                default:
136d9c5261fSeinhirn                    //Everything else (false)
137d9c5261fSeinhirn                    return parent::canDo($cap);
13886e0f1b9SPhilipp Neuser            }
139d9c5261fSeinhirn            #echo "canDo $cap ".$this->chained_auth->canDo($cap)."\n";
140d9c5261fSeinhirn        }
14186e0f1b9SPhilipp Neuser    }
14286e0f1b9SPhilipp Neuser
14386e0f1b9SPhilipp Neuser    /**
14486e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user and
14586e0f1b9SPhilipp Neuser    * unsets our session variable.
14686e0f1b9SPhilipp Neuser    * @see     auth_logoff()
14786e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de
148d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
14986e0f1b9SPhilipp Neuser    */
15086e0f1b9SPhilipp Neuser    public function logOff() {
15186e0f1b9SPhilipp Neuser        if(!is_null($this->chained_auth))
15286e0f1b9SPhilipp Neuser            $this->chained_auth->logOff();
1539e84dbfbSPhilipp Neuser        unset($_SESSION[DOKU_COOKIE]['plugin']['authchained']['module']);
15486e0f1b9SPhilipp Neuser    }
15586e0f1b9SPhilipp Neuser
15686e0f1b9SPhilipp Neuser    /**
15786e0f1b9SPhilipp Neuser    * Do all authentication [ OPTIONAL ]
15886e0f1b9SPhilipp Neuser    * If the current plugin is external, be external.
15986e0f1b9SPhilipp Neuser    *
16086e0f1b9SPhilipp Neuser    * @see     auth_login()
16186e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
162d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
16386e0f1b9SPhilipp Neuser    *
16486e0f1b9SPhilipp Neuser    * @param   string  $user    Username
16586e0f1b9SPhilipp Neuser    * @param   string  $pass    Cleartext Password
16686e0f1b9SPhilipp Neuser    * @param   bool    $sticky  Cookie should not expire
16786e0f1b9SPhilipp Neuser    * @return  bool             true on successful auth
16886e0f1b9SPhilipp Neuser    */
16986e0f1b9SPhilipp Neuser    public function trustExternal($user, $pass, $sticky = false) {
17086e0f1b9SPhilipp Neuser        if(!is_null($this->chained_auth) && $this->chained_auth->canDo('external'))
17186e0f1b9SPhilipp Neuser            $this->chained_auth->trustExternal($user, $pass, $sticky);
17286e0f1b9SPhilipp Neuser    }
17386e0f1b9SPhilipp Neuser
17486e0f1b9SPhilipp Neuser    /**
17586e0f1b9SPhilipp Neuser    * Check user+password [ MUST BE OVERRIDDEN ]
17686e0f1b9SPhilipp Neuser    *
17786e0f1b9SPhilipp Neuser    * Checks if the given user exists in one of the plugins and checks
17886e0f1b9SPhilipp Neuser    * against the given password. The first plugin returning true becomes
17986e0f1b9SPhilipp Neuser    * auth plugin of the user session.
18086e0f1b9SPhilipp Neuser    *
18186e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de
182d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
18386e0f1b9SPhilipp Neuser    * @param   string $user the user name
18486e0f1b9SPhilipp Neuser    * @param   string $pass the clear text password
18586e0f1b9SPhilipp Neuser    * @return  bool
18686e0f1b9SPhilipp Neuser    */
18786e0f1b9SPhilipp Neuser    public function checkPass($user, $pass) {
18886e0f1b9SPhilipp Neuser        //debug
18986e0f1b9SPhilipp Neuser        // print_r($this->chained_plugins);
190*fca3c6d7SPawel Jasinski        if(!is_null($this->chained_auth))
19132fe206aSeinhirn            return $this->chained_auth->checkPass($user, $pass);
192*fca3c6d7SPawel Jasinski        foreach($this->chained_plugins as $module) {
193*fca3c6d7SPawel Jasinski            if($module[1]->canDo('external') && $module[1]->trustExternal($user, $pass)) {
194*fca3c6d7SPawel Jasinski                $_SESSION[DOKU_COOKIE]['plugin']['authchained']['module'] = $module[0];
195*fca3c6d7SPawel Jasinski                $this->chained_auth = $module[1];
196*fca3c6d7SPawel Jasinski                return true;
197*fca3c6d7SPawel Jasinski            }
198*fca3c6d7SPawel Jasinski            if($module[1]->checkPass($user, $pass)) {
199*fca3c6d7SPawel Jasinski                $_SESSION[DOKU_COOKIE]['plugin']['authchained']['module'] = $module[0];
200*fca3c6d7SPawel Jasinski                $this->chained_auth = $module[1];
201*fca3c6d7SPawel Jasinski                return true;
202*fca3c6d7SPawel Jasinski            }
20332fe206aSeinhirn        }
20486e0f1b9SPhilipp Neuser        return false;
20586e0f1b9SPhilipp Neuser    }
20686e0f1b9SPhilipp Neuser
20786e0f1b9SPhilipp Neuser    /**
20886e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
20986e0f1b9SPhilipp Neuser    * checks all plugins if the users exists. The first plugin returning
21086e0f1b9SPhilipp Neuser    * data is used.
21186e0f1b9SPhilipp Neuser    *
21286e0f1b9SPhilipp Neuser    * name string  full name of the user
21386e0f1b9SPhilipp Neuser    * mail string  email addres of the user
21486e0f1b9SPhilipp Neuser    * grps array   list of groups the user is in
21586e0f1b9SPhilipp Neuser    *
21686e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
217d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
21886e0f1b9SPhilipp Neuser    * @param   string $user the user name
21986e0f1b9SPhilipp Neuser    * @return  array containing user data or false
22086e0f1b9SPhilipp Neuser    */
221c27cbb90Srnck    public function getUserData($user, $requireGroups=true) {
22212767e67SEmmanuel Collignon        global $ACT, $INPUT;
22312767e67SEmmanuel Collignon
22486e0f1b9SPhilipp Neuser        //if(!$this->cando['external']) msg("no valid authorisation system in use", -1);
22586e0f1b9SPhilipp Neuser        //       echo "TESTSETEST";
2261b39d8c6Seinhirn
2271b39d8c6Seinhirn        //print_r($this->chained_auth);
2281b39d8c6Seinhirn        if ($ACT == "admin" && $_REQUEST['page']=="usermanager") {
2291b39d8c6Seinhirn            if(!is_null($this->usermanager_auth))
2301b39d8c6Seinhirn                return $this->usermanager_auth->getUserData($user);
2314e6f1bb5Seinhirn	}
2321b39d8c6Seinhirn
2339ad8d9f1Seinhirn        if(is_null($this->chained_auth)||(!is_null($INPUT->server) && $user != $INPUT->server->str('REMOTE_USER'))) {
23432fe206aSeinhirn            foreach($this->chained_plugins as $module) {
23586e0f1b9SPhilipp Neuser                $tmp_array = $module[1]->getUserData($user);
23686e0f1b9SPhilipp Neuser                if(!is_bool($tmp_array))
23786e0f1b9SPhilipp Neuser                    $tmp_chk_arr =array_filter($tmp_array);
23886e0f1b9SPhilipp Neuser                if(!empty($tmp_chk_arr) && $tmp_array)
23986e0f1b9SPhilipp Neuser                    return $tmp_array;
24086e0f1b9SPhilipp Neuser            }
24186e0f1b9SPhilipp Neuser            return false;
24232fe206aSeinhirn        } else {
24386e0f1b9SPhilipp Neuser            return $this->chained_auth->getUserData($user);
24486e0f1b9SPhilipp Neuser        }
24586e0f1b9SPhilipp Neuser    }
24686e0f1b9SPhilipp Neuser
24786e0f1b9SPhilipp Neuser    /**
24886e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
24986e0f1b9SPhilipp Neuser    * returns null.
25086e0f1b9SPhilipp Neuser    *
25186e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
252d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
25386e0f1b9SPhilipp Neuser    * @param   string     $user
25486e0f1b9SPhilipp Neuser    * @param   string     $pass
25586e0f1b9SPhilipp Neuser    * @param   string     $name
25686e0f1b9SPhilipp Neuser    * @param   string     $mail
25786e0f1b9SPhilipp Neuser    * @param   null|array $grps
25886e0f1b9SPhilipp Neuser    * @return  bool|null
25986e0f1b9SPhilipp Neuser    */
26086e0f1b9SPhilipp Neuser    public function createUser($user, $pass, $name, $mail, $grps = null) {
261d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('addUser')) {
262d9c5261fSeinhirn            return $this->usermanager_auth->createUser($user, $pass, $name, $mail, $grps);
26386e0f1b9SPhilipp Neuser        } else {
26432fe206aSeinhirn            msg("authorisation method does not allow creation of new users", -1);
26586e0f1b9SPhilipp Neuser            return null;
26686e0f1b9SPhilipp Neuser        }
26786e0f1b9SPhilipp Neuser    }
26886e0f1b9SPhilipp Neuser
26986e0f1b9SPhilipp Neuser    /**
27086e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
27186e0f1b9SPhilipp Neuser    * returns false
27286e0f1b9SPhilipp Neuser    *
27386e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
274d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
27586e0f1b9SPhilipp Neuser    * @param   string $user    nick of the user to be changed
27686e0f1b9SPhilipp Neuser    * @param   array  $changes array of field/value pairs to be changed (password will be clear text)
27786e0f1b9SPhilipp Neuser    * @return  bool
27886e0f1b9SPhilipp Neuser    */
27986e0f1b9SPhilipp Neuser    public function modifyUser($user, $changes) {
280d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('UserMod') ) {
281d9c5261fSeinhirn            return $this->usermanager_auth->modifyUser($user, $changes);
28286e0f1b9SPhilipp Neuser        } else {
28332fe206aSeinhirn            msg("authorisation method does not allow modifying of user data", -1);
284d9c5261fSeinhirn            return null;
28586e0f1b9SPhilipp Neuser        }
28686e0f1b9SPhilipp Neuser    }
28786e0f1b9SPhilipp Neuser
28886e0f1b9SPhilipp Neuser    /**
28986e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
29086e0f1b9SPhilipp Neuser    * returns false
29186e0f1b9SPhilipp Neuser    *
29286e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
293d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
29486e0f1b9SPhilipp Neuser    * @param   array  $users
29586e0f1b9SPhilipp Neuser    * @return  int    number of users deleted
29686e0f1b9SPhilipp Neuser    */
29786e0f1b9SPhilipp Neuser    public function deleteUsers($users) {
298d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('delUser') ) {
299d9c5261fSeinhirn            return $this->usermanager_auth->deleteUsers($users);
30086e0f1b9SPhilipp Neuser        }else{
30186e0f1b9SPhilipp Neuser            msg("authorisation method does not allow deleting of users", -1);
30286e0f1b9SPhilipp Neuser            return false;
30386e0f1b9SPhilipp Neuser        }
30486e0f1b9SPhilipp Neuser    }
30586e0f1b9SPhilipp Neuser
30686e0f1b9SPhilipp Neuser    /**
30786e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
30886e0f1b9SPhilipp Neuser    * returns 0
30986e0f1b9SPhilipp Neuser    *
31086e0f1b9SPhilipp Neuser    * @author Philipp Neuser <pneuser@physik.fu-berlin.de>
311d9c5261fSeinhirn    * @author Christian Marg <marg@rz.tu-clausthal.de>
31286e0f1b9SPhilipp Neuser    * @param  array $filter array of field/pattern pairs, empty array for no filter
31386e0f1b9SPhilipp Neuser    * @return int
31486e0f1b9SPhilipp Neuser    */
31586e0f1b9SPhilipp Neuser    public function getUserCount($filter = array()) {
316d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('getUserCount') ){
317d9c5261fSeinhirn            return $this->usermanager_auth->getUserCount($filter);
31886e0f1b9SPhilipp Neuser        } else {
31986e0f1b9SPhilipp Neuser            msg("authorisation method does not provide user counts", -1);
32086e0f1b9SPhilipp Neuser            return 0;
32186e0f1b9SPhilipp Neuser        }
32286e0f1b9SPhilipp Neuser    }
32386e0f1b9SPhilipp Neuser
32486e0f1b9SPhilipp Neuser    /**
32586e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
32686e0f1b9SPhilipp Neuser    * returns empty array
32786e0f1b9SPhilipp Neuser    *
32886e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
329d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
33086e0f1b9SPhilipp Neuser    * @param   int   $start     index of first user to be returned
33186e0f1b9SPhilipp Neuser    * @param   int   $limit     max number of users to be returned
33286e0f1b9SPhilipp Neuser    * @param   array $filter    array of field/pattern pairs, null for no filter
33386e0f1b9SPhilipp Neuser    * @return  array list of userinfo (refer getUserData for internal userinfo details)
33486e0f1b9SPhilipp Neuser    */
33586e0f1b9SPhilipp Neuser    public function retrieveUsers($start = 0, $limit = -1, $filter = null) {
336d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('getUsers') ) {
337d9c5261fSeinhirn            //msg("RetrieveUsers is using ".get_class($this->usermanager_auth));
338d9c5261fSeinhirn            return $this->usermanager_auth->retrieveUsers($start, $limit, $filter);
33986e0f1b9SPhilipp Neuser        } else {
34086e0f1b9SPhilipp Neuser            msg("authorisation method does not support mass retrievals", -1);
34186e0f1b9SPhilipp Neuser            return array();
34286e0f1b9SPhilipp Neuser        }
34386e0f1b9SPhilipp Neuser    }
34486e0f1b9SPhilipp Neuser
34586e0f1b9SPhilipp Neuser    /**
34686e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
34786e0f1b9SPhilipp Neuser    * returns false
34886e0f1b9SPhilipp Neuser    *
34986e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
350d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
35186e0f1b9SPhilipp Neuser    * @param   string $group
35286e0f1b9SPhilipp Neuser    * @return  bool
35386e0f1b9SPhilipp Neuser    */
35486e0f1b9SPhilipp Neuser    public function addGroup($group) {
355d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('addGroup') ) {
356d9c5261fSeinhirn            return $this->usermanager_auth->addGroup($group);
35786e0f1b9SPhilipp Neuser        } else {
35832fe206aSeinhirn            msg("authorisation method does not support independent group creation", -1);
35986e0f1b9SPhilipp Neuser            return false;
36086e0f1b9SPhilipp Neuser        }
36186e0f1b9SPhilipp Neuser    }
36286e0f1b9SPhilipp Neuser
36386e0f1b9SPhilipp Neuser    /**
36486e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
36586e0f1b9SPhilipp Neuser    * returns empty array
36686e0f1b9SPhilipp Neuser    *
36786e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
368d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
36986e0f1b9SPhilipp Neuser    * @param   int $start
37086e0f1b9SPhilipp Neuser    * @param   int $limit
37186e0f1b9SPhilipp Neuser    * @return  array
37286e0f1b9SPhilipp Neuser    */
37386e0f1b9SPhilipp Neuser    public function retrieveGroups($start = 0, $limit = 0) {
374d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('getGroups') ) {
375d9c5261fSeinhirn                return $this->usermanager_auth->retrieveGroups($start,$limit);
37686e0f1b9SPhilipp Neuser        } else {
37732fe206aSeinhirn            msg("authorisation method does not support group list retrieval", -1);
37886e0f1b9SPhilipp Neuser            return array();
37986e0f1b9SPhilipp Neuser        }
38086e0f1b9SPhilipp Neuser    }
38186e0f1b9SPhilipp Neuser
38286e0f1b9SPhilipp Neuser    /**
38386e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
38486e0f1b9SPhilipp Neuser    * returns true
38586e0f1b9SPhilipp Neuser    *
38686e0f1b9SPhilipp Neuser    * @return bool
38786e0f1b9SPhilipp Neuser    */
38886e0f1b9SPhilipp Neuser    public function isCaseSensitive() {
38986e0f1b9SPhilipp Neuser        if(is_null($this->chained_auth))
390d9c5261fSeinhirn            return parent::isCaseSensitive();
39186e0f1b9SPhilipp Neuser        else
39286e0f1b9SPhilipp Neuser            return $this->chained_auth->isCaseSensitive();
39386e0f1b9SPhilipp Neuser    }
39486e0f1b9SPhilipp Neuser
39586e0f1b9SPhilipp Neuser    /**
39686e0f1b9SPhilipp Neuser    * Sanitize a given username [OPTIONAL]
39786e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
39886e0f1b9SPhilipp Neuser    * returns false
39986e0f1b9SPhilipp Neuser    *
40086e0f1b9SPhilipp Neuser    *
40186e0f1b9SPhilipp Neuser    * @author Philipp Neuser <pneuser@physik.fu-berlin.de>
402d9c5261fSeinhirn    * @author Christian Marg <marg@rz.tu-clausthal.de>
40386e0f1b9SPhilipp Neuser    * @param  string $user username
40486e0f1b9SPhilipp Neuser    * @return string the cleaned username
40586e0f1b9SPhilipp Neuser    */
40686e0f1b9SPhilipp Neuser    public function cleanUser($user) {
407d9c5261fSeinhirn        global $ACT;
40886e0f1b9SPhilipp Neuser        //print_r($this->chained_auth);
409d9c5261fSeinhirn        if ($ACT == "admin" && $_REQUEST['page']=="usermanager") {
410d9c5261fSeinhirn            if(!is_null($this->usermanager_auth))
411d9c5261fSeinhirn                return $this->usermanager_auth->cleanUser($user);
412d9c5261fSeinhirn        } else {
413d9c5261fSeinhirn            if(!is_null($this->chained_auth))
41486e0f1b9SPhilipp Neuser                return $this->chained_auth->cleanUser($user);
41586e0f1b9SPhilipp Neuser        }
416d9c5261fSeinhirn        return parent::cleanUser($user);
417d9c5261fSeinhirn    }
41886e0f1b9SPhilipp Neuser
41986e0f1b9SPhilipp Neuser    /**
42086e0f1b9SPhilipp Neuser    * Sanitize a given groupname [OPTIONAL]
42186e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
42286e0f1b9SPhilipp Neuser    * returns false
42386e0f1b9SPhilipp Neuser    *
42486e0f1b9SPhilipp Neuser    * @author Philipp Neuser <pneuser@physik.fu-berlin.de>
425d9c5261fSeinhirn    * @author Christian Marg <marg@rz.tu-clausthal.de>
42686e0f1b9SPhilipp Neuser    * @param  string $group groupname
42786e0f1b9SPhilipp Neuser    * @return string the cleaned groupname
42886e0f1b9SPhilipp Neuser    */
42986e0f1b9SPhilipp Neuser    public function cleanGroup($group) {
430d9c5261fSeinhirn        global $ACT;
431d9c5261fSeinhirn        if ($ACT == "admin" && $_REQUEST['page']=="usermanager") {
432d9c5261fSeinhirn            if(!is_null($this->usermanager_auth))
433d9c5261fSeinhirn                return $this->usermanager_auth->cleanGroup($group);
43432fe206aSeinhirn        } else {
435d9c5261fSeinhirn            if(!is_null($this->chained_auth))
43686e0f1b9SPhilipp Neuser                return $this->chained_auth->cleanGroup($group);
43786e0f1b9SPhilipp Neuser        }
438d9c5261fSeinhirn        return parent::cleanGroup($group);
43932fe206aSeinhirn    }
44086e0f1b9SPhilipp Neuser
44186e0f1b9SPhilipp Neuser
44286e0f1b9SPhilipp Neuser    public function useSessionCache($user) {
44386e0f1b9SPhilipp Neuser        global $conf;
44486e0f1b9SPhilipp Neuser        if(is_null($this->chained_auth))
445d9c5261fSeinhirn            return parent::useSessionCache($user);
44686e0f1b9SPhilipp Neuser        else
44786e0f1b9SPhilipp Neuser            return $this->chained_auth->useSessionCache($user);
44886e0f1b9SPhilipp Neuser    }
449d9c5261fSeinhirn
45086e0f1b9SPhilipp Neuser}
451