xref: /plugin/authchained/auth.php (revision 5db6eafad4e6eb64b87c674e09099fb1d1d972ad)
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;
23a015b733SPawel 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);
58a015b733SPawel 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)) {
98a015b733SPawel Jasinski            if ($cap == "external") {
99a015b733SPawel Jasinski                return $this->any_external;
100a015b733SPawel 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':
110*5db6eafaSPawel Jasinski                case 'external':
111d9c5261fSeinhirn                    //Depends on current user.
112d9c5261fSeinhirn                    return $this->chained_auth->canDo($cap);
113d9c5261fSeinhirn                case 'UserMod':
114d9c5261fSeinhirn                case 'addUser':
115d9c5261fSeinhirn                case 'delUser':
116d9c5261fSeinhirn                case 'getUsers':
117d9c5261fSeinhirn                case 'getUserCount':
118d9c5261fSeinhirn                case 'getGroups':
119d9c5261fSeinhirn                    //Depends on the auth for use with user manager
120d9c5261fSeinhirn                    return $this->usermanager_auth->canDo($cap);
121d9c5261fSeinhirn                case 'modPass':
122d9c5261fSeinhirn                case 'modName':
123d9c5261fSeinhirn                case 'modLogin':
124d9c5261fSeinhirn                case 'modGroups':
125d9c5261fSeinhirn                case 'modMail':
126d9c5261fSeinhirn                    /**
127d9c5261fSeinhirn                    * Use request attributes to guess whether we are in the Profile or UserManager
128d9c5261fSeinhirn                    * and return the appropriate auth capabilities
129d9c5261fSeinhirn                    */
130d9c5261fSeinhirn                    if ($ACT == "admin" && $_REQUEST['page']=="usermanager") {
131d9c5261fSeinhirn                        return $this->usermanager_auth->canDo($cap);
132d9c5261fSeinhirn                    } else {
133d9c5261fSeinhirn                        // assume we want profile info.
13486e0f1b9SPhilipp Neuser                        return $this->chained_auth->canDo($cap);
13586e0f1b9SPhilipp Neuser                    }
136d9c5261fSeinhirn                default:
137d9c5261fSeinhirn                    //Everything else (false)
138d9c5261fSeinhirn                    return parent::canDo($cap);
13986e0f1b9SPhilipp Neuser            }
140d9c5261fSeinhirn            #echo "canDo $cap ".$this->chained_auth->canDo($cap)."\n";
141d9c5261fSeinhirn        }
14286e0f1b9SPhilipp Neuser    }
14386e0f1b9SPhilipp Neuser
14486e0f1b9SPhilipp Neuser    /**
14586e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user and
14686e0f1b9SPhilipp Neuser    * unsets our session variable.
14786e0f1b9SPhilipp Neuser    * @see     auth_logoff()
14886e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de
149d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
15086e0f1b9SPhilipp Neuser    */
15186e0f1b9SPhilipp Neuser    public function logOff() {
15286e0f1b9SPhilipp Neuser        if(!is_null($this->chained_auth))
15386e0f1b9SPhilipp Neuser            $this->chained_auth->logOff();
1549e84dbfbSPhilipp Neuser        unset($_SESSION[DOKU_COOKIE]['plugin']['authchained']['module']);
15586e0f1b9SPhilipp Neuser    }
15686e0f1b9SPhilipp Neuser
15786e0f1b9SPhilipp Neuser    /**
15886e0f1b9SPhilipp Neuser    * Do all authentication [ OPTIONAL ]
15986e0f1b9SPhilipp Neuser    * If the current plugin is external, be external.
16086e0f1b9SPhilipp Neuser    *
16186e0f1b9SPhilipp Neuser    * @see     auth_login()
16286e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
163d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
16486e0f1b9SPhilipp Neuser    *
16586e0f1b9SPhilipp Neuser    * @param   string  $user    Username
16686e0f1b9SPhilipp Neuser    * @param   string  $pass    Cleartext Password
16786e0f1b9SPhilipp Neuser    * @param   bool    $sticky  Cookie should not expire
16886e0f1b9SPhilipp Neuser    * @return  bool             true on successful auth
16986e0f1b9SPhilipp Neuser    */
17086e0f1b9SPhilipp Neuser    public function trustExternal($user, $pass, $sticky = false) {
171a015b733SPawel Jasinski        foreach($this->chained_plugins as $module) {
172*5db6eafaSPawel Jasinski            if($module[1]->canDo('external') && $module[1]->trustExternal($user, $pass, $sticky)) {
173a015b733SPawel Jasinski                $_SESSION[DOKU_COOKIE]['plugin']['authchained']['module'] = $module[0];
174a015b733SPawel Jasinski                $this->chained_auth = $module[1];
175a015b733SPawel Jasinski                return true;
176a015b733SPawel Jasinski            }
177a015b733SPawel Jasinski        }
178a015b733SPawel Jasinski        return false;
17986e0f1b9SPhilipp Neuser    }
18086e0f1b9SPhilipp Neuser
18186e0f1b9SPhilipp Neuser    /**
18286e0f1b9SPhilipp Neuser    * Check user+password [ MUST BE OVERRIDDEN ]
18386e0f1b9SPhilipp Neuser    *
18486e0f1b9SPhilipp Neuser    * Checks if the given user exists in one of the plugins and checks
18586e0f1b9SPhilipp Neuser    * against the given password. The first plugin returning true becomes
18686e0f1b9SPhilipp Neuser    * auth plugin of the user session.
18786e0f1b9SPhilipp Neuser    *
18886e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de
189d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
19086e0f1b9SPhilipp Neuser    * @param   string $user the user name
19186e0f1b9SPhilipp Neuser    * @param   string $pass the clear text password
19286e0f1b9SPhilipp Neuser    * @return  bool
19386e0f1b9SPhilipp Neuser    */
19486e0f1b9SPhilipp Neuser    public function checkPass($user, $pass) {
19586e0f1b9SPhilipp Neuser        //debug
19686e0f1b9SPhilipp Neuser        // print_r($this->chained_plugins);
197fca3c6d7SPawel Jasinski        if(!is_null($this->chained_auth))
19832fe206aSeinhirn            return $this->chained_auth->checkPass($user, $pass);
199fca3c6d7SPawel Jasinski        foreach($this->chained_plugins as $module) {
200fca3c6d7SPawel Jasinski            if($module[1]->canDo('external') && $module[1]->trustExternal($user, $pass)) {
201fca3c6d7SPawel Jasinski                $_SESSION[DOKU_COOKIE]['plugin']['authchained']['module'] = $module[0];
202fca3c6d7SPawel Jasinski                $this->chained_auth = $module[1];
203fca3c6d7SPawel Jasinski                return true;
204fca3c6d7SPawel Jasinski            }
205fca3c6d7SPawel Jasinski            if($module[1]->checkPass($user, $pass)) {
206fca3c6d7SPawel Jasinski                $_SESSION[DOKU_COOKIE]['plugin']['authchained']['module'] = $module[0];
207fca3c6d7SPawel Jasinski                $this->chained_auth = $module[1];
208fca3c6d7SPawel Jasinski                return true;
209fca3c6d7SPawel Jasinski            }
21032fe206aSeinhirn        }
21186e0f1b9SPhilipp Neuser        return false;
21286e0f1b9SPhilipp Neuser    }
21386e0f1b9SPhilipp Neuser
21486e0f1b9SPhilipp Neuser    /**
21586e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
21686e0f1b9SPhilipp Neuser    * checks all plugins if the users exists. The first plugin returning
21786e0f1b9SPhilipp Neuser    * data is used.
21886e0f1b9SPhilipp Neuser    *
21986e0f1b9SPhilipp Neuser    * name string  full name of the user
22086e0f1b9SPhilipp Neuser    * mail string  email addres of the user
22186e0f1b9SPhilipp Neuser    * grps array   list of groups the user is in
22286e0f1b9SPhilipp Neuser    *
22386e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
224d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
22586e0f1b9SPhilipp Neuser    * @param   string $user the user name
22686e0f1b9SPhilipp Neuser    * @return  array containing user data or false
22786e0f1b9SPhilipp Neuser    */
228c27cbb90Srnck    public function getUserData($user, $requireGroups=true) {
22912767e67SEmmanuel Collignon        global $ACT, $INPUT;
23012767e67SEmmanuel Collignon
23186e0f1b9SPhilipp Neuser        //if(!$this->cando['external']) msg("no valid authorisation system in use", -1);
23286e0f1b9SPhilipp Neuser        //       echo "TESTSETEST";
2331b39d8c6Seinhirn
2341b39d8c6Seinhirn        //print_r($this->chained_auth);
2351b39d8c6Seinhirn        if ($ACT == "admin" && $_REQUEST['page']=="usermanager") {
2361b39d8c6Seinhirn            if(!is_null($this->usermanager_auth))
2371b39d8c6Seinhirn                return $this->usermanager_auth->getUserData($user);
2384e6f1bb5Seinhirn	}
2391b39d8c6Seinhirn
2409ad8d9f1Seinhirn        if(is_null($this->chained_auth)||(!is_null($INPUT->server) && $user != $INPUT->server->str('REMOTE_USER'))) {
24132fe206aSeinhirn            foreach($this->chained_plugins as $module) {
24286e0f1b9SPhilipp Neuser                $tmp_array = $module[1]->getUserData($user);
24386e0f1b9SPhilipp Neuser                if(!is_bool($tmp_array))
24486e0f1b9SPhilipp Neuser                    $tmp_chk_arr =array_filter($tmp_array);
24586e0f1b9SPhilipp Neuser                if(!empty($tmp_chk_arr) && $tmp_array)
24686e0f1b9SPhilipp Neuser                    return $tmp_array;
24786e0f1b9SPhilipp Neuser            }
24886e0f1b9SPhilipp Neuser            return false;
24932fe206aSeinhirn        } else {
25086e0f1b9SPhilipp Neuser            return $this->chained_auth->getUserData($user);
25186e0f1b9SPhilipp Neuser        }
25286e0f1b9SPhilipp Neuser    }
25386e0f1b9SPhilipp Neuser
25486e0f1b9SPhilipp Neuser    /**
25586e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
25686e0f1b9SPhilipp Neuser    * returns null.
25786e0f1b9SPhilipp Neuser    *
25886e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
259d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
26086e0f1b9SPhilipp Neuser    * @param   string     $user
26186e0f1b9SPhilipp Neuser    * @param   string     $pass
26286e0f1b9SPhilipp Neuser    * @param   string     $name
26386e0f1b9SPhilipp Neuser    * @param   string     $mail
26486e0f1b9SPhilipp Neuser    * @param   null|array $grps
26586e0f1b9SPhilipp Neuser    * @return  bool|null
26686e0f1b9SPhilipp Neuser    */
26786e0f1b9SPhilipp Neuser    public function createUser($user, $pass, $name, $mail, $grps = null) {
268d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('addUser')) {
269d9c5261fSeinhirn            return $this->usermanager_auth->createUser($user, $pass, $name, $mail, $grps);
27086e0f1b9SPhilipp Neuser        } else {
27132fe206aSeinhirn            msg("authorisation method does not allow creation of new users", -1);
27286e0f1b9SPhilipp Neuser            return null;
27386e0f1b9SPhilipp Neuser        }
27486e0f1b9SPhilipp Neuser    }
27586e0f1b9SPhilipp Neuser
27686e0f1b9SPhilipp Neuser    /**
27786e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
27886e0f1b9SPhilipp Neuser    * returns false
27986e0f1b9SPhilipp Neuser    *
28086e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
281d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
28286e0f1b9SPhilipp Neuser    * @param   string $user    nick of the user to be changed
28386e0f1b9SPhilipp Neuser    * @param   array  $changes array of field/value pairs to be changed (password will be clear text)
28486e0f1b9SPhilipp Neuser    * @return  bool
28586e0f1b9SPhilipp Neuser    */
28686e0f1b9SPhilipp Neuser    public function modifyUser($user, $changes) {
287d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('UserMod') ) {
288d9c5261fSeinhirn            return $this->usermanager_auth->modifyUser($user, $changes);
28986e0f1b9SPhilipp Neuser        } else {
29032fe206aSeinhirn            msg("authorisation method does not allow modifying of user data", -1);
291d9c5261fSeinhirn            return null;
29286e0f1b9SPhilipp Neuser        }
29386e0f1b9SPhilipp Neuser    }
29486e0f1b9SPhilipp Neuser
29586e0f1b9SPhilipp Neuser    /**
29686e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
29786e0f1b9SPhilipp Neuser    * returns false
29886e0f1b9SPhilipp Neuser    *
29986e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
300d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
30186e0f1b9SPhilipp Neuser    * @param   array  $users
30286e0f1b9SPhilipp Neuser    * @return  int    number of users deleted
30386e0f1b9SPhilipp Neuser    */
30486e0f1b9SPhilipp Neuser    public function deleteUsers($users) {
305d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('delUser') ) {
306d9c5261fSeinhirn            return $this->usermanager_auth->deleteUsers($users);
30786e0f1b9SPhilipp Neuser        }else{
30886e0f1b9SPhilipp Neuser            msg("authorisation method does not allow deleting of users", -1);
30986e0f1b9SPhilipp Neuser            return false;
31086e0f1b9SPhilipp Neuser        }
31186e0f1b9SPhilipp Neuser    }
31286e0f1b9SPhilipp Neuser
31386e0f1b9SPhilipp Neuser    /**
31486e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
31586e0f1b9SPhilipp Neuser    * returns 0
31686e0f1b9SPhilipp Neuser    *
31786e0f1b9SPhilipp Neuser    * @author Philipp Neuser <pneuser@physik.fu-berlin.de>
318d9c5261fSeinhirn    * @author Christian Marg <marg@rz.tu-clausthal.de>
31986e0f1b9SPhilipp Neuser    * @param  array $filter array of field/pattern pairs, empty array for no filter
32086e0f1b9SPhilipp Neuser    * @return int
32186e0f1b9SPhilipp Neuser    */
32286e0f1b9SPhilipp Neuser    public function getUserCount($filter = array()) {
323d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('getUserCount') ){
324d9c5261fSeinhirn            return $this->usermanager_auth->getUserCount($filter);
32586e0f1b9SPhilipp Neuser        } else {
32686e0f1b9SPhilipp Neuser            msg("authorisation method does not provide user counts", -1);
32786e0f1b9SPhilipp Neuser            return 0;
32886e0f1b9SPhilipp Neuser        }
32986e0f1b9SPhilipp Neuser    }
33086e0f1b9SPhilipp Neuser
33186e0f1b9SPhilipp Neuser    /**
33286e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
33386e0f1b9SPhilipp Neuser    * returns empty array
33486e0f1b9SPhilipp Neuser    *
33586e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
336d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
33786e0f1b9SPhilipp Neuser    * @param   int   $start     index of first user to be returned
33886e0f1b9SPhilipp Neuser    * @param   int   $limit     max number of users to be returned
33986e0f1b9SPhilipp Neuser    * @param   array $filter    array of field/pattern pairs, null for no filter
34086e0f1b9SPhilipp Neuser    * @return  array list of userinfo (refer getUserData for internal userinfo details)
34186e0f1b9SPhilipp Neuser    */
34286e0f1b9SPhilipp Neuser    public function retrieveUsers($start = 0, $limit = -1, $filter = null) {
343d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('getUsers') ) {
344d9c5261fSeinhirn            //msg("RetrieveUsers is using ".get_class($this->usermanager_auth));
345d9c5261fSeinhirn            return $this->usermanager_auth->retrieveUsers($start, $limit, $filter);
34686e0f1b9SPhilipp Neuser        } else {
34786e0f1b9SPhilipp Neuser            msg("authorisation method does not support mass retrievals", -1);
34886e0f1b9SPhilipp Neuser            return array();
34986e0f1b9SPhilipp Neuser        }
35086e0f1b9SPhilipp Neuser    }
35186e0f1b9SPhilipp Neuser
35286e0f1b9SPhilipp Neuser    /**
35386e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
35486e0f1b9SPhilipp Neuser    * returns false
35586e0f1b9SPhilipp Neuser    *
35686e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
357d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
35886e0f1b9SPhilipp Neuser    * @param   string $group
35986e0f1b9SPhilipp Neuser    * @return  bool
36086e0f1b9SPhilipp Neuser    */
36186e0f1b9SPhilipp Neuser    public function addGroup($group) {
362d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('addGroup') ) {
363d9c5261fSeinhirn            return $this->usermanager_auth->addGroup($group);
36486e0f1b9SPhilipp Neuser        } else {
36532fe206aSeinhirn            msg("authorisation method does not support independent group creation", -1);
36686e0f1b9SPhilipp Neuser            return false;
36786e0f1b9SPhilipp Neuser        }
36886e0f1b9SPhilipp Neuser    }
36986e0f1b9SPhilipp Neuser
37086e0f1b9SPhilipp Neuser    /**
37186e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
37286e0f1b9SPhilipp Neuser    * returns empty array
37386e0f1b9SPhilipp Neuser    *
37486e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
375d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
37686e0f1b9SPhilipp Neuser    * @param   int $start
37786e0f1b9SPhilipp Neuser    * @param   int $limit
37886e0f1b9SPhilipp Neuser    * @return  array
37986e0f1b9SPhilipp Neuser    */
38086e0f1b9SPhilipp Neuser    public function retrieveGroups($start = 0, $limit = 0) {
381d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('getGroups') ) {
382d9c5261fSeinhirn                return $this->usermanager_auth->retrieveGroups($start,$limit);
38386e0f1b9SPhilipp Neuser        } else {
38432fe206aSeinhirn            msg("authorisation method does not support group list retrieval", -1);
38586e0f1b9SPhilipp Neuser            return array();
38686e0f1b9SPhilipp Neuser        }
38786e0f1b9SPhilipp Neuser    }
38886e0f1b9SPhilipp Neuser
38986e0f1b9SPhilipp Neuser    /**
39086e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
39186e0f1b9SPhilipp Neuser    * returns true
39286e0f1b9SPhilipp Neuser    *
39386e0f1b9SPhilipp Neuser    * @return bool
39486e0f1b9SPhilipp Neuser    */
39586e0f1b9SPhilipp Neuser    public function isCaseSensitive() {
39686e0f1b9SPhilipp Neuser        if(is_null($this->chained_auth))
397d9c5261fSeinhirn            return parent::isCaseSensitive();
39886e0f1b9SPhilipp Neuser        else
39986e0f1b9SPhilipp Neuser            return $this->chained_auth->isCaseSensitive();
40086e0f1b9SPhilipp Neuser    }
40186e0f1b9SPhilipp Neuser
40286e0f1b9SPhilipp Neuser    /**
40386e0f1b9SPhilipp Neuser    * Sanitize a given username [OPTIONAL]
40486e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
40586e0f1b9SPhilipp Neuser    * returns false
40686e0f1b9SPhilipp Neuser    *
40786e0f1b9SPhilipp Neuser    *
40886e0f1b9SPhilipp Neuser    * @author Philipp Neuser <pneuser@physik.fu-berlin.de>
409d9c5261fSeinhirn    * @author Christian Marg <marg@rz.tu-clausthal.de>
41086e0f1b9SPhilipp Neuser    * @param  string $user username
41186e0f1b9SPhilipp Neuser    * @return string the cleaned username
41286e0f1b9SPhilipp Neuser    */
41386e0f1b9SPhilipp Neuser    public function cleanUser($user) {
414d9c5261fSeinhirn        global $ACT;
41586e0f1b9SPhilipp Neuser        //print_r($this->chained_auth);
416d9c5261fSeinhirn        if ($ACT == "admin" && $_REQUEST['page']=="usermanager") {
417d9c5261fSeinhirn            if(!is_null($this->usermanager_auth))
418d9c5261fSeinhirn                return $this->usermanager_auth->cleanUser($user);
419d9c5261fSeinhirn        } else {
420d9c5261fSeinhirn            if(!is_null($this->chained_auth))
42186e0f1b9SPhilipp Neuser                return $this->chained_auth->cleanUser($user);
42286e0f1b9SPhilipp Neuser        }
423d9c5261fSeinhirn        return parent::cleanUser($user);
424d9c5261fSeinhirn    }
42586e0f1b9SPhilipp Neuser
42686e0f1b9SPhilipp Neuser    /**
42786e0f1b9SPhilipp Neuser    * Sanitize a given groupname [OPTIONAL]
42886e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
42986e0f1b9SPhilipp Neuser    * returns false
43086e0f1b9SPhilipp Neuser    *
43186e0f1b9SPhilipp Neuser    * @author Philipp Neuser <pneuser@physik.fu-berlin.de>
432d9c5261fSeinhirn    * @author Christian Marg <marg@rz.tu-clausthal.de>
43386e0f1b9SPhilipp Neuser    * @param  string $group groupname
43486e0f1b9SPhilipp Neuser    * @return string the cleaned groupname
43586e0f1b9SPhilipp Neuser    */
43686e0f1b9SPhilipp Neuser    public function cleanGroup($group) {
437d9c5261fSeinhirn        global $ACT;
438d9c5261fSeinhirn        if ($ACT == "admin" && $_REQUEST['page']=="usermanager") {
439d9c5261fSeinhirn            if(!is_null($this->usermanager_auth))
440d9c5261fSeinhirn                return $this->usermanager_auth->cleanGroup($group);
44132fe206aSeinhirn        } else {
442d9c5261fSeinhirn            if(!is_null($this->chained_auth))
44386e0f1b9SPhilipp Neuser                return $this->chained_auth->cleanGroup($group);
44486e0f1b9SPhilipp Neuser        }
445d9c5261fSeinhirn        return parent::cleanGroup($group);
44632fe206aSeinhirn    }
44786e0f1b9SPhilipp Neuser
44886e0f1b9SPhilipp Neuser
44986e0f1b9SPhilipp Neuser    public function useSessionCache($user) {
45086e0f1b9SPhilipp Neuser        global $conf;
45186e0f1b9SPhilipp Neuser        if(is_null($this->chained_auth))
452d9c5261fSeinhirn            return parent::useSessionCache($user);
45386e0f1b9SPhilipp Neuser        else
45486e0f1b9SPhilipp Neuser            return $this->chained_auth->useSessionCache($user);
45586e0f1b9SPhilipp Neuser    }
456d9c5261fSeinhirn
45786e0f1b9SPhilipp Neuser}
458