summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-01-17 05:33:07 +0100
committerGitHub <noreply@github.com>2018-01-17 05:33:07 +0100
commit0b464e527489488ed058cc80f6bb93e086eec681 (patch)
treed2d0002f3a86221a09cb8373fa382af5c807a7a9
parentca2904a01778eab0bb595700d01df075bb4cf92f (diff)
parent55532f19d90b40f7f46354b92a5322676729ba7e (diff)
downloadnextcloud-server-0b464e527489488ed058cc80f6bb93e086eec681.tar.gz
nextcloud-server-0b464e527489488ed058cc80f6bb93e086eec681.zip
Merge pull request #7884 from nextcloud/cleanup-oc_user
Cleanup OC_User and OCP\User
-rw-r--r--apps/federatedfilesharing/lib/Controller/RequestHandlerController.php2
-rw-r--r--apps/files_sharing/tests/CacheTest.php6
-rw-r--r--apps/user_ldap/lib/Access.php4
-rw-r--r--apps/user_ldap/tests/User_LDAPTest.php24
-rw-r--r--lib/private/Share/Share.php2
-rw-r--r--lib/private/legacy/json.php2
-rw-r--r--lib/private/legacy/user.php76
-rw-r--r--lib/private/legacy/util.php2
-rw-r--r--lib/public/User.php25
-rw-r--r--settings/users.php11
-rw-r--r--tests/lib/TestCase.php2
-rw-r--r--tests/lib/Traits/EncryptionTrait.php2
-rw-r--r--tests/lib/UserTest.php55
13 files changed, 42 insertions, 171 deletions
diff --git a/apps/federatedfilesharing/lib/Controller/RequestHandlerController.php b/apps/federatedfilesharing/lib/Controller/RequestHandlerController.php
index e0985f9aefc..a74342f1182 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 5d5de433ee4..c891f56f3d3 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 b84f5a38b31..43feeb4c1f0 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 3262a2360ad..9911aa37e37 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 193e0c1a27e..5a88f57fb14 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 7b3a1b6d9cd..7bfc815ab24 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 52ed1369c47..8f342281adb 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);
}
@@ -235,25 +228,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
*
* @deprecated use \OC::$server->getUserSession()->isLoggedIn()
@@ -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 {
@@ -377,25 +351,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
*
@@ -451,31 +406,6 @@ class OC_User {
}
/**
- * 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.
*
* @return OCP\Authentication\IApacheBackend|null if no backend active, otherwise OCP\Authentication\IApacheBackend
diff --git a/lib/private/legacy/util.php b/lib/private/legacy/util.php
index aaedd88a7ff..ca7cc1dc5cf 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 fd39b103d65..2fdf540b958 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 20b9e21d58e..03523fc5305 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 64036084dc2..345b2a68e6f 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 8a06d37fa7f..ba759a51a28 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 2a477522dea..00000000000
--- a/tests/lib/UserTest.php
+++ /dev/null
@@ -1,55 +0,0 @@
-<?php
-
-/**
- * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
- * 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');
- }
-
-}