xref: /plugin/authchained/auth.php (revision a015b7336312e0d49e4dd988e5fa36c642c8d93e)
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;
23*a015b733SPawel Jasinski    protected $any_external = false;
2486e0f1b9SPhilipp Neuser
2586e0f1b9SPhilipp Neuser    /**
2686e0f1b9SPhilipp Neuser    * Constructor.
2786e0f1b9SPhilipp Neuser    *
2886e0f1b9SPhilipp Neuser    * Loads all configured plugins or the authentication plugin of the
2986e0f1b9SPhilipp Neuser    * logged in user.
3086e0f1b9SPhilipp Neuser    *
3186e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
32d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
3386e0f1b9SPhilipp Neuser    */
3486e0f1b9SPhilipp Neuser    public function __construct() {
3586e0f1b9SPhilipp Neuser        global $conf;
3686e0f1b9SPhilipp Neuser        // call parent
3786e0f1b9SPhilipp Neuser        #      parent::__constructor();
3886e0f1b9SPhilipp Neuser
3932fe206aSeinhirn        //check if there is already an authentication plugin selected
409e84dbfbSPhilipp Neuser        if(     isset($_SESSION[DOKU_COOKIE]['plugin']['authchained']['module']) &&
4132fe206aSeinhirn                !empty($_SESSION[DOKU_COOKIE]['plugin']['authchained']['module']) ) {
4232fe206aSeinhirn
43d9c5261fSeinhirn            //get previously selected authentication plugin
44d9c5261fSeinhirn            $this->chained_auth =& plugin_load('auth',$_SESSION[DOKU_COOKIE]['plugin']['authchained']['module']);
45d9c5261fSeinhirn            if ( is_null($this->chained_auth) || !$this->chained_auth->success ) {
46d9c5261fSeinhirn                $this->success = false;
47d9c5261fSeinhirn            }
4812767e67SEmmanuel Collignon        }
4912767e67SEmmanuel Collignon
5086e0f1b9SPhilipp Neuser        //get authentication plugins
51d9c5261fSeinhirn        if($this->getConf('authtypes')){
52d9c5261fSeinhirn            foreach(explode(":",$this->getConf('authtypes')) as $tmp_plugin){
53d9c5261fSeinhirn                $tmp_class =& plugin_load('auth',$tmp_plugin);
54d9c5261fSeinhirn
55d9c5261fSeinhirn                if ( !is_null($tmp_class) || $tmp_class->success ) {
5686e0f1b9SPhilipp Neuser                    $tmp_module = array($tmp_plugin,$tmp_class);
5786e0f1b9SPhilipp Neuser                    array_push($this->chained_plugins, $tmp_module);
58*a015b733SPawel Jasinski                    $this->any_external |= $tmp_class->canDo('external');
59d9c5261fSeinhirn                } else {
60d9c5261fSeinhirn                    msg("Problem constructing $tmp_plugin",-1);
61d9c5261fSeinhirn                    $this->success = false;
62d9c5261fSeinhirn                }
6386e0f1b9SPhilipp Neuser            }
6486e0f1b9SPhilipp Neuser        } else {
6586e0f1b9SPhilipp Neuser            $success = false;
6686e0f1b9SPhilipp Neuser        }
67d9c5261fSeinhirn
68d9c5261fSeinhirn        // If defined, instantiate usermanager authtype.
69d9c5261fSeinhirn        // No need to check for duplicates, "plugin_load" does that for us.
70d9c5261fSeinhirn        if($this->getConf('usermanager_authtype')){
71d9c5261fSeinhirn            $this->usermanager_auth =& plugin_load('auth',$this->getConf('usermanager_authtype'));
72d9c5261fSeinhirn            if(is_null($this->usermanager_auth) || !$this->usermanager_auth->success ) {
73d9c5261fSeinhirn                    msg("Problem constructing usermanager authtype: ".$this->getConf('usermanager_authtype'),-1);
74d9c5261fSeinhirn                    $this->success = false;
75d9c5261fSeinhirn            }
76d9c5261fSeinhirn        } else {
77d9c5261fSeinhirn            $this->usermanager_auth =& $this->chained_auth;
78d9c5261fSeinhirn        }
79d9c5261fSeinhirn
8086e0f1b9SPhilipp Neuser        //debug
8186e0f1b9SPhilipp Neuser        // print_r($chained_plugins);
8286e0f1b9SPhilipp Neuser    }
8386e0f1b9SPhilipp Neuser
8486e0f1b9SPhilipp Neuser    /**
8586e0f1b9SPhilipp Neuser    * Forwards the authentication to configured authplugins.
8686e0f1b9SPhilipp Neuser    * Returns true, if the usermanager authtype has the capability and no user
8786e0f1b9SPhilipp Neuser    * is logged in.
8886e0f1b9SPhilipp Neuser    *
8986e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
90d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
9186e0f1b9SPhilipp Neuser    * @param   string $cap the capability to check
9286e0f1b9SPhilipp Neuser    * @return  bool
9386e0f1b9SPhilipp Neuser    */
9486e0f1b9SPhilipp Neuser    public function canDo($cap) {
95d9c5261fSeinhirn        global $ACT;
96c368b833SPhilipp Neuser        #      print_r($cap);
9732fe206aSeinhirn        if(is_null($this->chained_auth)) {
98*a015b733SPawel Jasinski            if ($cap == "external") {
99*a015b733SPawel Jasinski                return $this->any_external;
100*a015b733SPawel Jasinski            }
101d9c5261fSeinhirn            if (!is_null($this->usermanager_auth)) {
102d9c5261fSeinhirn                return $this->usermanager_auth->canDo($cap);
10332fe206aSeinhirn            } else {
104d9c5261fSeinhirn                return parent::canDo($cap);
105d9c5261fSeinhirn            }
106d9c5261fSeinhirn        } else {
107d9c5261fSeinhirn            switch($cap) {
108d9c5261fSeinhirn                case 'Profile':
10954719a74SPawel Jasinski                case 'logout':
110d9c5261fSeinhirn                    //Depends on current user.
111d9c5261fSeinhirn                    return $this->chained_auth->canDo($cap);
112d9c5261fSeinhirn                case 'UserMod':
113d9c5261fSeinhirn                case 'addUser':
114d9c5261fSeinhirn                case 'delUser':
115d9c5261fSeinhirn                case 'getUsers':
116d9c5261fSeinhirn                case 'getUserCount':
117d9c5261fSeinhirn                case 'getGroups':
118d9c5261fSeinhirn                    //Depends on the auth for use with user manager
119d9c5261fSeinhirn                    return $this->usermanager_auth->canDo($cap);
120d9c5261fSeinhirn                case 'modPass':
121d9c5261fSeinhirn                case 'modName':
122d9c5261fSeinhirn                case 'modLogin':
123d9c5261fSeinhirn                case 'modGroups':
124d9c5261fSeinhirn                case 'modMail':
125d9c5261fSeinhirn                    /**
126d9c5261fSeinhirn                    * Use request attributes to guess whether we are in the Profile or UserManager
127d9c5261fSeinhirn                    * and return the appropriate auth capabilities
128d9c5261fSeinhirn                    */
129d9c5261fSeinhirn                    if ($ACT == "admin" && $_REQUEST['page']=="usermanager") {
130d9c5261fSeinhirn                        return $this->usermanager_auth->canDo($cap);
131d9c5261fSeinhirn                    } else {
132d9c5261fSeinhirn                        // assume we want profile info.
13386e0f1b9SPhilipp Neuser                        return $this->chained_auth->canDo($cap);
13486e0f1b9SPhilipp Neuser                    }
135*a015b733SPawel Jasinski                case 'external':
136*a015b733SPawel Jasinski                    return $this->chained_auth->canDo($cap);
137d9c5261fSeinhirn                default:
138d9c5261fSeinhirn                    //Everything else (false)
139d9c5261fSeinhirn                    return parent::canDo($cap);
14086e0f1b9SPhilipp Neuser            }
141d9c5261fSeinhirn            #echo "canDo $cap ".$this->chained_auth->canDo($cap)."\n";
142d9c5261fSeinhirn        }
14386e0f1b9SPhilipp Neuser    }
14486e0f1b9SPhilipp Neuser
14586e0f1b9SPhilipp Neuser    /**
14686e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user and
14786e0f1b9SPhilipp Neuser    * unsets our session variable.
14886e0f1b9SPhilipp Neuser    * @see     auth_logoff()
14986e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de
150d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
15186e0f1b9SPhilipp Neuser    */
15286e0f1b9SPhilipp Neuser    public function logOff() {
15386e0f1b9SPhilipp Neuser        if(!is_null($this->chained_auth))
15486e0f1b9SPhilipp Neuser            $this->chained_auth->logOff();
1559e84dbfbSPhilipp Neuser        unset($_SESSION[DOKU_COOKIE]['plugin']['authchained']['module']);
15686e0f1b9SPhilipp Neuser    }
15786e0f1b9SPhilipp Neuser
15886e0f1b9SPhilipp Neuser    /**
15986e0f1b9SPhilipp Neuser    * Do all authentication [ OPTIONAL ]
16086e0f1b9SPhilipp Neuser    * If the current plugin is external, be external.
16186e0f1b9SPhilipp Neuser    *
16286e0f1b9SPhilipp Neuser    * @see     auth_login()
16386e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
164d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
16586e0f1b9SPhilipp Neuser    *
16686e0f1b9SPhilipp Neuser    * @param   string  $user    Username
16786e0f1b9SPhilipp Neuser    * @param   string  $pass    Cleartext Password
16886e0f1b9SPhilipp Neuser    * @param   bool    $sticky  Cookie should not expire
16986e0f1b9SPhilipp Neuser    * @return  bool             true on successful auth
17086e0f1b9SPhilipp Neuser    */
17186e0f1b9SPhilipp Neuser    public function trustExternal($user, $pass, $sticky = false) {
172*a015b733SPawel Jasinski        foreach($this->chained_plugins as $module) {
173*a015b733SPawel Jasinski            if($module[1]->canDo('external') && $module[1]->trustExternal($user, $pass)) {
174*a015b733SPawel Jasinski                $_SESSION[DOKU_COOKIE]['plugin']['authchained']['module'] = $module[0];
175*a015b733SPawel Jasinski                $this->chained_auth = $module[1];
176*a015b733SPawel Jasinski                return true;
177*a015b733SPawel Jasinski            }
178*a015b733SPawel Jasinski        }
179*a015b733SPawel Jasinski        return false;
18086e0f1b9SPhilipp Neuser    }
18186e0f1b9SPhilipp Neuser
18286e0f1b9SPhilipp Neuser    /**
18386e0f1b9SPhilipp Neuser    * Check user+password [ MUST BE OVERRIDDEN ]
18486e0f1b9SPhilipp Neuser    *
18586e0f1b9SPhilipp Neuser    * Checks if the given user exists in one of the plugins and checks
18686e0f1b9SPhilipp Neuser    * against the given password. The first plugin returning true becomes
18786e0f1b9SPhilipp Neuser    * auth plugin of the user session.
18886e0f1b9SPhilipp Neuser    *
18986e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de
190d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
19186e0f1b9SPhilipp Neuser    * @param   string $user the user name
19286e0f1b9SPhilipp Neuser    * @param   string $pass the clear text password
19386e0f1b9SPhilipp Neuser    * @return  bool
19486e0f1b9SPhilipp Neuser    */
19586e0f1b9SPhilipp Neuser    public function checkPass($user, $pass) {
19686e0f1b9SPhilipp Neuser        //debug
19786e0f1b9SPhilipp Neuser        // print_r($this->chained_plugins);
198fca3c6d7SPawel Jasinski        if(!is_null($this->chained_auth))
19932fe206aSeinhirn            return $this->chained_auth->checkPass($user, $pass);
200fca3c6d7SPawel Jasinski        foreach($this->chained_plugins as $module) {
201fca3c6d7SPawel Jasinski            if($module[1]->canDo('external') && $module[1]->trustExternal($user, $pass)) {
202fca3c6d7SPawel Jasinski                $_SESSION[DOKU_COOKIE]['plugin']['authchained']['module'] = $module[0];
203fca3c6d7SPawel Jasinski                $this->chained_auth = $module[1];
204fca3c6d7SPawel Jasinski                return true;
205fca3c6d7SPawel Jasinski            }
206fca3c6d7SPawel Jasinski            if($module[1]->checkPass($user, $pass)) {
207fca3c6d7SPawel Jasinski                $_SESSION[DOKU_COOKIE]['plugin']['authchained']['module'] = $module[0];
208fca3c6d7SPawel Jasinski                $this->chained_auth = $module[1];
209fca3c6d7SPawel Jasinski                return true;
210fca3c6d7SPawel Jasinski            }
21132fe206aSeinhirn        }
21286e0f1b9SPhilipp Neuser        return false;
21386e0f1b9SPhilipp Neuser    }
21486e0f1b9SPhilipp Neuser
21586e0f1b9SPhilipp Neuser    /**
21686e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
21786e0f1b9SPhilipp Neuser    * checks all plugins if the users exists. The first plugin returning
21886e0f1b9SPhilipp Neuser    * data is used.
21986e0f1b9SPhilipp Neuser    *
22086e0f1b9SPhilipp Neuser    * name string  full name of the user
22186e0f1b9SPhilipp Neuser    * mail string  email addres of the user
22286e0f1b9SPhilipp Neuser    * grps array   list of groups the user is in
22386e0f1b9SPhilipp Neuser    *
22486e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
225d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
22686e0f1b9SPhilipp Neuser    * @param   string $user the user name
22786e0f1b9SPhilipp Neuser    * @return  array containing user data or false
22886e0f1b9SPhilipp Neuser    */
229c27cbb90Srnck    public function getUserData($user, $requireGroups=true) {
23012767e67SEmmanuel Collignon        global $ACT, $INPUT;
23112767e67SEmmanuel Collignon
23286e0f1b9SPhilipp Neuser        //if(!$this->cando['external']) msg("no valid authorisation system in use", -1);
23386e0f1b9SPhilipp Neuser        //       echo "TESTSETEST";
2341b39d8c6Seinhirn
2351b39d8c6Seinhirn        //print_r($this->chained_auth);
2361b39d8c6Seinhirn        if ($ACT == "admin" && $_REQUEST['page']=="usermanager") {
2371b39d8c6Seinhirn            if(!is_null($this->usermanager_auth))
2381b39d8c6Seinhirn                return $this->usermanager_auth->getUserData($user);
2394e6f1bb5Seinhirn	}
2401b39d8c6Seinhirn
2419ad8d9f1Seinhirn        if(is_null($this->chained_auth)||(!is_null($INPUT->server) && $user != $INPUT->server->str('REMOTE_USER'))) {
24232fe206aSeinhirn            foreach($this->chained_plugins as $module) {
24386e0f1b9SPhilipp Neuser                $tmp_array = $module[1]->getUserData($user);
24486e0f1b9SPhilipp Neuser                if(!is_bool($tmp_array))
24586e0f1b9SPhilipp Neuser                    $tmp_chk_arr =array_filter($tmp_array);
24686e0f1b9SPhilipp Neuser                if(!empty($tmp_chk_arr) && $tmp_array)
24786e0f1b9SPhilipp Neuser                    return $tmp_array;
24886e0f1b9SPhilipp Neuser            }
24986e0f1b9SPhilipp Neuser            return false;
25032fe206aSeinhirn        } else {
25186e0f1b9SPhilipp Neuser            return $this->chained_auth->getUserData($user);
25286e0f1b9SPhilipp Neuser        }
25386e0f1b9SPhilipp Neuser    }
25486e0f1b9SPhilipp Neuser
25586e0f1b9SPhilipp Neuser    /**
25686e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
25786e0f1b9SPhilipp Neuser    * returns null.
25886e0f1b9SPhilipp Neuser    *
25986e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
260d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
26186e0f1b9SPhilipp Neuser    * @param   string     $user
26286e0f1b9SPhilipp Neuser    * @param   string     $pass
26386e0f1b9SPhilipp Neuser    * @param   string     $name
26486e0f1b9SPhilipp Neuser    * @param   string     $mail
26586e0f1b9SPhilipp Neuser    * @param   null|array $grps
26686e0f1b9SPhilipp Neuser    * @return  bool|null
26786e0f1b9SPhilipp Neuser    */
26886e0f1b9SPhilipp Neuser    public function createUser($user, $pass, $name, $mail, $grps = null) {
269d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('addUser')) {
270d9c5261fSeinhirn            return $this->usermanager_auth->createUser($user, $pass, $name, $mail, $grps);
27186e0f1b9SPhilipp Neuser        } else {
27232fe206aSeinhirn            msg("authorisation method does not allow creation of new users", -1);
27386e0f1b9SPhilipp Neuser            return null;
27486e0f1b9SPhilipp Neuser        }
27586e0f1b9SPhilipp Neuser    }
27686e0f1b9SPhilipp Neuser
27786e0f1b9SPhilipp Neuser    /**
27886e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
27986e0f1b9SPhilipp Neuser    * returns false
28086e0f1b9SPhilipp Neuser    *
28186e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
282d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
28386e0f1b9SPhilipp Neuser    * @param   string $user    nick of the user to be changed
28486e0f1b9SPhilipp Neuser    * @param   array  $changes array of field/value pairs to be changed (password will be clear text)
28586e0f1b9SPhilipp Neuser    * @return  bool
28686e0f1b9SPhilipp Neuser    */
28786e0f1b9SPhilipp Neuser    public function modifyUser($user, $changes) {
288d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('UserMod') ) {
289d9c5261fSeinhirn            return $this->usermanager_auth->modifyUser($user, $changes);
29086e0f1b9SPhilipp Neuser        } else {
29132fe206aSeinhirn            msg("authorisation method does not allow modifying of user data", -1);
292d9c5261fSeinhirn            return null;
29386e0f1b9SPhilipp Neuser        }
29486e0f1b9SPhilipp Neuser    }
29586e0f1b9SPhilipp Neuser
29686e0f1b9SPhilipp Neuser    /**
29786e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
29886e0f1b9SPhilipp Neuser    * returns false
29986e0f1b9SPhilipp Neuser    *
30086e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
301d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
30286e0f1b9SPhilipp Neuser    * @param   array  $users
30386e0f1b9SPhilipp Neuser    * @return  int    number of users deleted
30486e0f1b9SPhilipp Neuser    */
30586e0f1b9SPhilipp Neuser    public function deleteUsers($users) {
306d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('delUser') ) {
307d9c5261fSeinhirn            return $this->usermanager_auth->deleteUsers($users);
30886e0f1b9SPhilipp Neuser        }else{
30986e0f1b9SPhilipp Neuser            msg("authorisation method does not allow deleting of users", -1);
31086e0f1b9SPhilipp Neuser            return false;
31186e0f1b9SPhilipp Neuser        }
31286e0f1b9SPhilipp Neuser    }
31386e0f1b9SPhilipp Neuser
31486e0f1b9SPhilipp Neuser    /**
31586e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
31686e0f1b9SPhilipp Neuser    * returns 0
31786e0f1b9SPhilipp Neuser    *
31886e0f1b9SPhilipp Neuser    * @author Philipp Neuser <pneuser@physik.fu-berlin.de>
319d9c5261fSeinhirn    * @author Christian Marg <marg@rz.tu-clausthal.de>
32086e0f1b9SPhilipp Neuser    * @param  array $filter array of field/pattern pairs, empty array for no filter
32186e0f1b9SPhilipp Neuser    * @return int
32286e0f1b9SPhilipp Neuser    */
32386e0f1b9SPhilipp Neuser    public function getUserCount($filter = array()) {
324d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('getUserCount') ){
325d9c5261fSeinhirn            return $this->usermanager_auth->getUserCount($filter);
32686e0f1b9SPhilipp Neuser        } else {
32786e0f1b9SPhilipp Neuser            msg("authorisation method does not provide user counts", -1);
32886e0f1b9SPhilipp Neuser            return 0;
32986e0f1b9SPhilipp Neuser        }
33086e0f1b9SPhilipp Neuser    }
33186e0f1b9SPhilipp Neuser
33286e0f1b9SPhilipp Neuser    /**
33386e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
33486e0f1b9SPhilipp Neuser    * returns empty array
33586e0f1b9SPhilipp Neuser    *
33686e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
337d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
33886e0f1b9SPhilipp Neuser    * @param   int   $start     index of first user to be returned
33986e0f1b9SPhilipp Neuser    * @param   int   $limit     max number of users to be returned
34086e0f1b9SPhilipp Neuser    * @param   array $filter    array of field/pattern pairs, null for no filter
34186e0f1b9SPhilipp Neuser    * @return  array list of userinfo (refer getUserData for internal userinfo details)
34286e0f1b9SPhilipp Neuser    */
34386e0f1b9SPhilipp Neuser    public function retrieveUsers($start = 0, $limit = -1, $filter = null) {
344d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('getUsers') ) {
345d9c5261fSeinhirn            //msg("RetrieveUsers is using ".get_class($this->usermanager_auth));
346d9c5261fSeinhirn            return $this->usermanager_auth->retrieveUsers($start, $limit, $filter);
34786e0f1b9SPhilipp Neuser        } else {
34886e0f1b9SPhilipp Neuser            msg("authorisation method does not support mass retrievals", -1);
34986e0f1b9SPhilipp Neuser            return array();
35086e0f1b9SPhilipp Neuser        }
35186e0f1b9SPhilipp Neuser    }
35286e0f1b9SPhilipp Neuser
35386e0f1b9SPhilipp Neuser    /**
35486e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
35586e0f1b9SPhilipp Neuser    * returns false
35686e0f1b9SPhilipp Neuser    *
35786e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
358d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
35986e0f1b9SPhilipp Neuser    * @param   string $group
36086e0f1b9SPhilipp Neuser    * @return  bool
36186e0f1b9SPhilipp Neuser    */
36286e0f1b9SPhilipp Neuser    public function addGroup($group) {
363d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('addGroup') ) {
364d9c5261fSeinhirn            return $this->usermanager_auth->addGroup($group);
36586e0f1b9SPhilipp Neuser        } else {
36632fe206aSeinhirn            msg("authorisation method does not support independent group creation", -1);
36786e0f1b9SPhilipp Neuser            return false;
36886e0f1b9SPhilipp Neuser        }
36986e0f1b9SPhilipp Neuser    }
37086e0f1b9SPhilipp Neuser
37186e0f1b9SPhilipp Neuser    /**
37286e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
37386e0f1b9SPhilipp Neuser    * returns empty array
37486e0f1b9SPhilipp Neuser    *
37586e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
376d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
37786e0f1b9SPhilipp Neuser    * @param   int $start
37886e0f1b9SPhilipp Neuser    * @param   int $limit
37986e0f1b9SPhilipp Neuser    * @return  array
38086e0f1b9SPhilipp Neuser    */
38186e0f1b9SPhilipp Neuser    public function retrieveGroups($start = 0, $limit = 0) {
382d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('getGroups') ) {
383d9c5261fSeinhirn                return $this->usermanager_auth->retrieveGroups($start,$limit);
38486e0f1b9SPhilipp Neuser        } else {
38532fe206aSeinhirn            msg("authorisation method does not support group list retrieval", -1);
38686e0f1b9SPhilipp Neuser            return array();
38786e0f1b9SPhilipp Neuser        }
38886e0f1b9SPhilipp Neuser    }
38986e0f1b9SPhilipp Neuser
39086e0f1b9SPhilipp Neuser    /**
39186e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
39286e0f1b9SPhilipp Neuser    * returns true
39386e0f1b9SPhilipp Neuser    *
39486e0f1b9SPhilipp Neuser    * @return bool
39586e0f1b9SPhilipp Neuser    */
39686e0f1b9SPhilipp Neuser    public function isCaseSensitive() {
39786e0f1b9SPhilipp Neuser        if(is_null($this->chained_auth))
398d9c5261fSeinhirn            return parent::isCaseSensitive();
39986e0f1b9SPhilipp Neuser        else
40086e0f1b9SPhilipp Neuser            return $this->chained_auth->isCaseSensitive();
40186e0f1b9SPhilipp Neuser    }
40286e0f1b9SPhilipp Neuser
40386e0f1b9SPhilipp Neuser    /**
40486e0f1b9SPhilipp Neuser    * Sanitize a given username [OPTIONAL]
40586e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
40686e0f1b9SPhilipp Neuser    * returns false
40786e0f1b9SPhilipp Neuser    *
40886e0f1b9SPhilipp Neuser    *
40986e0f1b9SPhilipp Neuser    * @author Philipp Neuser <pneuser@physik.fu-berlin.de>
410d9c5261fSeinhirn    * @author Christian Marg <marg@rz.tu-clausthal.de>
41186e0f1b9SPhilipp Neuser    * @param  string $user username
41286e0f1b9SPhilipp Neuser    * @return string the cleaned username
41386e0f1b9SPhilipp Neuser    */
41486e0f1b9SPhilipp Neuser    public function cleanUser($user) {
415d9c5261fSeinhirn        global $ACT;
41686e0f1b9SPhilipp Neuser        //print_r($this->chained_auth);
417d9c5261fSeinhirn        if ($ACT == "admin" && $_REQUEST['page']=="usermanager") {
418d9c5261fSeinhirn            if(!is_null($this->usermanager_auth))
419d9c5261fSeinhirn                return $this->usermanager_auth->cleanUser($user);
420d9c5261fSeinhirn        } else {
421d9c5261fSeinhirn            if(!is_null($this->chained_auth))
42286e0f1b9SPhilipp Neuser                return $this->chained_auth->cleanUser($user);
42386e0f1b9SPhilipp Neuser        }
424d9c5261fSeinhirn        return parent::cleanUser($user);
425d9c5261fSeinhirn    }
42686e0f1b9SPhilipp Neuser
42786e0f1b9SPhilipp Neuser    /**
42886e0f1b9SPhilipp Neuser    * Sanitize a given groupname [OPTIONAL]
42986e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
43086e0f1b9SPhilipp Neuser    * returns false
43186e0f1b9SPhilipp Neuser    *
43286e0f1b9SPhilipp Neuser    * @author Philipp Neuser <pneuser@physik.fu-berlin.de>
433d9c5261fSeinhirn    * @author Christian Marg <marg@rz.tu-clausthal.de>
43486e0f1b9SPhilipp Neuser    * @param  string $group groupname
43586e0f1b9SPhilipp Neuser    * @return string the cleaned groupname
43686e0f1b9SPhilipp Neuser    */
43786e0f1b9SPhilipp Neuser    public function cleanGroup($group) {
438d9c5261fSeinhirn        global $ACT;
439d9c5261fSeinhirn        if ($ACT == "admin" && $_REQUEST['page']=="usermanager") {
440d9c5261fSeinhirn            if(!is_null($this->usermanager_auth))
441d9c5261fSeinhirn                return $this->usermanager_auth->cleanGroup($group);
44232fe206aSeinhirn        } else {
443d9c5261fSeinhirn            if(!is_null($this->chained_auth))
44486e0f1b9SPhilipp Neuser                return $this->chained_auth->cleanGroup($group);
44586e0f1b9SPhilipp Neuser        }
446d9c5261fSeinhirn        return parent::cleanGroup($group);
44732fe206aSeinhirn    }
44886e0f1b9SPhilipp Neuser
44986e0f1b9SPhilipp Neuser
45086e0f1b9SPhilipp Neuser    public function useSessionCache($user) {
45186e0f1b9SPhilipp Neuser        global $conf;
45286e0f1b9SPhilipp Neuser        if(is_null($this->chained_auth))
453d9c5261fSeinhirn            return parent::useSessionCache($user);
45486e0f1b9SPhilipp Neuser        else
45586e0f1b9SPhilipp Neuser            return $this->chained_auth->useSessionCache($user);
45686e0f1b9SPhilipp Neuser    }
457d9c5261fSeinhirn
45886e0f1b9SPhilipp Neuser}
459