diff --git a/apps/federatedfilesharing/lib/Controller/RequestHandlerController.php b/apps/federatedfilesharing/lib/Controller/RequestHandlerController.php index e0985f9aef..a74342f118 100644 --- a/apps/federatedfilesharing/lib/Controller/RequestHandlerController.php +++ b/apps/federatedfilesharing/lib/Controller/RequestHandlerController.php @@ -148,7 +148,7 @@ class RequestHandlerController extends OCSController { ); \OCP\Util::writeLog('files_sharing', 'shareWith after, ' . $shareWith, \OCP\Util::DEBUG); - if (!\OCP\User::userExists($shareWith)) { + if (!\OC::$server->getUserManager()->userExists($shareWith)) { throw new OCSException('User does not exists', 400); } diff --git a/apps/files_sharing/tests/CacheTest.php b/apps/files_sharing/tests/CacheTest.php index 5d5de433ee..c891f56f3d 100644 --- a/apps/files_sharing/tests/CacheTest.php +++ b/apps/files_sharing/tests/CacheTest.php @@ -66,8 +66,10 @@ class CacheTest extends TestCase { $this->shareManager = \OC::$server->getShareManager(); - \OC_User::setDisplayName(self::TEST_FILES_SHARING_API_USER1, 'User One'); - \OC_User::setDisplayName(self::TEST_FILES_SHARING_API_USER2, 'User Two'); + + $userManager = \OC::$server->getUserManager(); + $userManager->get(self::TEST_FILES_SHARING_API_USER1)->setDisplayName('User One'); + $userManager->get(self::TEST_FILES_SHARING_API_USER2)->setDisplayName('User Two'); self::loginHelper(self::TEST_FILES_SHARING_API_USER1); diff --git a/apps/user_ldap/lib/Access.php b/apps/user_ldap/lib/Access.php index b84f5a38b3..43feeb4c1f 100644 --- a/apps/user_ldap/lib/Access.php +++ b/apps/user_ldap/lib/Access.php @@ -588,7 +588,7 @@ class Access extends LDAPUtility implements IUserTools { // outside of core user management will still cache the user as non-existing. $originalTTL = $this->connection->ldapCacheTTL; $this->connection->setConfiguration(array('ldapCacheTTL' => 0)); - if(($isUser && $intName !== '' && !\OCP\User::userExists($intName)) + if(($isUser && $intName !== '' && !\OC::$server->getUserManager()->userExists($intName)) || (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName))) { if($mapper->map($fdn, $intName, $uuid)) { $this->connection->setConfiguration(array('ldapCacheTTL' => $originalTTL)); @@ -721,7 +721,7 @@ class Access extends LDAPUtility implements IUserTools { //20 attempts, something else is very wrong. Avoids infinite loop. while($attempts < 20){ $altName = $name . '_' . rand(1000,9999); - if(!\OCP\User::userExists($altName)) { + if(!\OC::$server->getUserManager()->userExists($altName)) { return $altName; } $attempts++; diff --git a/apps/user_ldap/tests/User_LDAPTest.php b/apps/user_ldap/tests/User_LDAPTest.php index 3262a2360a..9911aa37e3 100644 --- a/apps/user_ldap/tests/User_LDAPTest.php +++ b/apps/user_ldap/tests/User_LDAPTest.php @@ -275,7 +275,11 @@ class User_LDAPTest extends TestCase { $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock()); \OC_User::useBackend($backend); - $result = \OCP\User::checkPassword('roland', 'dt19'); + $user = \OC::$server->getUserManager()->checkPassword('roland', 'dt19'); + $result = false; + if ($user !== false) { + $result = $user->getUID(); + } $this->assertEquals('gunslinger', $result); } @@ -285,7 +289,11 @@ class User_LDAPTest extends TestCase { $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock()); \OC_User::useBackend($backend); - $result = \OCP\User::checkPassword('roland', 'wrong'); + $user = \OC::$server->getUserManager()->checkPassword('roland', 'wrong'); + $result = false; + if ($user !== false) { + $result = $user->getUID(); + } $this->assertFalse($result); } @@ -295,7 +303,11 @@ class User_LDAPTest extends TestCase { $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock()); \OC_User::useBackend($backend); - $result = \OCP\User::checkPassword('mallory', 'evil'); + $user = \OC::$server->getUserManager()->checkPassword('mallory', 'evil'); + $result = false; + if ($user !== false) { + $result = $user->getUID(); + } $this->assertFalse($result); } @@ -629,7 +641,7 @@ class User_LDAPTest extends TestCase { ->willReturn($this->createMock(UserMapping::class)); //test for existing user - $result = \OCP\User::userExists('gunslinger'); + $result = \OC::$server->getUserManager()->userExists('gunslinger'); $this->assertTrue($result); } @@ -656,7 +668,7 @@ class User_LDAPTest extends TestCase { ->willReturn($this->createMock(User::class)); //test for deleted user - \OCP\User::userExists('formerUser'); + \OC::$server->getUserManager()->userExists('formerUser'); } public function testUserExistsPublicAPIForNeverExisting() { @@ -675,7 +687,7 @@ class User_LDAPTest extends TestCase { })); //test for never-existing user - $result = \OCP\User::userExists('mallory'); + $result = \OC::$server->getUserManager()->userExists('mallory'); $this->assertFalse($result); } diff --git a/lib/private/Share/Share.php b/lib/private/Share/Share.php index 193e0c1a27..5a88f57fb1 100644 --- a/lib/private/Share/Share.php +++ b/lib/private/Share/Share.php @@ -439,7 +439,7 @@ class Share extends Constants { \OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName), \OCP\Util::DEBUG); throw new \Exception($message_t); } - if (!\OC_User::userExists($shareWith)) { + if (!\OC::$server->getUserManager()->userExists($shareWith)) { $message = 'Sharing %s failed, because the user %s does not exist'; $message_t = $l->t('Sharing %s failed, because the user %s does not exist', array($itemSourceName, $shareWith)); \OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName, $shareWith), \OCP\Util::DEBUG); diff --git a/lib/private/legacy/json.php b/lib/private/legacy/json.php index 7b3a1b6d9c..7bfc815ab2 100644 --- a/lib/private/legacy/json.php +++ b/lib/private/legacy/json.php @@ -118,7 +118,7 @@ class OC_JSON{ * @suppress PhanDeprecatedFunction */ public static function checkUserExists($user) { - if (!OCP\User::userExists($user)) { + if (!\OC::$server->getUserManager()->userExists($user)) { $l = \OC::$server->getL10N('lib'); OCP\JSON::error(array('data' => array('message' => $l->t('Unknown user'), 'error' => 'unknown_user' ))); exit; diff --git a/lib/private/legacy/user.php b/lib/private/legacy/user.php index 52ed1369c4..8f342281ad 100644 --- a/lib/private/legacy/user.php +++ b/lib/private/legacy/user.php @@ -58,13 +58,6 @@ */ class OC_User { - /** - * @return \OC\User\Session - */ - public static function getUserSession() { - return OC::$server->getUserSession(); - } - private static $_usedBackends = array(); private static $_setupedBackends = array(); @@ -176,7 +169,7 @@ class OC_User { if ($uid) { if (self::getUser() !== $uid) { self::setUserId($uid); - $userSession = self::getUserSession(); + $userSession = \OC::$server->getUserSession(); $userSession->setLoginName($uid); $request = OC::$server->getRequest(); $userSession->createSessionToken($request, $uid, $uid); @@ -210,7 +203,7 @@ class OC_User { //setup extra user backends self::setupBackends(); - self::getUserSession()->unsetMagicInCookie(); + \OC::$server->getUserSession()->unsetMagicInCookie(); return self::loginWithApache($backend); } @@ -234,25 +227,6 @@ class OC_User { } } - /** - * Sets user display name for session - * - * @param string $uid - * @param string $displayName - * @return bool Whether the display name could get set - */ - public static function setDisplayName($uid, $displayName = null) { - if (is_null($displayName)) { - $displayName = $uid; - } - $user = \OC::$server->getUserManager()->get($uid); - if ($user) { - return $user->setDisplayName($displayName); - } else { - return false; - } - } - /** * Check if the user is logged in, considers also the HTTP basic credentials * @@ -348,7 +322,7 @@ class OC_User { return $uid; } } else { - $user = self::getUserSession()->getUser(); + $user = \OC::$server->getUserSession()->getUser(); if ($user) { return $user->getDisplayName(); } else { @@ -376,25 +350,6 @@ class OC_User { } } - /** - * Check if the password is correct - * - * @param string $uid The username - * @param string $password The password - * @return string|false user id a string on success, false otherwise - * - * Check if the password is correct without logging in the user - * returns the user id or false - */ - public static function checkPassword($uid, $password) { - $manager = \OC::$server->getUserManager(); - $username = $manager->checkPassword($uid, $password); - if ($username !== false) { - return $username->getUID(); - } - return false; - } - /** * @param string $uid The username * @return string @@ -450,31 +405,6 @@ class OC_User { return $displayNames; } - /** - * check if a user exists - * - * @param string $uid the username - * @return boolean - */ - public static function userExists($uid) { - return \OC::$server->getUserManager()->userExists($uid); - } - - /** - * checks if a user is enabled - * - * @param string $uid - * @return bool - */ - public static function isEnabled($uid) { - $user = \OC::$server->getUserManager()->get($uid); - if ($user) { - return $user->isEnabled(); - } else { - return false; - } - } - /** * Returns the first active backend from self::$_usedBackends. * diff --git a/lib/private/legacy/util.php b/lib/private/legacy/util.php index aaedd88a7f..ca7cc1dc5c 100644 --- a/lib/private/legacy/util.php +++ b/lib/private/legacy/util.php @@ -274,7 +274,7 @@ class OC_Util { self::initLocalStorageRootFS(); } - if ($user != '' && !OCP\User::userExists($user)) { + if ($user != '' && !\OC::$server->getUserManager()->userExists($user)) { \OC::$server->getEventLogger()->end('setup_fs'); return false; } diff --git a/lib/public/User.php b/lib/public/User.php index fd39b103d6..2fdf540b95 100644 --- a/lib/public/User.php +++ b/lib/public/User.php @@ -115,30 +115,7 @@ class User { * @since 5.0.0 */ public static function userExists($uid, $excludingBackend = null) { - return \OC_User::userExists($uid); - } - /** - * Logs the user out including all the session data - * Logout, destroys session - * @deprecated 8.0.0 Use \OC::$server->getUserSession()->logout(); - * @since 5.0.0 - */ - public static function logout() { - \OC::$server->getUserSession()->logout(); - } - - /** - * Check if the password is correct - * @param string $uid The username - * @param string $password The password - * @return string|false username on success, false otherwise - * - * Check if the password is correct without logging in the user - * @deprecated 8.0.0 Use \OC::$server->getUserManager()->checkPassword(); - * @since 5.0.0 - */ - public static function checkPassword( $uid, $password ) { - return \OC_User::checkPassword( $uid, $password ); + return \OC::$server->getUserManager()->userExists($uid); } /** diff --git a/settings/users.php b/settings/users.php index 20b9e21d58..03523fc530 100644 --- a/settings/users.php +++ b/settings/users.php @@ -62,12 +62,17 @@ if ($config->getSystemValue('sort_groups_by_name', false)) { } } -$isAdmin = OC_User::isAdminUser(OC_User::getUser()); +$uid = \OC_User::getUser(); +$isAdmin = OC_User::isAdminUser($uid); -$isDisabled = !OC_User::isEnabled(OC_User::getUser()); +$isDisabled = true; +$user = $userManager->get($uid); +if ($user) { + $isDisabled = !$user->isEnabled(); +} $groupsInfo = new \OC\Group\MetaData( - OC_User::getUser(), + $uid, $isAdmin, $groupManager, \OC::$server->getUserSession() diff --git a/tests/lib/TestCase.php b/tests/lib/TestCase.php index 64036084dc..345b2a68e6 100644 --- a/tests/lib/TestCase.php +++ b/tests/lib/TestCase.php @@ -385,7 +385,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase { $userObject->updateLastLoginTimestamp(); } \OC_Util::setupFS($user); - if (\OC_User::userExists($user)) { + if (\OC::$server->getUserManager()->userExists($user)) { \OC::$server->getUserFolder($user); } } diff --git a/tests/lib/Traits/EncryptionTrait.php b/tests/lib/Traits/EncryptionTrait.php index 8a06d37fa7..ba759a51a2 100644 --- a/tests/lib/Traits/EncryptionTrait.php +++ b/tests/lib/Traits/EncryptionTrait.php @@ -50,7 +50,7 @@ trait EncryptionTrait { \OC_User::setUserId($user); $this->postLogin(); \OC_Util::setupFS($user); - if (\OC_User::userExists($user)) { + if (\OC::$server->getUserManager()->userExists($user)) { \OC::$server->getUserFolder($user); } } diff --git a/tests/lib/UserTest.php b/tests/lib/UserTest.php deleted file mode 100644 index 2a477522de..0000000000 --- a/tests/lib/UserTest.php +++ /dev/null @@ -1,55 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -namespace Test; - -/** - * Class User - * - * @group DB - * - * @package Test - */ -class UserTest extends TestCase { - /** - * @var \OC\User\Backend | \PHPUnit_Framework_MockObject_MockObject $backend - */ - private $backend; - - protected function setUp(){ - parent::setUp(); - - $this->backend = $this->createMock(\Test\Util\User\Dummy::class); - $manager = \OC::$server->getUserManager(); - $manager->registerBackend($this->backend); - } - - public function testCheckPassword() { - - $this->backend->expects($this->once()) - ->method('checkPassword') - ->with($this->equalTo('foo'), $this->equalTo('bar')) - ->will($this->returnValue('foo')) - ; - - $this->backend->expects($this->any()) - ->method('implementsActions') - ->will($this->returnCallback(function ($actions) { - if ($actions === \OC\USER\BACKEND::CHECK_PASSWORD) { - return true; - } else { - return false; - } - })); - - $uid = \OC_User::checkPassword('foo', 'bar'); - $this->assertEquals($uid, 'foo'); - } - -}