diff --git a/auth.php b/auth.php index 20a43f3..9213929 100644 --- a/auth.php +++ b/auth.php @@ -13,6 +13,7 @@ class auth_plugin_authsplit extends DokuWiki_Auth_Plugin { protected $authplugins; protected $autocreate_users; protected $debug; + protected $use_fallback; /** * Show a debug message @@ -39,7 +40,7 @@ public function __construct() { $this->loadConfig(); /* Load all referenced auth plugins */ - foreach (array('primary', 'secondary') as $type) { + foreach (array('primary', 'secondary', 'fallback') as $type) { $settingName = $type.'_authplugin'; $pluginName = $this->getConf($settingName); if (!$pluginName) { @@ -74,6 +75,14 @@ public function __construct() { $this->success = false; return; } + /* Use fallback auth methode? */ + $this->use_fallback = $this->getConf('use_fallback', null); + if ($this->use_fallback === null) { + msg(sprintf($this->getLang('nocfg'), 'use_fallback'), -1); + $this->success = false; + return; + } + /* Of course, to modify login names actually BOTH auth plugins must support that. However, at this place we just consider the secondary @@ -142,15 +151,36 @@ public function checkPass($user, $pass) { 'authsplit:checkPass(): primary auth plugin\'s checkPass() '. 'failed', -1, __LINE__, __FILE__ ); - return false; + + if ($this->use_fallback) { + $this->_debug( + 'authsplit:checkPass(): use fallback auth plugin\'s '. + 'checkPass()', -1, __LINE__, __FILE__ + ); + + if (!$this->authplugins['fallback']->checkPass($user, $pass)) { + $this->_debug( + 'authsplit:checkPass(): fallback auth plugin\'s checkPass() '. + 'failed', -1, __LINE__, __FILE__ + ); + return false; + } else { + $this->_debug( + 'authsplit:checkPass(): fallback auth plugin authenticated the '. + 'user successfully.', 1, __LINE__, __FILE__ + ); + } + } + } else { + $this->_debug( + 'authsplit:checkPass(): primary auth plugin authenticated the '. + 'user successfully.', 1, __LINE__, __FILE__ + ); } - $this->_debug( - 'authsplit:checkPass(): primary auth plugin authenticated the '. - 'user successfully.', 1, __LINE__, __FILE__ - ); /* Then make sure that the secondary auth plugin also knows about the user. */ + return $this->_checkUserOnSecondaryAuthPlugin($user); } diff --git a/conf/default.php b/conf/default.php index b98f12a..9ecdce9 100644 --- a/conf/default.php +++ b/conf/default.php @@ -9,3 +9,5 @@ $conf['secondary_authplugin'] = 'authplain'; $conf['autocreate_users'] = 0; $conf['debug'] = 0; +$conf['use_fallback'] = 0; +$conf['fallback_authplugin'] = 'authplain'; diff --git a/conf/metadata.php b/conf/metadata.php index f04fee1..3c3cb2d 100644 --- a/conf/metadata.php +++ b/conf/metadata.php @@ -20,3 +20,5 @@ function initialize($default, $local, $protected) { $meta['secondary_authplugin'] = array('authtype_nosplit', '_cautionList' => array('plugin____authsplit____secondary_authplugin' => 'danger')); $meta['autocreate_users'] = array('onoff'); $meta['debug'] = array('onoff'); +$meta['fallback_authplugin'] = array('authtype_nosplit', '_cautionList' => array('plugin____authsplit____secondary_authplugin' => 'danger')); +$meta['use_fallback'] = array('onoff');