Пример #1
0
 public function testTryTokenLoginWithDisabledUser()
 {
     $manager = $this->getMockBuilder('\\OC\\User\\Manager')->disableOriginalConstructor()->getMock();
     $session = new Memory('');
     $token = $this->getMock('\\OC\\Authentication\\Token\\IToken');
     $user = $this->getMock('\\OCP\\IUser');
     $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config);
     $request = $this->getMock('\\OCP\\IRequest');
     $request->expects($this->once())->method('getHeader')->with('Authorization')->will($this->returnValue('token xxxxx'));
     $this->tokenProvider->expects($this->once())->method('validateToken')->with('xxxxx')->will($this->returnValue($token));
     $token->expects($this->once())->method('getUID')->will($this->returnValue('user123'));
     $manager->expects($this->once())->method('get')->with('user123')->will($this->returnValue($user));
     $user->expects($this->once())->method('isEnabled')->will($this->returnValue(false));
     $this->assertFalse($userSession->tryTokenLogin($request));
 }
Пример #2
0
 function __construct()
 {
     $this->registerService('ContactsManager', function ($c) {
         return new ContactsManager();
     });
     $this->registerService('Request', function ($c) {
         if (isset($c['urlParams'])) {
             $urlParams = $c['urlParams'];
         } else {
             $urlParams = array();
         }
         if (\OC::$server->getSession()->exists('requesttoken')) {
             $requestToken = \OC::$server->getSession()->get('requesttoken');
         } else {
             $requestToken = false;
         }
         if (defined('PHPUNIT_RUN') && PHPUNIT_RUN && in_array('fakeinput', stream_get_wrappers())) {
             $stream = 'fakeinput://data';
         } else {
             $stream = 'php://input';
         }
         return new Request(array('get' => $_GET, 'post' => $_POST, 'files' => $_FILES, 'server' => $_SERVER, 'env' => $_ENV, 'cookies' => $_COOKIE, 'method' => isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null, 'urlParams' => $urlParams, 'requesttoken' => $requestToken), $stream);
     });
     $this->registerService('PreviewManager', function ($c) {
         return new PreviewManager();
     });
     $this->registerService('TagManager', function ($c) {
         $user = \OC_User::getUser();
         return new TagManager($user);
     });
     $this->registerService('RootFolder', function ($c) {
         // TODO: get user and user manager from container as well
         $user = \OC_User::getUser();
         /** @var $c SimpleContainer */
         $userManager = $c->query('UserManager');
         $user = $userManager->get($user);
         $manager = \OC\Files\Filesystem::getMountManager();
         $view = new View();
         return new Root($manager, $view, $user);
     });
     $this->registerService('UserManager', function ($c) {
         /**
          * @var SimpleContainer $c
          * @var \OC\AllConfig $config
          */
         $config = $c->query('AllConfig');
         return new \OC\User\Manager($config);
     });
     $this->registerService('GroupManager', function ($c) {
         /**
          * @var SimpleContainer $c
          * @var \OC\User\Manager $userManager
          */
         $userManager = $c->query('UserManager');
         return new \OC\Group\Manager($userManager);
     });
     $this->registerService('UserSession', function ($c) {
         /**
          * @var SimpleContainer $c
          * @var \OC\User\Manager $manager
          */
         $manager = $c->query('UserManager');
         $userSession = new \OC\User\Session($manager, new \OC\Session\Memory(''));
         $userSession->listen('\\OC\\User', 'preCreateUser', function ($uid, $password) {
             \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'postCreateUser', function ($user, $password) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'preDelete', function ($user) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
         });
         $userSession->listen('\\OC\\User', 'postDelete', function ($user) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
         });
         $userSession->listen('\\OC\\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
         });
         $userSession->listen('\\OC\\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
         });
         $userSession->listen('\\OC\\User', 'preLogin', function ($uid, $password) {
             \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'postLogin', function ($user, $password) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'logout', function () {
             \OC_Hook::emit('OC_User', 'logout', array());
         });
         return $userSession;
     });
     $this->registerService('NavigationManager', function ($c) {
         return new \OC\NavigationManager();
     });
     $this->registerService('AllConfig', function ($c) {
         return new \OC\AllConfig();
     });
     $this->registerService('AppConfig', function ($c) {
         return new \OC\AppConfig(\OC_DB::getConnection());
     });
     $this->registerService('L10NFactory', function ($c) {
         return new \OC\L10N\Factory();
     });
     $this->registerService('URLGenerator', function ($c) {
         /** @var $c SimpleContainer */
         $config = $c->query('AllConfig');
         return new \OC\URLGenerator($config);
     });
     $this->registerService('AppHelper', function ($c) {
         return new \OC\AppHelper();
     });
     $this->registerService('UserCache', function ($c) {
         return new UserCache();
     });
     $this->registerService('MemCacheFactory', function ($c) {
         $instanceId = \OC_Util::getInstanceId();
         return new \OC\Memcache\Factory($instanceId);
     });
     $this->registerService('ActivityManager', function ($c) {
         return new ActivityManager();
     });
     $this->registerService('AvatarManager', function ($c) {
         return new AvatarManager();
     });
     $this->registerService('Logger', function ($c) {
         /** @var $c SimpleContainer */
         $logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud');
         $logger = 'OC_Log_' . ucfirst($logClass);
         call_user_func(array($logger, 'init'));
         return new Log($logger);
     });
     $this->registerService('JobList', function ($c) {
         /**
          * @var Server $c
          */
         $config = $c->getConfig();
         return new \OC\BackgroundJob\JobList($c->getDatabaseConnection(), $config);
     });
     $this->registerService('Router', function ($c) {
         /**
          * @var Server $c
          */
         $cacheFactory = $c->getMemCacheFactory();
         if ($cacheFactory->isAvailable()) {
             $router = new \OC\Route\CachingRouter($cacheFactory->create('route'));
         } else {
             $router = new \OC\Route\Router();
         }
         return $router;
     });
     $this->registerService('Search', function ($c) {
         return new Search();
     });
     $this->registerService('SecureRandom', function ($c) {
         return new SecureRandom();
     });
     $this->registerService('Crypto', function ($c) {
         return new Crypto(\OC::$server->getConfig(), \OC::$server->getSecureRandom());
     });
     $this->registerService('Db', function ($c) {
         return new Db();
     });
 }
Пример #3
0
 /**
  * @param string $webRoot
  */
 public function __construct($webRoot)
 {
     $this->webRoot = $webRoot;
     $this->registerService('ContactsManager', function ($c) {
         return new ContactsManager();
     });
     $this->registerService('PreviewManager', function (Server $c) {
         return new PreviewManager($c->getConfig());
     });
     $this->registerService('EncryptionManager', function (Server $c) {
         return new Encryption\Manager($c->getConfig(), $c->getLogger(), $c->getL10N('core'));
     });
     $this->registerService('EncryptionFileHelper', function (Server $c) {
         $util = new \OC\Encryption\Util(new \OC\Files\View(), $c->getUserManager(), $c->getGroupManager(), $c->getConfig());
         return new Encryption\File($util);
     });
     $this->registerService('EncryptionKeyStorage', function (Server $c) {
         $view = new \OC\Files\View();
         $util = new \OC\Encryption\Util($view, $c->getUserManager(), $c->getGroupManager(), $c->getConfig());
         return new Encryption\Keys\Storage($view, $util);
     });
     $this->registerService('TagMapper', function (Server $c) {
         return new TagMapper($c->getDatabaseConnection());
     });
     $this->registerService('TagManager', function (Server $c) {
         $tagMapper = $c->query('TagMapper');
         return new TagManager($tagMapper, $c->getUserSession());
     });
     $this->registerService('RootFolder', function (Server $c) {
         // TODO: get user and user manager from container as well
         $user = \OC_User::getUser();
         /** @var $c SimpleContainer */
         $userManager = $c->query('UserManager');
         $user = $userManager->get($user);
         $manager = \OC\Files\Filesystem::getMountManager();
         $view = new View();
         return new Root($manager, $view, $user);
     });
     $this->registerService('UserManager', function (Server $c) {
         $config = $c->getConfig();
         return new \OC\User\Manager($config);
     });
     $this->registerService('GroupManager', function (Server $c) {
         $groupManager = new \OC\Group\Manager($this->getUserManager());
         $groupManager->listen('\\OC\\Group', 'preCreate', function ($gid) {
             \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
         });
         $groupManager->listen('\\OC\\Group', 'postCreate', function (\OC\Group\Group $gid) {
             \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'preDelete', function (\OC\Group\Group $group) {
             \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'postDelete', function (\OC\Group\Group $group) {
             \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
             \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
             \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
         });
         return $groupManager;
     });
     $this->registerService('UserSession', function (Server $c) {
         $manager = $c->getUserManager();
         $userSession = new \OC\User\Session($manager, new \OC\Session\Memory(''));
         $userSession->listen('\\OC\\User', 'preCreateUser', function ($uid, $password) {
             \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'postCreateUser', function ($user, $password) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'preDelete', function ($user) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
         });
         $userSession->listen('\\OC\\User', 'postDelete', function ($user) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
         });
         $userSession->listen('\\OC\\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
         });
         $userSession->listen('\\OC\\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
         });
         $userSession->listen('\\OC\\User', 'preLogin', function ($uid, $password) {
             \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'postLogin', function ($user, $password) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'logout', function () {
             \OC_Hook::emit('OC_User', 'logout', array());
         });
         return $userSession;
     });
     $this->registerService('NavigationManager', function ($c) {
         return new \OC\NavigationManager();
     });
     $this->registerService('AllConfig', function (Server $c) {
         return new \OC\AllConfig($c->getSystemConfig());
     });
     $this->registerService('SystemConfig', function ($c) {
         return new \OC\SystemConfig();
     });
     $this->registerService('AppConfig', function ($c) {
         return new \OC\AppConfig(\OC_DB::getConnection());
     });
     $this->registerService('L10NFactory', function ($c) {
         return new \OC\L10N\Factory();
     });
     $this->registerService('URLGenerator', function (Server $c) {
         $config = $c->getConfig();
         $cacheFactory = $c->getMemCacheFactory();
         return new \OC\URLGenerator($config, $cacheFactory);
     });
     $this->registerService('AppHelper', function ($c) {
         return new \OC\AppHelper();
     });
     $this->registerService('UserCache', function ($c) {
         return new Cache\File();
     });
     $this->registerService('MemCacheFactory', function (Server $c) {
         $config = $c->getConfig();
         if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
             $v = \OC_App::getAppVersions();
             $v['core'] = implode('.', \OC_Util::getVersion());
             $version = implode(',', $v);
             $instanceId = \OC_Util::getInstanceId();
             $path = \OC::$SERVERROOT;
             $prefix = md5($instanceId . '-' . $version . '-' . $path);
             return new \OC\Memcache\Factory($prefix, $config->getSystemValue('memcache.local', null), $config->getSystemValue('memcache.distributed', null), $config->getSystemValue('memcache.locking', null));
         }
         return new \OC\Memcache\Factory('', new ArrayCache(), new ArrayCache(), new ArrayCache());
     });
     $this->registerService('ActivityManager', function (Server $c) {
         return new ActivityManager($c->getRequest(), $c->getUserSession(), $c->getConfig());
     });
     $this->registerService('AvatarManager', function ($c) {
         return new AvatarManager();
     });
     $this->registerService('Logger', function (Server $c) {
         $logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud');
         $logger = 'OC_Log_' . ucfirst($logClass);
         call_user_func(array($logger, 'init'));
         return new Log($logger);
     });
     $this->registerService('JobList', function (Server $c) {
         $config = $c->getConfig();
         return new \OC\BackgroundJob\JobList($c->getDatabaseConnection(), $config);
     });
     $this->registerService('Router', function (Server $c) {
         $cacheFactory = $c->getMemCacheFactory();
         if ($cacheFactory->isAvailable()) {
             $router = new \OC\Route\CachingRouter($cacheFactory->create('route'));
         } else {
             $router = new \OC\Route\Router();
         }
         return $router;
     });
     $this->registerService('Search', function ($c) {
         return new Search();
     });
     $this->registerService('SecureRandom', function ($c) {
         return new SecureRandom();
     });
     $this->registerService('Crypto', function (Server $c) {
         return new Crypto($c->getConfig(), $c->getSecureRandom());
     });
     $this->registerService('Hasher', function (Server $c) {
         return new Hasher($c->getConfig());
     });
     $this->registerService('DatabaseConnection', function (Server $c) {
         $factory = new \OC\DB\ConnectionFactory();
         $systemConfig = $c->getSystemConfig();
         $type = $systemConfig->getValue('dbtype', 'sqlite');
         if (!$factory->isValidType($type)) {
             throw new \OC\DatabaseException('Invalid database type');
         }
         $connectionParams = $factory->createConnectionParams($systemConfig);
         $connection = $factory->getConnection($type, $connectionParams);
         $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
         return $connection;
     });
     $this->registerService('Db', function (Server $c) {
         return new Db($c->getDatabaseConnection());
     });
     $this->registerService('HTTPHelper', function (Server $c) {
         $config = $c->getConfig();
         return new HTTPHelper($config, $c->getHTTPClientService());
     });
     $this->registerService('HttpClientService', function (Server $c) {
         $user = \OC_User::getUser();
         $uid = $user ? $user : null;
         return new ClientService($c->getConfig(), new \OC\Security\CertificateManager($uid, new \OC\Files\View()));
     });
     $this->registerService('EventLogger', function (Server $c) {
         if (defined('DEBUG') and DEBUG) {
             return new EventLogger();
         } else {
             return new NullEventLogger();
         }
     });
     $this->registerService('QueryLogger', function ($c) {
         if (defined('DEBUG') and DEBUG) {
             return new QueryLogger();
         } else {
             return new NullQueryLogger();
         }
     });
     $this->registerService('TempManager', function (Server $c) {
         return new TempManager(get_temp_dir(), $c->getLogger());
     });
     $this->registerService('AppManager', function (Server $c) {
         return new \OC\App\AppManager($c->getUserSession(), $c->getAppConfig(), $c->getGroupManager(), $c->getMemCacheFactory());
     });
     $this->registerService('DateTimeZone', function (Server $c) {
         return new DateTimeZone($c->getConfig(), $c->getSession());
     });
     $this->registerService('DateTimeFormatter', function (Server $c) {
         $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
         return new DateTimeFormatter($c->getDateTimeZone()->getTimeZone(), $c->getL10N('lib', $language));
     });
     $this->registerService('MountConfigManager', function () {
         $loader = \OC\Files\Filesystem::getLoader();
         return new \OC\Files\Config\MountProviderCollection($loader);
     });
     $this->registerService('IniWrapper', function ($c) {
         return new IniGetWrapper();
     });
     $this->registerService('AsyncCommandBus', function (Server $c) {
         $jobList = $c->getJobList();
         return new AsyncBus($jobList);
     });
     $this->registerService('TrustedDomainHelper', function ($c) {
         return new TrustedDomainHelper($this->getConfig());
     });
     $this->registerService('Request', function ($c) {
         if (isset($this['urlParams'])) {
             $urlParams = $this['urlParams'];
         } else {
             $urlParams = [];
         }
         if ($this->getSession()->exists('requesttoken')) {
             $requestToken = $this->getSession()->get('requesttoken');
         } else {
             $requestToken = false;
         }
         if (defined('PHPUNIT_RUN') && PHPUNIT_RUN && in_array('fakeinput', stream_get_wrappers())) {
             $stream = 'fakeinput://data';
         } else {
             $stream = 'php://input';
         }
         return new Request(['get' => $_GET, 'post' => $_POST, 'files' => $_FILES, 'server' => $_SERVER, 'env' => $_ENV, 'cookies' => $_COOKIE, 'method' => isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null, 'urlParams' => $urlParams, 'requesttoken' => $requestToken], $this->getSecureRandom(), $this->getConfig(), $stream);
     });
     $this->registerService('Mailer', function (Server $c) {
         return new Mailer($c->getConfig(), $c->getLogger(), new \OC_Defaults());
     });
     $this->registerService('OcsClient', function (Server $c) {
         return new OCSClient($this->getHTTPClientService(), $this->getConfig(), $this->getLogger());
     });
     $this->registerService('LockingProvider', function (Server $c) {
         if ($c->getConfig()->getSystemValue('filelocking.enabled', false) or defined('PHPUNIT_RUN') && PHPUNIT_RUN) {
             /** @var \OC\Memcache\Factory $memcacheFactory */
             $memcacheFactory = $c->getMemCacheFactory();
             $memcache = $memcacheFactory->createLocking('lock');
             if (!$memcache instanceof \OC\Memcache\NullCache) {
                 return new MemcacheLockingProvider($memcache);
             }
             throw new HintException('File locking is enabled but the locking cache class was not found', 'Please check the "memcache.locking" setting and make sure the matching PHP module is installed and enabled');
         }
         return new NoopLockingProvider();
     });
 }
Пример #4
0
 /**
  * @param string $webRoot
  */
 public function __construct($webRoot)
 {
     parent::__construct();
     $this->webRoot = $webRoot;
     $this->registerService('ContactsManager', function ($c) {
         return new ContactsManager();
     });
     $this->registerService('PreviewManager', function (Server $c) {
         return new PreviewManager($c->getConfig());
     });
     $this->registerService('EncryptionManager', function (Server $c) {
         $view = new View();
         $util = new Encryption\Util($view, $c->getUserManager(), $c->getGroupManager(), $c->getConfig());
         return new Encryption\Manager($c->getConfig(), $c->getLogger(), $c->getL10N('core'), new View(), $util);
     });
     $this->registerService('EncryptionFileHelper', function (Server $c) {
         $util = new Encryption\Util(new View(), $c->getUserManager(), $c->getGroupManager(), $c->getConfig());
         return new Encryption\File($util);
     });
     $this->registerService('EncryptionKeyStorage', function (Server $c) {
         $view = new View();
         $util = new Encryption\Util($view, $c->getUserManager(), $c->getGroupManager(), $c->getConfig());
         return new Encryption\Keys\Storage($view, $util);
     });
     $this->registerService('TagMapper', function (Server $c) {
         return new TagMapper($c->getDatabaseConnection());
     });
     $this->registerService('TagManager', function (Server $c) {
         $tagMapper = $c->query('TagMapper');
         return new TagManager($tagMapper, $c->getUserSession());
     });
     $this->registerService('SystemTagManager', function (Server $c) {
         return new SystemTag\SystemTagManager($c->getDatabaseConnection());
     });
     $this->registerService('SystemTagObjectMapper', function (Server $c) {
         return new SystemTag\SystemTagObjectMapper($c->getDatabaseConnection(), $c->getSystemTagManager());
     });
     $this->registerService('RootFolder', function (Server $c) {
         // TODO: get user and user manager from container as well
         $user = \OC_User::getUser();
         /** @var $c SimpleContainer */
         $userManager = $c->query('UserManager');
         $user = $userManager->get($user);
         $manager = \OC\Files\Filesystem::getMountManager();
         $view = new View();
         $root = new Root($manager, $view, $user);
         $connector = new HookConnector($root, $view);
         $connector->viewToNode();
         return $root;
     });
     $this->registerService('UserManager', function (Server $c) {
         $config = $c->getConfig();
         return new \OC\User\Manager($config);
     });
     $this->registerService('GroupManager', function (Server $c) {
         $groupManager = new \OC\Group\Manager($this->getUserManager());
         $groupManager->listen('\\OC\\Group', 'preCreate', function ($gid) {
             \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
         });
         $groupManager->listen('\\OC\\Group', 'postCreate', function (\OC\Group\Group $gid) {
             \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'preDelete', function (\OC\Group\Group $group) {
             \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'postDelete', function (\OC\Group\Group $group) {
             \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
             \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
             \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
             //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
             \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
         });
         return $groupManager;
     });
     $this->registerService('UserSession', function (Server $c) {
         $manager = $c->getUserManager();
         $session = new \OC\Session\Memory('');
         $userSession = new \OC\User\Session($manager, $session);
         $userSession->listen('\\OC\\User', 'preCreateUser', function ($uid, $password) {
             \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'postCreateUser', function ($user, $password) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'preDelete', function ($user) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
         });
         $userSession->listen('\\OC\\User', 'postDelete', function ($user) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
         });
         $userSession->listen('\\OC\\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
         });
         $userSession->listen('\\OC\\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
         });
         $userSession->listen('\\OC\\User', 'preLogin', function ($uid, $password) {
             \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'postLogin', function ($user, $password) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'logout', function () {
             \OC_Hook::emit('OC_User', 'logout', array());
         });
         return $userSession;
     });
     $this->registerService('NavigationManager', function ($c) {
         return new \OC\NavigationManager();
     });
     $this->registerService('AllConfig', function (Server $c) {
         return new \OC\AllConfig($c->getSystemConfig());
     });
     $this->registerService('SystemConfig', function ($c) {
         return new \OC\SystemConfig();
     });
     $this->registerService('AppConfig', function ($c) {
         return new \OC\AppConfig(\OC_DB::getConnection());
     });
     $this->registerService('L10NFactory', function ($c) {
         return new \OC\L10N\Factory();
     });
     $this->registerService('URLGenerator', function (Server $c) {
         $config = $c->getConfig();
         $cacheFactory = $c->getMemCacheFactory();
         return new \OC\URLGenerator($config, $cacheFactory);
     });
     $this->registerService('AppHelper', function ($c) {
         return new \OC\AppHelper();
     });
     $this->registerService('UserCache', function ($c) {
         return new Cache\File();
     });
     $this->registerService('MemCacheFactory', function (Server $c) {
         $config = $c->getConfig();
         if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
             $v = \OC_App::getAppVersions();
             $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
             $version = implode(',', $v);
             $instanceId = \OC_Util::getInstanceId();
             $path = \OC::$SERVERROOT;
             $prefix = md5($instanceId . '-' . $version . '-' . $path);
             return new \OC\Memcache\Factory($prefix, $c->getLogger(), $config->getSystemValue('memcache.local', null), $config->getSystemValue('memcache.distributed', null), $config->getSystemValue('memcache.locking', null));
         }
         return new \OC\Memcache\Factory('', $c->getLogger(), '\\OC\\Memcache\\ArrayCache', '\\OC\\Memcache\\ArrayCache', '\\OC\\Memcache\\ArrayCache');
     });
     $this->registerService('ActivityManager', function (Server $c) {
         return new ActivityManager($c->getRequest(), $c->getUserSession(), $c->getConfig());
     });
     $this->registerService('AvatarManager', function (Server $c) {
         return new AvatarManager($c->getUserManager(), $c->getRootFolder(), $c->getL10N('lib'));
     });
     $this->registerService('Logger', function (Server $c) {
         $logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud');
         $logger = 'OC_Log_' . ucfirst($logClass);
         call_user_func(array($logger, 'init'));
         return new Log($logger);
     });
     $this->registerService('JobList', function (Server $c) {
         $config = $c->getConfig();
         return new \OC\BackgroundJob\JobList($c->getDatabaseConnection(), $config);
     });
     $this->registerService('Router', function (Server $c) {
         $cacheFactory = $c->getMemCacheFactory();
         $logger = $c->getLogger();
         if ($cacheFactory->isAvailable()) {
             $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
         } else {
             $router = new \OC\Route\Router($logger);
         }
         return $router;
     });
     $this->registerService('Search', function ($c) {
         return new Search();
     });
     $this->registerService('SecureRandom', function ($c) {
         return new SecureRandom();
     });
     $this->registerService('Crypto', function (Server $c) {
         return new Crypto($c->getConfig(), $c->getSecureRandom());
     });
     $this->registerService('Hasher', function (Server $c) {
         return new Hasher($c->getConfig());
     });
     $this->registerService('DatabaseConnection', function (Server $c) {
         $factory = new \OC\DB\ConnectionFactory();
         $systemConfig = $c->getSystemConfig();
         $type = $systemConfig->getValue('dbtype', 'sqlite');
         if (!$factory->isValidType($type)) {
             throw new \OC\DatabaseException('Invalid database type');
         }
         $connectionParams = $factory->createConnectionParams($systemConfig);
         $connection = $factory->getConnection($type, $connectionParams);
         $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
         return $connection;
     });
     $this->registerService('Db', function (Server $c) {
         return new Db($c->getDatabaseConnection());
     });
     $this->registerService('HTTPHelper', function (Server $c) {
         $config = $c->getConfig();
         return new HTTPHelper($config, $c->getHTTPClientService());
     });
     $this->registerService('HttpClientService', function (Server $c) {
         $user = \OC_User::getUser();
         $uid = $user ? $user : null;
         return new ClientService($c->getConfig(), new \OC\Security\CertificateManager($uid, new View(), $c->getConfig()));
     });
     $this->registerService('EventLogger', function (Server $c) {
         if ($c->getSystemConfig()->getValue('debug', false)) {
             return new EventLogger();
         } else {
             return new NullEventLogger();
         }
     });
     $this->registerService('QueryLogger', function (Server $c) {
         if ($c->getSystemConfig()->getValue('debug', false)) {
             return new QueryLogger();
         } else {
             return new NullQueryLogger();
         }
     });
     $this->registerService('TempManager', function (Server $c) {
         return new TempManager($c->getLogger(), $c->getConfig());
     });
     $this->registerService('AppManager', function (Server $c) {
         return new \OC\App\AppManager($c->getUserSession(), $c->getAppConfig(), $c->getGroupManager(), $c->getMemCacheFactory());
     });
     $this->registerService('DateTimeZone', function (Server $c) {
         return new DateTimeZone($c->getConfig(), $c->getSession());
     });
     $this->registerService('DateTimeFormatter', function (Server $c) {
         $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
         return new DateTimeFormatter($c->getDateTimeZone()->getTimeZone(), $c->getL10N('lib', $language));
     });
     $this->registerService('MountConfigManager', function () {
         $loader = \OC\Files\Filesystem::getLoader();
         return new \OC\Files\Config\MountProviderCollection($loader);
     });
     $this->registerService('IniWrapper', function ($c) {
         return new IniGetWrapper();
     });
     $this->registerService('AsyncCommandBus', function (Server $c) {
         $jobList = $c->getJobList();
         return new AsyncBus($jobList);
     });
     $this->registerService('TrustedDomainHelper', function ($c) {
         return new TrustedDomainHelper($this->getConfig());
     });
     $this->registerService('IntegrityCodeChecker', function (Server $c) {
         // IConfig and IAppManager requires a working database. This code
         // might however be called when ownCloud is not yet setup.
         if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
             $config = $c->getConfig();
             $appManager = $c->getAppManager();
         } else {
             $config = null;
             $appManager = null;
         }
         return new Checker(new EnvironmentHelper(), new FileAccessHelper(), new AppLocator(), $config, $c->getMemCacheFactory(), $appManager);
     });
     $this->registerService('Request', function ($c) {
         if (isset($this['urlParams'])) {
             $urlParams = $this['urlParams'];
         } else {
             $urlParams = [];
         }
         if ($this->getSession()->exists('requesttoken')) {
             $requestToken = $this->getSession()->get('requesttoken');
         } else {
             $requestToken = false;
         }
         if (defined('PHPUNIT_RUN') && PHPUNIT_RUN && in_array('fakeinput', stream_get_wrappers())) {
             $stream = 'fakeinput://data';
         } else {
             $stream = 'php://input';
         }
         return new Request(['get' => $_GET, 'post' => $_POST, 'files' => $_FILES, 'server' => $_SERVER, 'env' => $_ENV, 'cookies' => $_COOKIE, 'method' => isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null, 'urlParams' => $urlParams, 'requesttoken' => $requestToken], $this->getSecureRandom(), $this->getConfig(), $stream);
     });
     $this->registerService('Mailer', function (Server $c) {
         return new Mailer($c->getConfig(), $c->getLogger(), new \OC_Defaults());
     });
     $this->registerService('OcsClient', function (Server $c) {
         return new OCSClient($this->getHTTPClientService(), $this->getConfig(), $this->getLogger());
     });
     $this->registerService('LockingProvider', function (Server $c) {
         if ($c->getConfig()->getSystemValue('filelocking.enabled', true) or defined('PHPUNIT_RUN') && PHPUNIT_RUN) {
             /** @var \OC\Memcache\Factory $memcacheFactory */
             $memcacheFactory = $c->getMemCacheFactory();
             $memcache = $memcacheFactory->createLocking('lock');
             if (!$memcache instanceof \OC\Memcache\NullCache) {
                 return new MemcacheLockingProvider($memcache);
             }
             return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory());
         }
         return new NoopLockingProvider();
     });
     $this->registerService('MountManager', function () {
         return new \OC\Files\Mount\Manager();
     });
     $this->registerService('MimeTypeDetector', function (Server $c) {
         return new \OC\Files\Type\Detection($c->getURLGenerator(), \OC::$SERVERROOT . '/config/', \OC::$SERVERROOT . '/resources/config/');
     });
     $this->registerService('MimeTypeLoader', function (Server $c) {
         return new \OC\Files\Type\Loader($c->getDatabaseConnection());
     });
     $this->registerService('NotificationManager', function () {
         return new Manager();
     });
     $this->registerService('CapabilitiesManager', function (Server $c) {
         $manager = new \OC\CapabilitiesManager();
         $manager->registerCapability(function () use($c) {
             return new \OC\OCS\CoreCapabilities($c->getConfig());
         });
         return $manager;
     });
     $this->registerService('CommentsManager', function (Server $c) {
         $config = $c->getConfig();
         $factoryClass = $config->getSystemValue('comments.managerFactory', '\\OC\\Comments\\ManagerFactory');
         /** @var \OCP\Comments\ICommentsManagerFactory $factory */
         $factory = new $factoryClass();
         return $factory->getManager();
     });
     $this->registerService('EventDispatcher', function () {
         return new EventDispatcher();
     });
     $this->registerService('CryptoWrapper', function (Server $c) {
         // FIXME: Instantiiated here due to cyclic dependency
         $request = new Request(['get' => $_GET, 'post' => $_POST, 'files' => $_FILES, 'server' => $_SERVER, 'env' => $_ENV, 'cookies' => $_COOKIE, 'method' => isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null], new SecureRandom(), $c->getConfig());
         return new CryptoWrapper($c->getConfig(), $c->getCrypto(), $c->getSecureRandom(), $request);
     });
 }
Пример #5
0
 public function testActiveUserAfterSetSession()
 {
     $users = array('foo' => new User('foo', null), 'bar' => new User('bar', null));
     $manager = $this->getMockBuilder('\\OC\\User\\Manager')->disableOriginalConstructor()->getMock();
     $manager->expects($this->any())->method('get')->will($this->returnCallback(function ($uid) use($users) {
         return $users[$uid];
     }));
     $session = new Memory('');
     $session->set('user_id', 'foo');
     $userSession = new \OC\User\Session($manager, $session);
     $this->assertEquals($users['foo'], $userSession->getUser());
     $session2 = new Memory('');
     $session2->set('user_id', 'bar');
     $userSession->setSession($session2);
     $this->assertEquals($users['bar'], $userSession->getUser());
 }
Пример #6
0
 /**
  * @param string $webRoot
  */
 function __construct($webRoot)
 {
     $this->webRoot = $webRoot;
     $this->registerService('ContactsManager', function ($c) {
         return new ContactsManager();
     });
     $this->registerService('Request', function (Server $c) {
         if (isset($c['urlParams'])) {
             $urlParams = $c['urlParams'];
         } else {
             $urlParams = array();
         }
         if ($c->getSession()->exists('requesttoken')) {
             $requestToken = $c->getSession()->get('requesttoken');
         } else {
             $requestToken = false;
         }
         if (defined('PHPUNIT_RUN') && PHPUNIT_RUN && in_array('fakeinput', stream_get_wrappers())) {
             $stream = 'fakeinput://data';
         } else {
             $stream = 'php://input';
         }
         return new Request(array('get' => $_GET, 'post' => $_POST, 'files' => $_FILES, 'server' => $_SERVER, 'env' => $_ENV, 'cookies' => $_COOKIE, 'method' => isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null, 'urlParams' => $urlParams, 'requesttoken' => $requestToken), $stream);
     });
     $this->registerService('PreviewManager', function ($c) {
         return new PreviewManager();
     });
     $this->registerService('TagMapper', function (Server $c) {
         return new TagMapper($c->getDb());
     });
     $this->registerService('TagManager', function (Server $c) {
         $tagMapper = $c->query('TagMapper');
         return new TagManager($tagMapper, $c->getUserSession());
     });
     $this->registerService('RootFolder', function (Server $c) {
         // TODO: get user and user manager from container as well
         $user = \OC_User::getUser();
         /** @var $c SimpleContainer */
         $userManager = $c->query('UserManager');
         $user = $userManager->get($user);
         $manager = \OC\Files\Filesystem::getMountManager();
         $view = new View();
         return new Root($manager, $view, $user);
     });
     $this->registerService('UserManager', function (Server $c) {
         $config = $c->getConfig();
         return new \OC\User\Manager($config);
     });
     $this->registerService('GroupManager', function (Server $c) {
         $groupManager = new \OC\Group\Manager($this->getUserManager());
         $groupManager->listen('\\OC\\Group', 'preCreate', function ($gid) {
             \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
         });
         $groupManager->listen('\\OC\\Group', 'postCreate', function (\OC\Group\Group $gid) {
             \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'preDelete', function (\OC\Group\Group $group) {
             \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'postDelete', function (\OC\Group\Group $group) {
             \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
             \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
             \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
         });
         return $groupManager;
     });
     $this->registerService('UserSession', function (Server $c) {
         $manager = $c->getUserManager();
         $userSession = new \OC\User\Session($manager, new \OC\Session\Memory(''));
         $userSession->listen('\\OC\\User', 'preCreateUser', function ($uid, $password) {
             \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'postCreateUser', function ($user, $password) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'preDelete', function ($user) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
         });
         $userSession->listen('\\OC\\User', 'postDelete', function ($user) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
         });
         $userSession->listen('\\OC\\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
         });
         $userSession->listen('\\OC\\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
         });
         $userSession->listen('\\OC\\User', 'preLogin', function ($uid, $password) {
             \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'postLogin', function ($user, $password) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'logout', function () {
             \OC_Hook::emit('OC_User', 'logout', array());
         });
         return $userSession;
     });
     $this->registerService('NavigationManager', function ($c) {
         return new \OC\NavigationManager();
     });
     $this->registerService('AllConfig', function (Server $c) {
         return new \OC\AllConfig($c->getSystemConfig());
     });
     $this->registerService('SystemConfig', function ($c) {
         return new \OC\SystemConfig();
     });
     $this->registerService('AppConfig', function ($c) {
         return new \OC\AppConfig(\OC_DB::getConnection());
     });
     $this->registerService('L10NFactory', function ($c) {
         return new \OC\L10N\Factory();
     });
     $this->registerService('URLGenerator', function (Server $c) {
         $config = $c->getConfig();
         return new \OC\URLGenerator($config);
     });
     $this->registerService('AppHelper', function ($c) {
         return new \OC\AppHelper();
     });
     $this->registerService('UserCache', function ($c) {
         return new UserCache();
     });
     $this->registerService('MemCacheFactory', function ($c) {
         $instanceId = \OC_Util::getInstanceId();
         return new \OC\Memcache\Factory($instanceId);
     });
     $this->registerService('RedisSession', function (Server $c) {
         return new \OC\Session\redisSession($c->getSystemConfig()->getValue('redis'));
     });
     $this->registerService('ActivityManager', function ($c) {
         return new ActivityManager();
     });
     $this->registerService('AvatarManager', function ($c) {
         return new AvatarManager();
     });
     $this->registerService('Logger', function (Server $c) {
         $logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud');
         $logger = 'OC_Log_' . ucfirst($logClass);
         call_user_func(array($logger, 'init'));
         return new Log($logger);
     });
     $this->registerService('JobList', function (Server $c) {
         $config = $c->getConfig();
         return new \OC\BackgroundJob\JobList($c->getDatabaseConnection(), $config);
     });
     $this->registerService('Router', function (Server $c) {
         $cacheFactory = $c->getMemCacheFactory();
         if ($cacheFactory->isAvailable()) {
             $router = new \OC\Route\CachingRouter($cacheFactory->create('route'));
         } else {
             $router = new \OC\Route\Router();
         }
         return $router;
     });
     $this->registerService('Search', function ($c) {
         return new Search();
     });
     $this->registerService('SecureRandom', function ($c) {
         return new SecureRandom();
     });
     $this->registerService('Crypto', function (Server $c) {
         return new Crypto($c->getConfig(), $c->getSecureRandom());
     });
     $this->registerService('Hasher', function (Server $c) {
         return new Hasher($c->getConfig());
     });
     $this->registerService('DatabaseConnection', function (Server $c) {
         $factory = new \OC\DB\ConnectionFactory();
         $systemConfig = $c->getSystemConfig();
         $type = $systemConfig->getValue('dbtype', 'sqlite');
         if (!$factory->isValidType($type)) {
             throw new \OC\DatabaseException('Invalid database type');
         }
         $connectionParams = $factory->createConnectionParams($systemConfig);
         $connection = $factory->getConnection($type, $connectionParams);
         $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
         return $connection;
     });
     $this->registerService('Db', function (Server $c) {
         return new Db($c->getDatabaseConnection());
     });
     $this->registerService('HTTPHelper', function (Server $c) {
         $config = $c->getConfig();
         $user = $c->getUserSession()->getUser();
         $uid = $user ? $user->getUID() : null;
         return new HTTPHelper($config, new \OC\Security\CertificateManager($uid, new \OC\Files\View()));
     });
     $this->registerService('EventLogger', function (Server $c) {
         if (defined('DEBUG') and DEBUG) {
             return new EventLogger();
         } else {
             return new NullEventLogger();
         }
     });
     $this->registerService('QueryLogger', function ($c) {
         if (defined('DEBUG') and DEBUG) {
             return new QueryLogger();
         } else {
             return new NullQueryLogger();
         }
     });
     $this->registerService('TempManager', function (Server $c) {
         return new TempManager(get_temp_dir(), $c->getLogger());
     });
     $this->registerService('AppManager', function (Server $c) {
         $userSession = $c->getUserSession();
         $appConfig = $c->getAppConfig();
         $groupManager = $c->getGroupManager();
         return new \OC\App\AppManager($userSession, $appConfig, $groupManager);
     });
     $this->registerService('DateTimeZone', function (Server $c) {
         return new DateTimeZone($c->getConfig(), $c->getSession());
     });
     $this->registerService('DateTimeFormatter', function (Server $c) {
         $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
         return new DateTimeFormatter($c->getDateTimeZone()->getTimeZone(), $c->getL10N('lib', $language));
     });
     $this->registerService('MountConfigManager', function () {
         $loader = \OC\Files\Filesystem::getLoader();
         return new \OC\Files\Config\MountProviderCollection($loader);
     });
     $this->registerService('IniWrapper', function ($c) {
         return new IniGetWrapper();
     });
 }
Пример #7
0
 function __construct()
 {
     $this->registerService('ContactsManager', function ($c) {
         return new ContactsManager();
     });
     $this->registerService('Request', function ($c) {
         if (isset($c['urlParams'])) {
             $urlParams = $c['urlParams'];
         } else {
             $urlParams = array();
         }
         if (\OC::$session->exists('requesttoken')) {
             $requesttoken = \OC::$session->get('requesttoken');
         } else {
             $requesttoken = false;
         }
         if (defined('PHPUNIT_RUN') && PHPUNIT_RUN && in_array('fakeinput', stream_get_wrappers())) {
             $stream = 'fakeinput://data';
         } else {
             $stream = 'php://input';
         }
         return new Request(array('get' => $_GET, 'post' => $_POST, 'files' => $_FILES, 'server' => $_SERVER, 'env' => $_ENV, 'cookies' => $_COOKIE, 'method' => isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null, 'urlParams' => $urlParams, 'requesttoken' => $requesttoken), $stream);
     });
     $this->registerService('PreviewManager', function ($c) {
         return new PreviewManager();
     });
     $this->registerService('TagManager', function ($c) {
         $user = \OC_User::getUser();
         return new TagManager($user);
     });
     $this->registerService('RootFolder', function ($c) {
         // TODO: get user and user manager from container as well
         $user = \OC_User::getUser();
         /** @var $c SimpleContainer */
         $userManager = $c->query('UserManager');
         $user = $userManager->get($user);
         $manager = \OC\Files\Filesystem::getMountManager();
         $view = new View();
         return new Root($manager, $view, $user);
     });
     $this->registerService('UserManager', function ($c) {
         /**
          * @var SimpleContainer $c
          * @var \OC\AllConfig $config
          */
         $config = $c->query('AllConfig');
         return new \OC\User\Manager($config);
     });
     $this->registerService('UserSession', function ($c) {
         /**
          * @var SimpleContainer $c
          * @var \OC\User\Manager $manager
          */
         $manager = $c->query('UserManager');
         $userSession = new \OC\User\Session($manager, \OC::$session);
         $userSession->listen('\\OC\\User', 'preCreateUser', function ($uid, $password) {
             \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'postCreateUser', function ($user, $password) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'preDelete', function ($user) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
         });
         $userSession->listen('\\OC\\User', 'postDelete', function ($user) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
         });
         $userSession->listen('\\OC\\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
         });
         $userSession->listen('\\OC\\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
         });
         $userSession->listen('\\OC\\User', 'preLogin', function ($uid, $password) {
             \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'postLogin', function ($user, $password) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'logout', function () {
             \OC_Hook::emit('OC_User', 'logout', array());
         });
         return $userSession;
     });
     $this->registerService('NavigationManager', function ($c) {
         return new \OC\NavigationManager();
     });
     $this->registerService('AllConfig', function ($c) {
         return new \OC\AllConfig();
     });
     $this->registerService('L10NFactory', function ($c) {
         return new \OC\L10N\Factory();
     });
     $this->registerService('URLGenerator', function ($c) {
         return new \OC\URLGenerator();
     });
     $this->registerService('AppHelper', function ($c) {
         return new \OC\AppHelper();
     });
     $this->registerService('UserCache', function ($c) {
         return new UserCache();
     });
     $this->registerService('ActivityManager', function ($c) {
         return new ActivityManager();
     });
     $this->registerService('AvatarManager', function ($c) {
         return new AvatarManager();
     });
     $this->registerService('HTTPHelper', function (SimpleContainer $c) {
         $config = $c->query('AllConfig');
         return new HTTPHelper($config);
     });
     $this->registerService('TempManager', function ($c) {
         /** @var Server $c */
         return new TempManager(get_temp_dir(), \OC_Log::$object);
     });
 }
Пример #8
0
 public function testRememberLoginInvalidUser()
 {
     $session = $this->getMock('\\OC\\Session\\Memory', array(), array(''));
     $session->expects($this->never())->method('set');
     $managerMethods = get_class_methods('\\OC\\User\\Manager');
     //keep following methods intact in order to ensure hooks are
     //working
     $doNotMock = array('__construct', 'emit', 'listen');
     foreach ($doNotMock as $methodName) {
         $i = array_search($methodName, $managerMethods, true);
         if ($i !== false) {
             unset($managerMethods[$i]);
         }
     }
     $manager = $this->getMock('\\OC\\User\\Manager', $managerMethods, array());
     $backend = $this->getMock('OC_User_Dummy');
     $user = $this->getMock('\\OC\\User\\User', array(), array('foo', $backend));
     $user->expects($this->never())->method('getUID');
     $user->expects($this->never())->method('updateLastLoginTimestamp');
     $manager->expects($this->once())->method('get')->with('foo')->will($this->returnValue(null));
     //prepare login token
     $token = 'goodToken';
     \OC_Preferences::setValue('foo', 'login_token', $token, time());
     //also set the \OC::$session or the \OC\User\Session will use it
     \OC::$session = $session;
     $userSession = new \OC\User\Session($manager, $session);
     $granted = $userSession->loginWithCookie('foo', $token);
     $this->assertSame($granted, false);
 }
Пример #9
0
 public function testUpdateSessionTokenPasswordInvalidTokenException()
 {
     $userManager = $this->getMock('\\OCP\\IUserManager');
     $session = $this->getMock('\\OCP\\ISession');
     $timeFactory = $this->getMock('\\OCP\\AppFramework\\Utility\\ITimeFactory');
     $tokenProvider = $this->getMock('\\OC\\Authentication\\Token\\IProvider');
     $userSession = new \OC\User\Session($userManager, $session, $timeFactory, $tokenProvider, $this->config);
     $password = '******';
     $sessionId = 'session1234';
     $token = new \OC\Authentication\Token\DefaultToken();
     $session->expects($this->once())->method('getId')->will($this->returnValue($sessionId));
     $tokenProvider->expects($this->once())->method('getToken')->with($sessionId)->will($this->returnValue($token));
     $tokenProvider->expects($this->once())->method('setPassword')->with($token, $sessionId, $password)->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException()));
     $userSession->updateSessionTokenPassword($password);
 }