diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base.php | 1 | ||||
-rw-r--r-- | lib/private/api.php | 8 | ||||
-rw-r--r-- | lib/private/app/infoparser.php | 3 | ||||
-rw-r--r-- | lib/private/appframework/dependencyinjection/dicontainer.php | 4 | ||||
-rw-r--r-- | lib/private/group/manager.php | 30 | ||||
-rw-r--r-- | lib/private/memcache/memcached.php | 8 | ||||
-rw-r--r-- | lib/private/user.php | 14 | ||||
-rw-r--r-- | lib/private/user/session.php | 9 | ||||
-rw-r--r-- | lib/public/appframework/iappcontainer.php | 4 | ||||
-rw-r--r-- | lib/public/igroupmanager.php | 15 | ||||
-rw-r--r-- | lib/public/iusersession.php | 9 |
11 files changed, 92 insertions, 13 deletions
diff --git a/lib/base.php b/lib/base.php index 1dd259b0914..ae87ecff394 100644 --- a/lib/base.php +++ b/lib/base.php @@ -766,6 +766,7 @@ class OC { // For guests: Load only authentication, filesystem and logging OC_App::loadApps(array('authentication')); OC_App::loadApps(array('filesystem', 'logging')); + \OC_User::tryBasicAuthLogin(); } } diff --git a/lib/private/api.php b/lib/private/api.php index 66b763fdc3e..35a09c5cd1b 100644 --- a/lib/private/api.php +++ b/lib/private/api.php @@ -47,6 +47,7 @@ class OC_API { */ protected static $actions = array(); private static $logoutRequired = false; + private static $isLoggedIn = false; /** * registers an api call @@ -269,7 +270,10 @@ class OC_API { * http basic auth * @return string|false (username, or false on failure) */ - private static function loginUser(){ + private static function loginUser() { + if(self::$isLoggedIn === true) { + return \OC_User::getUser(); + } // reuse existing login $loggedIn = OC_User::isLoggedIn(); @@ -279,6 +283,7 @@ class OC_API { // initialize the user's filesystem \OC_Util::setUpFS(\OC_User::getUser()); + self::$isLoggedIn = true; return OC_User::getUser(); } @@ -296,6 +301,7 @@ class OC_API { // initialize the user's filesystem \OC_Util::setUpFS(\OC_User::getUser()); + self::$isLoggedIn = true; return $authUser; } diff --git a/lib/private/app/infoparser.php b/lib/private/app/infoparser.php index 0bfbf6bd139..0603a7a7b7f 100644 --- a/lib/private/app/infoparser.php +++ b/lib/private/app/infoparser.php @@ -41,8 +41,9 @@ class InfoParser { return null; } + libxml_use_internal_errors(true); $loadEntities = libxml_disable_entity_loader(false); - $xml = @simplexml_load_file($file); + $xml = simplexml_load_file($file); libxml_disable_entity_loader($loadEntities); if ($xml == false) { return null; diff --git a/lib/private/appframework/dependencyinjection/dicontainer.php b/lib/private/appframework/dependencyinjection/dicontainer.php index 517ada2d205..dc57ef4c167 100644 --- a/lib/private/appframework/dependencyinjection/dicontainer.php +++ b/lib/private/appframework/dependencyinjection/dicontainer.php @@ -188,6 +188,7 @@ class DIContainer extends SimpleContainer implements IAppContainer{ } /** + * @deprecated use IUserSession->isLoggedIn() * @return boolean */ function isLoggedIn() { @@ -195,8 +196,7 @@ class DIContainer extends SimpleContainer implements IAppContainer{ } /** - * @deprecated use the groupmanager instead to find out if the user is in - * the admin group + * @deprecated use IGroupManager->isAdmin($userId) * @return boolean */ function isAdminUser() { diff --git a/lib/private/group/manager.php b/lib/private/group/manager.php index be7bf972693..8dcf14fc1d2 100644 --- a/lib/private/group/manager.php +++ b/lib/private/group/manager.php @@ -170,7 +170,14 @@ class Manager extends PublicEmitter implements IGroupManager { * @return \OC\Group\Group[] */ public function getUserGroups($user) { - $uid = $user->getUID(); + return $this->getUserIdGroups($user->getUID()); + } + + /** + * @param string $uid the user id + * @return \OC\Group\Group[] + */ + public function getUserIdGroups($uid) { if (isset($this->cachedUserGroups[$uid])) { return $this->cachedUserGroups[$uid]; } @@ -184,7 +191,26 @@ class Manager extends PublicEmitter implements IGroupManager { $this->cachedUserGroups[$uid] = $groups; return $this->cachedUserGroups[$uid]; } - + + /** + * Checks if a userId is in the admin group + * @param string $userId + * @return bool if admin + */ + public function isAdmin($userId) { + return $this->isInGroup($userId, 'admin'); + } + + /** + * Checks if a userId is in a group + * @param string $userId + * @param group $group + * @return bool if in group + */ + public function isInGroup($userId, $group) { + return array_key_exists($group, $this->getUserIdGroups($userId)); + } + /** * get a list of group ids for a user * @param \OC\User\User $user diff --git a/lib/private/memcache/memcached.php b/lib/private/memcache/memcached.php index cd8e2e8d0b6..042fead3347 100644 --- a/lib/private/memcache/memcached.php +++ b/lib/private/memcache/memcached.php @@ -74,7 +74,13 @@ class Memcached extends Cache { $keys[] = $key; } } - self::$cache->deleteMulti($keys); + if (method_exists(self::$cache, 'deleteMulti')) { + self::$cache->deleteMulti($keys); + } else { + foreach ($keys as $key) { + self::$cache->delete($key); + } + } return true; } diff --git a/lib/private/user.php b/lib/private/user.php index 2964b58ba14..17b84d1f93e 100644 --- a/lib/private/user.php +++ b/lib/private/user.php @@ -317,6 +317,15 @@ class OC_User { } /** + * Tries to login the user with HTTP Basic Authentication + */ + public static function tryBasicAuthLogin() { + if(!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_USER'])) { + \OC_User::login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); + } + } + + /** * Check if the user is logged in, considers also the HTTP basic credentials * @return bool */ @@ -325,11 +334,6 @@ class OC_User { return self::userExists(\OC::$server->getSession()->get('user_id')); } - // Check whether the user has authenticated using Basic Authentication - if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { - return \OC_User::login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); - } - return false; } diff --git a/lib/private/user/session.php b/lib/private/user/session.php index 277aa1a047e..53662d00952 100644 --- a/lib/private/user/session.php +++ b/lib/private/user/session.php @@ -138,6 +138,15 @@ class Session implements IUserSession, Emitter { } /** + * Checks wether the user is logged in + * + * @return bool if logged in + */ + public function isLoggedIn() { + return $this->getUser() !== null; + } + + /** * set the login name * * @param string|null $loginName for the logged in user diff --git a/lib/public/appframework/iappcontainer.php b/lib/public/appframework/iappcontainer.php index 3621d69a542..cb75bf4026c 100644 --- a/lib/public/appframework/iappcontainer.php +++ b/lib/public/appframework/iappcontainer.php @@ -31,7 +31,7 @@ use OCP\IContainer; * * This container interface provides short cuts for app developers to access predefined app service. */ -interface IAppContainer extends IContainer{ +interface IAppContainer extends IContainer { /** * used to return the appname of the set application @@ -57,11 +57,13 @@ interface IAppContainer extends IContainer{ function registerMiddleWare($middleWare); /** + * @deprecated use IUserSession->isLoggedIn() * @return boolean */ function isLoggedIn(); /** + * @deprecated use IGroupManager->isAdmin($userId) * @return boolean * @deprecated use the groupmanager instead to find out if the user is in * the admin group diff --git a/lib/public/igroupmanager.php b/lib/public/igroupmanager.php index dc69044c490..8f468574c6b 100644 --- a/lib/public/igroupmanager.php +++ b/lib/public/igroupmanager.php @@ -80,4 +80,19 @@ interface IGroupManager { * @return array an array of display names (value) and user ids (key) */ public function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0); + + /** + * Checks if a userId is in the admin group + * @param string $userId + * @return bool if admin + */ + public function isAdmin($userId); + + /** + * Checks if a userId is in a group + * @param string $userId + * @param group $group + * @return bool if in group + */ + public function isInGroup($userId, $group); } diff --git a/lib/public/iusersession.php b/lib/public/iusersession.php index db4abe150d2..4c5b4d1ba51 100644 --- a/lib/public/iusersession.php +++ b/lib/public/iusersession.php @@ -3,7 +3,9 @@ * ownCloud * * @author Bart Visscher + * @author Bernhard Posselt * @copyright 2013 Bart Visscher bartv@thisnet.nl + * @copyright 2014 Bernhard Posselt <dev@bernhard-posselt.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE @@ -62,4 +64,11 @@ interface IUserSession { * @return \OCP\IUser */ public function getUser(); + + /** + * Checks wether the user is logged in + * + * @return bool if logged in + */ + public function isLoggedIn(); } |