xref: /plugin/authchained/auth.php (revision 4cbfa2dcbe1cd4b6c8401df088992bb6b702bf85)
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':
1105db6eafaSPawel 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                    */
130*4cbfa2dcSUnFefeSauvage                    if ($ACT == "admin" && isset($_REQUEST['page']) && $_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) {
1716fb8fffbSPawel Jasinski        global $INPUT;
172a015b733SPawel Jasinski        foreach($this->chained_plugins as $module) {
1735db6eafaSPawel Jasinski            if($module[1]->canDo('external') && $module[1]->trustExternal($user, $pass, $sticky)) {
174a015b733SPawel Jasinski                $_SESSION[DOKU_COOKIE]['plugin']['authchained']['module'] = $module[0];
175a015b733SPawel Jasinski                $this->chained_auth = $module[1];
176a015b733SPawel Jasinski                return true;
177a015b733SPawel Jasinski            }
178a015b733SPawel Jasinski        }
1796fb8fffbSPawel Jasinski        $evdata = array(
1806fb8fffbSPawel Jasinski            'user'     => $INPUT->str('u'),
1816fb8fffbSPawel Jasinski            'password' => $INPUT->str('p'),
1826fb8fffbSPawel Jasinski            'sticky'   => $INPUT->bool('r'),
1836fb8fffbSPawel Jasinski            'silent'   => $INPUT->bool('http_credentials')
1846fb8fffbSPawel Jasinski        );
1856fb8fffbSPawel Jasinski        trigger_event('AUTH_LOGIN_CHECK', $evdata, 'auth_login_wrapper');
186a015b733SPawel Jasinski        return false;
18786e0f1b9SPhilipp Neuser    }
18886e0f1b9SPhilipp Neuser
18986e0f1b9SPhilipp Neuser    /**
19086e0f1b9SPhilipp Neuser    * Check user+password [ MUST BE OVERRIDDEN ]
19186e0f1b9SPhilipp Neuser    *
19286e0f1b9SPhilipp Neuser    * Checks if the given user exists in one of the plugins and checks
19386e0f1b9SPhilipp Neuser    * against the given password. The first plugin returning true becomes
19486e0f1b9SPhilipp Neuser    * auth plugin of the user session.
19586e0f1b9SPhilipp Neuser    *
19686e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de
197d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
19886e0f1b9SPhilipp Neuser    * @param   string $user the user name
19986e0f1b9SPhilipp Neuser    * @param   string $pass the clear text password
20086e0f1b9SPhilipp Neuser    * @return  bool
20186e0f1b9SPhilipp Neuser    */
20286e0f1b9SPhilipp Neuser    public function checkPass($user, $pass) {
20386e0f1b9SPhilipp Neuser        //debug
20486e0f1b9SPhilipp Neuser        // print_r($this->chained_plugins);
205fca3c6d7SPawel Jasinski        if(!is_null($this->chained_auth))
20632fe206aSeinhirn            return $this->chained_auth->checkPass($user, $pass);
207fca3c6d7SPawel Jasinski        foreach($this->chained_plugins as $module) {
208fca3c6d7SPawel Jasinski            if($module[1]->canDo('external') && $module[1]->trustExternal($user, $pass)) {
209fca3c6d7SPawel Jasinski                $_SESSION[DOKU_COOKIE]['plugin']['authchained']['module'] = $module[0];
210fca3c6d7SPawel Jasinski                $this->chained_auth = $module[1];
211fca3c6d7SPawel Jasinski                return true;
212fca3c6d7SPawel Jasinski            }
213fca3c6d7SPawel Jasinski            if($module[1]->checkPass($user, $pass)) {
214fca3c6d7SPawel Jasinski                $_SESSION[DOKU_COOKIE]['plugin']['authchained']['module'] = $module[0];
215fca3c6d7SPawel Jasinski                $this->chained_auth = $module[1];
216fca3c6d7SPawel Jasinski                return true;
217fca3c6d7SPawel Jasinski            }
21832fe206aSeinhirn        }
21986e0f1b9SPhilipp Neuser        return false;
22086e0f1b9SPhilipp Neuser    }
22186e0f1b9SPhilipp Neuser
22286e0f1b9SPhilipp Neuser    /**
22386e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
22486e0f1b9SPhilipp Neuser    * checks all plugins if the users exists. The first plugin returning
22586e0f1b9SPhilipp Neuser    * data is used.
22686e0f1b9SPhilipp Neuser    *
22786e0f1b9SPhilipp Neuser    * name string  full name of the user
22886e0f1b9SPhilipp Neuser    * mail string  email addres of the user
22986e0f1b9SPhilipp Neuser    * grps array   list of groups the user is in
23086e0f1b9SPhilipp Neuser    *
23186e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
232d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
23386e0f1b9SPhilipp Neuser    * @param   string $user the user name
23486e0f1b9SPhilipp Neuser    * @return  array containing user data or false
23586e0f1b9SPhilipp Neuser    */
236c27cbb90Srnck    public function getUserData($user, $requireGroups=true) {
23712767e67SEmmanuel Collignon        global $ACT, $INPUT;
23812767e67SEmmanuel Collignon
23986e0f1b9SPhilipp Neuser        //if(!$this->cando['external']) msg("no valid authorisation system in use", -1);
24086e0f1b9SPhilipp Neuser        //       echo "TESTSETEST";
2411b39d8c6Seinhirn
2421b39d8c6Seinhirn        //print_r($this->chained_auth);
243*4cbfa2dcSUnFefeSauvage        if ($ACT == "admin" && isset($_REQUEST['page']) && $_REQUEST['page']=="usermanager") {
2441b39d8c6Seinhirn            if(!is_null($this->usermanager_auth))
2451b39d8c6Seinhirn                return $this->usermanager_auth->getUserData($user);
2464e6f1bb5Seinhirn	}
2471b39d8c6Seinhirn
2489ad8d9f1Seinhirn        if(is_null($this->chained_auth)||(!is_null($INPUT->server) && $user != $INPUT->server->str('REMOTE_USER'))) {
24932fe206aSeinhirn            foreach($this->chained_plugins as $module) {
25086e0f1b9SPhilipp Neuser                $tmp_array = $module[1]->getUserData($user);
25186e0f1b9SPhilipp Neuser                if(!is_bool($tmp_array))
25286e0f1b9SPhilipp Neuser                    $tmp_chk_arr =array_filter($tmp_array);
25386e0f1b9SPhilipp Neuser                if(!empty($tmp_chk_arr) && $tmp_array)
25486e0f1b9SPhilipp Neuser                    return $tmp_array;
25586e0f1b9SPhilipp Neuser            }
25686e0f1b9SPhilipp Neuser            return false;
25732fe206aSeinhirn        } else {
25886e0f1b9SPhilipp Neuser            return $this->chained_auth->getUserData($user);
25986e0f1b9SPhilipp Neuser        }
26086e0f1b9SPhilipp Neuser    }
26186e0f1b9SPhilipp Neuser
26286e0f1b9SPhilipp Neuser    /**
26386e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
26486e0f1b9SPhilipp Neuser    * returns null.
26586e0f1b9SPhilipp Neuser    *
26686e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
267d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
26886e0f1b9SPhilipp Neuser    * @param   string     $user
26986e0f1b9SPhilipp Neuser    * @param   string     $pass
27086e0f1b9SPhilipp Neuser    * @param   string     $name
27186e0f1b9SPhilipp Neuser    * @param   string     $mail
27286e0f1b9SPhilipp Neuser    * @param   null|array $grps
27386e0f1b9SPhilipp Neuser    * @return  bool|null
27486e0f1b9SPhilipp Neuser    */
27586e0f1b9SPhilipp Neuser    public function createUser($user, $pass, $name, $mail, $grps = null) {
276d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('addUser')) {
277d9c5261fSeinhirn            return $this->usermanager_auth->createUser($user, $pass, $name, $mail, $grps);
27886e0f1b9SPhilipp Neuser        } else {
27932fe206aSeinhirn            msg("authorisation method does not allow creation of new users", -1);
28086e0f1b9SPhilipp Neuser            return null;
28186e0f1b9SPhilipp Neuser        }
28286e0f1b9SPhilipp Neuser    }
28386e0f1b9SPhilipp Neuser
28486e0f1b9SPhilipp Neuser    /**
28586e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
28686e0f1b9SPhilipp Neuser    * returns false
28786e0f1b9SPhilipp Neuser    *
28886e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
289d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
29086e0f1b9SPhilipp Neuser    * @param   string $user    nick of the user to be changed
29186e0f1b9SPhilipp Neuser    * @param   array  $changes array of field/value pairs to be changed (password will be clear text)
29286e0f1b9SPhilipp Neuser    * @return  bool
29386e0f1b9SPhilipp Neuser    */
29486e0f1b9SPhilipp Neuser    public function modifyUser($user, $changes) {
295d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('UserMod') ) {
296d9c5261fSeinhirn            return $this->usermanager_auth->modifyUser($user, $changes);
29786e0f1b9SPhilipp Neuser        } else {
29832fe206aSeinhirn            msg("authorisation method does not allow modifying of user data", -1);
299d9c5261fSeinhirn            return null;
30086e0f1b9SPhilipp Neuser        }
30186e0f1b9SPhilipp Neuser    }
30286e0f1b9SPhilipp Neuser
30386e0f1b9SPhilipp Neuser    /**
30486e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
30586e0f1b9SPhilipp Neuser    * returns false
30686e0f1b9SPhilipp Neuser    *
30786e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
308d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
30986e0f1b9SPhilipp Neuser    * @param   array  $users
31086e0f1b9SPhilipp Neuser    * @return  int    number of users deleted
31186e0f1b9SPhilipp Neuser    */
31286e0f1b9SPhilipp Neuser    public function deleteUsers($users) {
313d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('delUser') ) {
314d9c5261fSeinhirn            return $this->usermanager_auth->deleteUsers($users);
31586e0f1b9SPhilipp Neuser        }else{
31686e0f1b9SPhilipp Neuser            msg("authorisation method does not allow deleting of users", -1);
31786e0f1b9SPhilipp Neuser            return false;
31886e0f1b9SPhilipp Neuser        }
31986e0f1b9SPhilipp Neuser    }
32086e0f1b9SPhilipp Neuser
32186e0f1b9SPhilipp Neuser    /**
32286e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
32386e0f1b9SPhilipp Neuser    * returns 0
32486e0f1b9SPhilipp Neuser    *
32586e0f1b9SPhilipp Neuser    * @author Philipp Neuser <pneuser@physik.fu-berlin.de>
326d9c5261fSeinhirn    * @author Christian Marg <marg@rz.tu-clausthal.de>
32786e0f1b9SPhilipp Neuser    * @param  array $filter array of field/pattern pairs, empty array for no filter
32886e0f1b9SPhilipp Neuser    * @return int
32986e0f1b9SPhilipp Neuser    */
33086e0f1b9SPhilipp Neuser    public function getUserCount($filter = array()) {
331d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('getUserCount') ){
332d9c5261fSeinhirn            return $this->usermanager_auth->getUserCount($filter);
33386e0f1b9SPhilipp Neuser        } else {
33486e0f1b9SPhilipp Neuser            msg("authorisation method does not provide user counts", -1);
33586e0f1b9SPhilipp Neuser            return 0;
33686e0f1b9SPhilipp Neuser        }
33786e0f1b9SPhilipp Neuser    }
33886e0f1b9SPhilipp Neuser
33986e0f1b9SPhilipp Neuser    /**
34086e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
34186e0f1b9SPhilipp Neuser    * returns empty array
34286e0f1b9SPhilipp Neuser    *
34386e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
344d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
34586e0f1b9SPhilipp Neuser    * @param   int   $start     index of first user to be returned
34686e0f1b9SPhilipp Neuser    * @param   int   $limit     max number of users to be returned
34786e0f1b9SPhilipp Neuser    * @param   array $filter    array of field/pattern pairs, null for no filter
34886e0f1b9SPhilipp Neuser    * @return  array list of userinfo (refer getUserData for internal userinfo details)
34986e0f1b9SPhilipp Neuser    */
35086e0f1b9SPhilipp Neuser    public function retrieveUsers($start = 0, $limit = -1, $filter = null) {
351d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('getUsers') ) {
352d9c5261fSeinhirn            //msg("RetrieveUsers is using ".get_class($this->usermanager_auth));
353d9c5261fSeinhirn            return $this->usermanager_auth->retrieveUsers($start, $limit, $filter);
35486e0f1b9SPhilipp Neuser        } else {
35586e0f1b9SPhilipp Neuser            msg("authorisation method does not support mass retrievals", -1);
35686e0f1b9SPhilipp Neuser            return array();
35786e0f1b9SPhilipp Neuser        }
35886e0f1b9SPhilipp Neuser    }
35986e0f1b9SPhilipp Neuser
36086e0f1b9SPhilipp Neuser    /**
36186e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
36286e0f1b9SPhilipp Neuser    * returns false
36386e0f1b9SPhilipp Neuser    *
36486e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
365d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
36686e0f1b9SPhilipp Neuser    * @param   string $group
36786e0f1b9SPhilipp Neuser    * @return  bool
36886e0f1b9SPhilipp Neuser    */
36986e0f1b9SPhilipp Neuser    public function addGroup($group) {
370d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('addGroup') ) {
371d9c5261fSeinhirn            return $this->usermanager_auth->addGroup($group);
37286e0f1b9SPhilipp Neuser        } else {
37332fe206aSeinhirn            msg("authorisation method does not support independent group creation", -1);
37486e0f1b9SPhilipp Neuser            return false;
37586e0f1b9SPhilipp Neuser        }
37686e0f1b9SPhilipp Neuser    }
37786e0f1b9SPhilipp Neuser
37886e0f1b9SPhilipp Neuser    /**
37986e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
38086e0f1b9SPhilipp Neuser    * returns empty array
38186e0f1b9SPhilipp Neuser    *
38286e0f1b9SPhilipp Neuser    * @author  Philipp Neuser <pneuser@physik.fu-berlin.de>
383d9c5261fSeinhirn    * @author  Christian Marg <marg@rz.tu-clausthal.de>
38486e0f1b9SPhilipp Neuser    * @param   int $start
38586e0f1b9SPhilipp Neuser    * @param   int $limit
38686e0f1b9SPhilipp Neuser    * @return  array
38786e0f1b9SPhilipp Neuser    */
38886e0f1b9SPhilipp Neuser    public function retrieveGroups($start = 0, $limit = 0) {
389d9c5261fSeinhirn        if(!is_null($this->usermanager_auth) && $this->canDo('getGroups') ) {
390d9c5261fSeinhirn                return $this->usermanager_auth->retrieveGroups($start,$limit);
39186e0f1b9SPhilipp Neuser        } else {
39232fe206aSeinhirn            msg("authorisation method does not support group list retrieval", -1);
39386e0f1b9SPhilipp Neuser            return array();
39486e0f1b9SPhilipp Neuser        }
39586e0f1b9SPhilipp Neuser    }
39686e0f1b9SPhilipp Neuser
39786e0f1b9SPhilipp Neuser    /**
39886e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
39986e0f1b9SPhilipp Neuser    * returns true
40086e0f1b9SPhilipp Neuser    *
40186e0f1b9SPhilipp Neuser    * @return bool
40286e0f1b9SPhilipp Neuser    */
40386e0f1b9SPhilipp Neuser    public function isCaseSensitive() {
40486e0f1b9SPhilipp Neuser        if(is_null($this->chained_auth))
405d9c5261fSeinhirn            return parent::isCaseSensitive();
40686e0f1b9SPhilipp Neuser        else
40786e0f1b9SPhilipp Neuser            return $this->chained_auth->isCaseSensitive();
40886e0f1b9SPhilipp Neuser    }
40986e0f1b9SPhilipp Neuser
41086e0f1b9SPhilipp Neuser    /**
41186e0f1b9SPhilipp Neuser    * Sanitize a given username [OPTIONAL]
41286e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
41386e0f1b9SPhilipp Neuser    * returns false
41486e0f1b9SPhilipp Neuser    *
41586e0f1b9SPhilipp Neuser    *
41686e0f1b9SPhilipp Neuser    * @author Philipp Neuser <pneuser@physik.fu-berlin.de>
417d9c5261fSeinhirn    * @author Christian Marg <marg@rz.tu-clausthal.de>
41886e0f1b9SPhilipp Neuser    * @param  string $user username
41986e0f1b9SPhilipp Neuser    * @return string the cleaned username
42086e0f1b9SPhilipp Neuser    */
42186e0f1b9SPhilipp Neuser    public function cleanUser($user) {
422d9c5261fSeinhirn        global $ACT;
42386e0f1b9SPhilipp Neuser        //print_r($this->chained_auth);
424*4cbfa2dcSUnFefeSauvage        if ($ACT == "admin" && isset($_REQUEST['page']) && $_REQUEST['page']=="usermanager") {
425d9c5261fSeinhirn            if(!is_null($this->usermanager_auth))
426d9c5261fSeinhirn                return $this->usermanager_auth->cleanUser($user);
427d9c5261fSeinhirn        } else {
428d9c5261fSeinhirn            if(!is_null($this->chained_auth))
42986e0f1b9SPhilipp Neuser                return $this->chained_auth->cleanUser($user);
43086e0f1b9SPhilipp Neuser        }
431d9c5261fSeinhirn        return parent::cleanUser($user);
432d9c5261fSeinhirn    }
43386e0f1b9SPhilipp Neuser
43486e0f1b9SPhilipp Neuser    /**
43586e0f1b9SPhilipp Neuser    * Sanitize a given groupname [OPTIONAL]
43686e0f1b9SPhilipp Neuser    * Forwards the result of the auth plugin of the logged in user or
43786e0f1b9SPhilipp Neuser    * returns false
43886e0f1b9SPhilipp Neuser    *
43986e0f1b9SPhilipp Neuser    * @author Philipp Neuser <pneuser@physik.fu-berlin.de>
440d9c5261fSeinhirn    * @author Christian Marg <marg@rz.tu-clausthal.de>
44186e0f1b9SPhilipp Neuser    * @param  string $group groupname
44286e0f1b9SPhilipp Neuser    * @return string the cleaned groupname
44386e0f1b9SPhilipp Neuser    */
44486e0f1b9SPhilipp Neuser    public function cleanGroup($group) {
445d9c5261fSeinhirn        global $ACT;
446*4cbfa2dcSUnFefeSauvage        if ($ACT == "admin" && isset($_REQUEST['page']) && $_REQUEST['page']=="usermanager") {
447d9c5261fSeinhirn            if(!is_null($this->usermanager_auth))
448d9c5261fSeinhirn                return $this->usermanager_auth->cleanGroup($group);
44932fe206aSeinhirn        } else {
450d9c5261fSeinhirn            if(!is_null($this->chained_auth))
45186e0f1b9SPhilipp Neuser                return $this->chained_auth->cleanGroup($group);
45286e0f1b9SPhilipp Neuser        }
453d9c5261fSeinhirn        return parent::cleanGroup($group);
45432fe206aSeinhirn    }
45586e0f1b9SPhilipp Neuser
45686e0f1b9SPhilipp Neuser
45786e0f1b9SPhilipp Neuser    public function useSessionCache($user) {
45886e0f1b9SPhilipp Neuser        global $conf;
45986e0f1b9SPhilipp Neuser        if(is_null($this->chained_auth))
460d9c5261fSeinhirn            return parent::useSessionCache($user);
46186e0f1b9SPhilipp Neuser        else
46286e0f1b9SPhilipp Neuser            return $this->chained_auth->useSessionCache($user);
46386e0f1b9SPhilipp Neuser    }
464d9c5261fSeinhirn
46586e0f1b9SPhilipp Neuser}
466