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;
$mountPoint = '/' . $this->uid . '/files' . $data['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);
$this->mountManager->addMount($mount);
return $mount;

View file

@ -30,8 +30,8 @@ class Hooks {
\OC::$server->getDatabaseConnection(),
\OC\Files\Filesystem::getMountManager(),
\OC\Files\Filesystem::getLoader(),
\OC::$server->getUserSession(),
\OC::$server->getHTTPHelper());
\OC::$server->getHTTPHelper(),
$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\Files\Filesystem::getMountManager(),
\OC\Files\Filesystem::getLoader(),
\OC::$server->getUserSession(),
\OC::$server->getHTTPHelper());
\OC::$server->getHTTPHelper(),
$toDelete
);
$manager->removeUserShares($toDelete);

View file

@ -16,15 +16,15 @@ use OCP\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) {
$this->user = $user;
public function __construct($uid) {
$this->uid = $uid;
}
/**
@ -134,7 +134,7 @@ class CertificateManager implements ICertificateManager {
}
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;
}

View file

@ -249,7 +249,9 @@ class Server extends SimpleContainer implements IServerContainer {
});
$this->registerService('HTTPHelper', function (Server $c) {
$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) {
if (defined('DEBUG') and DEBUG) {
@ -631,18 +633,19 @@ class Server extends SimpleContainer implements IServerContainer {
/**
* 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
*/
function getCertificateManager($user = null) {
if (is_null($user)) {
function getCertificateManager($uid = null) {
if (is_null($uid)) {
$userSession = $this->getUserSession();
$user = $userSession->getUser();
if (is_null($user)) {
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_Util::setupFS($this->username);
$this->user = \OC::$server->getUserManager()->get($this->username);
$this->certificateManager = new CertificateManager($this->user);
$this->certificateManager = new CertificateManager($this->username);
}
protected function tearDown() {
@ -84,7 +82,7 @@ class CertificateManagerTest extends \Test\TestCase {
}
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());
}
}