From 3dacf149de2ac560328242666473533c81c4b418 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 1 Sep 2012 02:48:54 +0200 Subject: [PATCH] allow configuring user backends in config.php --- lib/base.php | 11 ++++++++++- lib/user.php | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/base.php b/lib/base.php index 8d605e5280..fb83f6ea0a 100644 --- a/lib/base.php +++ b/lib/base.php @@ -351,6 +351,9 @@ class OC{ } } + //setup extra user backends + OC_User::setupBackends(); + // register cache cleanup jobs OC_BackgroundJob_RegularTask::register('OC_Cache_FileGlobal', 'gc'); OC_Hook::connect('OC_User', 'post_login', 'OC_Cache_File', 'loginListener'); @@ -423,6 +426,7 @@ class OC{ // Someone is logged in : if(OC_User::isLoggedIn()) { OC_App::loadApps(); + OC_User::setupBackends(); if(isset($_GET["logout"]) and ($_GET["logout"])) { OC_User::logout(); header("Location: ".OC::$WEBROOT.'/'); @@ -469,7 +473,7 @@ class OC{ } protected static function handleLogin() { - OC_App::loadApps(array('prelogin','authentication')); + OC_App::loadApps(array('prelogin')); $error = false; // remember was checked after last login if (OC::tryRememberLogin()) { @@ -517,7 +521,12 @@ class OC{ || ($_SESSION['sectoken']!=$_POST['sectoken']) ) { return false; } + OC_App::loadApps(); + + //setup extra user backends + OC_User::setupBackends(); + if(OC_User::login($_POST["user"], $_POST["password"])) { if(!empty($_POST["remember_login"])){ if(defined("DEBUG") && DEBUG) { diff --git a/lib/user.php b/lib/user.php index c432f6074a..305fb8ed3a 100644 --- a/lib/user.php +++ b/lib/user.php @@ -39,6 +39,8 @@ class OC_User { // The backend used for user management private static $_usedBackends = array(); + + private static $_setupedBackends = array(); // Backends available (except database) private static $_backends = array(); @@ -114,6 +116,28 @@ class OC_User { self::$_usedBackends=array(); } + /** + * setup the configured backends in config.php + */ + public static function setupBackends(){ + $backends=OC_Config::getValue('user_backends',array()); + foreach($backends as $i=>$config){ + $class=$config['class']; + $arguments=$config['arguments']; + if(class_exists($class) and array_search($i,self::$_setupedBackends)===false){ + // make a reflection object + $reflectionObj = new ReflectionClass($class); + + // use Reflection to create a new instance, using the $args + $backend = $reflectionObj->newInstanceArgs($arguments); + self::useBackend($backend); + $_setupedBackends[]=$i; + }else{ + OC_Log::write('core','User backend '.$class.' not found.',OC_Log::ERROR); + } + } + } + /** * @brief Create a new user * @param $uid The username of the user to create @@ -253,6 +277,7 @@ class OC_User { public static function isLoggedIn(){ if( isset($_SESSION['user_id']) AND $_SESSION['user_id']) { OC_App::loadApps(array('authentication')); + self::setupBackends(); if (self::userExists($_SESSION['user_id']) ){ return true; }