certificate manager only needs the user-id, no need to pass on the complete user object

This commit is contained in:
Bjoern Schiessle 2015-01-20 17:00:29 +01:00
parent 66f0db30b2
commit 67da1f7e5a
6 changed files with 22 additions and 20 deletions

View file

@ -199,7 +199,7 @@ class Manager {
$data['manager'] = $this; $data['manager'] = $this;
$mountPoint = '/' . $this->uid . '/files' . $data['mountpoint']; $mountPoint = '/' . $this->uid . '/files' . $data['mountpoint'];
$data['mountpoint'] = $mountPoint; $data['mountpoint'] = $mountPoint;
$data['certificateManager'] = \OC::$server->getCertificateManager(\OC::$server->getUserSession()->getUser()); $data['certificateManager'] = \OC::$server->getCertificateManager($this->uid);
$mount = new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader); $mount = new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader);
$this->mountManager->addMount($mount); $this->mountManager->addMount($mount);
return $mount; return $mount;

View file

@ -30,8 +30,8 @@ class Hooks {
\OC::$server->getDatabaseConnection(), \OC::$server->getDatabaseConnection(),
\OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getMountManager(),
\OC\Files\Filesystem::getLoader(), \OC\Files\Filesystem::getLoader(),
\OC::$server->getUserSession(), \OC::$server->getHTTPHelper(),
\OC::$server->getHTTPHelper()); $params['uid']);
$manager->removeUserShares($params['uid']); $manager->removeUserShares($params['uid']);
} }

View file

@ -153,8 +153,9 @@ class Test_Files_Sharing_S2S_OCS_API extends TestCase {
\OC::$server->getDatabaseConnection(), \OC::$server->getDatabaseConnection(),
\OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getMountManager(),
\OC\Files\Filesystem::getLoader(), \OC\Files\Filesystem::getLoader(),
\OC::$server->getUserSession(), \OC::$server->getHTTPHelper(),
\OC::$server->getHTTPHelper()); $toDelete
);
$manager->removeUserShares($toDelete); $manager->removeUserShares($toDelete);

View file

@ -16,15 +16,15 @@ use OCP\ICertificateManager;
*/ */
class CertificateManager implements ICertificateManager { class CertificateManager implements ICertificateManager {
/** /**
* @var \OCP\IUser * @var string
*/ */
protected $user; protected $uid;
/** /**
* @param \OCP\IUser $user * @param string $uid
*/ */
public function __construct($user) { public function __construct($uid) {
$this->user = $user; $this->uid = $uid;
} }
/** /**
@ -134,7 +134,7 @@ class CertificateManager implements ICertificateManager {
} }
private function getPathToCertificates() { private function getPathToCertificates() {
$path = $this->user ? $this->user->getHome() . '/files_external/' : '/files_external/'; $path = is_null($this->uid) ? '/files_external/' : '/' . $this->uid . '/files_external/';
return $path; return $path;
} }

View file

@ -249,7 +249,9 @@ class Server extends SimpleContainer implements IServerContainer {
}); });
$this->registerService('HTTPHelper', function (Server $c) { $this->registerService('HTTPHelper', function (Server $c) {
$config = $c->getConfig(); $config = $c->getConfig();
return new HTTPHelper($config, new \OC\Security\CertificateManager($c->getUserSession()->getUser())); $user = $c->getUserSession()->getUser();
$uid = $user ? $user->getUID() : null;
return new HTTPHelper($config, new \OC\Security\CertificateManager($uid));
}); });
$this->registerService('EventLogger', function (Server $c) { $this->registerService('EventLogger', function (Server $c) {
if (defined('DEBUG') and DEBUG) { if (defined('DEBUG') and DEBUG) {
@ -631,18 +633,19 @@ class Server extends SimpleContainer implements IServerContainer {
/** /**
* Get the certificate manager for the user * Get the certificate manager for the user
* *
* @param \OCP\IUser $user (optional) if not specified the current loggedin user is used * @param string $uid (optional) if not specified the current loggedin user is used
* @return \OCP\ICertificateManager * @return \OCP\ICertificateManager
*/ */
function getCertificateManager($user = null) { function getCertificateManager($uid = null) {
if (is_null($user)) { if (is_null($uid)) {
$userSession = $this->getUserSession(); $userSession = $this->getUserSession();
$user = $userSession->getUser(); $user = $userSession->getUser();
if (is_null($user)) { if (is_null($user)) {
return null; return null;
} }
$uid = $user->getUID();
} }
return new CertificateManager($user); return new CertificateManager($uid);
} }
/** /**

View file

@ -28,9 +28,7 @@ class CertificateManagerTest extends \Test\TestCase {
\OC\Files\Filesystem::tearDown(); \OC\Files\Filesystem::tearDown();
\OC_Util::setupFS($this->username); \OC_Util::setupFS($this->username);
$this->user = \OC::$server->getUserManager()->get($this->username); $this->certificateManager = new CertificateManager($this->username);
$this->certificateManager = new CertificateManager($this->user);
} }
protected function tearDown() { protected function tearDown() {
@ -84,7 +82,7 @@ class CertificateManagerTest extends \Test\TestCase {
} }
function testGetCertificateBundle() { function testGetCertificateBundle() {
$this->assertSame($this->user->getHome().'/files_external/rootcerts.crt', $this->certificateManager->getCertificateBundle()); $this->assertSame('/' . $this->username . '/files_external/rootcerts.crt', $this->certificateManager->getCertificateBundle());
} }
} }