public static function start()
 {
     $app = Core::make('app');
     if ($app->isRunThroughCommandLineInterface()) {
         $storage = new MockArraySessionStorage();
     } else {
         if (Config::get('concrete.session.handler') == 'database') {
             $db = \Database::get();
             $storage = new NativeSessionStorage(array(), new PdoSessionHandler($db->getWrappedConnection(), array('db_table' => 'Sessions', 'db_id_col' => 'sessionID', 'db_data_col' => 'sessionValue', 'db_time_col' => 'sessionTime')));
         } else {
             //$storage = new NativeSessionStorage(array(), new NativeFileSessionHandler());
             $storage = new NativeSessionStorage(array());
         }
         $options = Config::get('concrete.session.cookie');
         if ($options['cookie_path'] === false) {
             $options['cookie_path'] = $app['app_relative_path'] . '/';
         }
         $options['gc_max_lifetime'] = Config::get('concrete.session.max_lifetime');
         $storage->setOptions($options);
     }
     $session = new SymfonySession($storage);
     $session->setName(Config::get('concrete.session.name'));
     static::testSessionFixation($session);
     return $session;
 }
    /**
     * @param array $options
     *
     * @return NativeSessionStorage
     */
    protected function getStorage(array $options = array())
    {
        $storage = new NativeSessionStorage($options);
        $storage->registerBag(new AttributeBag());

        return $storage;
    }
 public function testConstruct()
 {
     $storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeFileSessionHandler(sys_get_temp_dir()));
     $this->assertEquals('files', $storage->getSaveHandler()->getSaveHandlerName());
     $this->assertEquals('user', ini_get('session.save_handler'));
     $this->assertEquals(sys_get_temp_dir(), ini_get('session.save_path'));
     $this->assertEquals('TESTING', ini_get('session.name'));
 }
 public function onSiteAccessMatch(PostSiteAccessMatchEvent $event)
 {
     if (!($event->getRequestType() === HttpKernelInterface::MASTER_REQUEST && isset($this->session) && !$this->session->isStarted() && $this->sessionStorage instanceof NativeSessionStorage)) {
         return;
     }
     $sessionOptions = (array) $this->configResolver->getParameter('session');
     $sessionName = isset($sessionOptions['name']) ? $sessionOptions['name'] : $this->session->getName();
     $sessionOptions['name'] = $this->getSessionName($sessionName, $event->getSiteAccess());
     $this->sessionStorage->setOptions($sessionOptions);
 }
 public function test__Construct()
 {
     $storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeFileSessionHandler(sys_get_temp_dir()));
     if (version_compare(phpversion(), '5.4.0', '<')) {
         $this->assertEquals('files', $storage->getSaveHandler()->getSaveHandlerName());
         $this->assertEquals('files', ini_get('session.save_handler'));
     } else {
         $this->assertEquals('files', $storage->getSaveHandler()->getSaveHandlerName());
         $this->assertEquals('user', ini_get('session.save_handler'));
     }
     $this->assertEquals(sys_get_temp_dir(), ini_get('session.save_path'));
     $this->assertEquals('TESTING', ini_get('session.name'));
 }
Example #6
0
 /**
  * setOptions.
  *
  * {@inheritDoc}
  */
 public function setOptions(array $options)
 {
     if (isset($_SERVER['HTTP_HOST'])) {
         $options["cookie_domain"] = '.' . $_SERVER['HTTP_HOST'];
     }
     return parent::setOptions($options);
 }
 /**
  * {@inheritdoc}
  */
 public function setOptions(array $options)
 {
     $options['cookie_domain'] = '.' . $this->domain;
     $options['cookie_httponly'] = true;
     $options['name'] = 'SUPERDESKPUBLISHER';
     parent::setOptions($options);
 }
 public function testSaveHandlers()
 {
     if (!extension_loaded('sqlite')) {
         $this->markTestSkipped('Skipped tests SQLite extension is not present');
     }
     $storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeSqliteSessionHandler(sys_get_temp_dir() . '/sqlite.db'));
     if (version_compare(phpversion(), '5.4.0', '<')) {
         $this->assertEquals('sqlite', $storage->getSaveHandler()->getSaveHandlerName());
         $this->assertEquals('sqlite', ini_get('session.save_handler'));
     } else {
         $this->assertEquals('sqlite', $storage->getSaveHandler()->getSaveHandlerName());
         $this->assertEquals('user', ini_get('session.save_handler'));
     }
     $this->assertEquals(sys_get_temp_dir() . '/sqlite.db', ini_get('session.save_path'));
     $this->assertEquals('TESTING', ini_get('session.name'));
 }
 public function setOptions( array $options )
 {
     if ( $this->innerSessionStorage instanceof NativeSessionStorage )
     {
         $this->innerSessionStorage->setOptions( $options );
     }
 }
 public function testSaveHandlers()
 {
     if (!extension_loaded('redis')) {
         $this->markTestSkipped('Skipped tests Redis extension is not present');
     }
     $storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeRedisSessionHandler('tcp://127.0.0.1:6379?persistent=0'));
     if (version_compare(phpversion(), '5.4.0', '<')) {
         $this->assertEquals('redis', $storage->getSaveHandler()->getSaveHandlerName());
         $this->assertEquals('redis', ini_get('session.save_handler'));
     } else {
         $this->assertEquals('redis', $storage->getSaveHandler()->getSaveHandlerName());
         $this->assertEquals('user', ini_get('session.save_handler'));
     }
     $this->assertEquals('tcp://127.0.0.1:6379?persistent=0', ini_get('session.save_path'));
     $this->assertEquals('TESTING', ini_get('session.name'));
 }
 /**
  * @param \Illuminate\Config\Repository $config
  * @return \Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface
  */
 private function getSessionStorage(Repository $config)
 {
     $app = $this->app;
     if ($app->isRunThroughCommandLineInterface()) {
         $storage = new MockArraySessionStorage();
     } else {
         $handler = $this->getSessionHandler($config);
         $storage = new NativeSessionStorage(array(), $handler);
         // Initialize the storage with some options
         $options = $config->get('concrete.session.cookie');
         if ($options['cookie_path'] === false) {
             $options['cookie_path'] = $app['app_relative_path'] . '/';
         }
         $options['gc_maxlifetime'] = $config->get('concrete.session.max_lifetime');
         $storage->setOptions($options);
     }
     return $storage;
 }
 public function testSaveHandlers()
 {
     if (!extension_loaded('memcached')) {
         $this->markTestSkipped('Skipped tests memcached extension is not present');
     }
     // test takes too long if memcached server is not running
     ini_set('memcached.sess_locking', '0');
     $storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeMemcachedSessionHandler('127.0.0.1:11211'));
     if (version_compare(phpversion(), '5.4.0', '<')) {
         $this->assertEquals('memcached', $storage->getSaveHandler()->getSaveHandlerName());
         $this->assertEquals('memcached', ini_get('session.save_handler'));
     } else {
         $this->assertEquals('memcached', $storage->getSaveHandler()->getSaveHandlerName());
         $this->assertEquals('user', ini_get('session.save_handler'));
     }
     $this->assertEquals('127.0.0.1:11211', ini_get('session.save_path'));
     $this->assertEquals('TESTING', ini_get('session.name'));
 }
Example #13
0
 /**
  * {@inheritdoc}
  */
 public function save()
 {
     if ($this->isCli()) {
         // We don't have anything to do if we are not allowed to save the session.
         return;
     }
     if ($this->isSessionObsolete()) {
         // There is no session data to store, destroy the session if it was
         // previously started.
         if ($this->getSaveHandler()->isActive()) {
             $this->destroy();
         }
     } else {
         // There is session data to store. Start the session if it is not already
         // started.
         if (!$this->getSaveHandler()->isActive()) {
             $this->startNow();
         }
         // Write the session data.
         parent::save();
     }
     $this->startedLazy = FALSE;
 }
 public function prodSession(SessionEvent $event)
 {
     $storage = new NativeSessionStorage(['cookie_lifetime' => ConfigQuery::read('session_config.lifetime', 0)]);
     $storage->setSaveHandler(new NativeFileSessionHandler(ConfigQuery::read("session_config.save_path", THELIA_ROOT . '/local/session/')));
     $event->setSession($this->getSession($storage));
 }
Example #15
0
 /**
  * {@inheritdoc}
  */
 public function save()
 {
     global $user;
     if (!$this->isEnabled() || $this->isCli()) {
         // We don't have anything to do if we are not allowed to save the session.
         return;
     }
     if ($user->isAnonymous() && $this->isSessionObsolete()) {
         // There is no session data to store, destroy the session if it was
         // previously started.
         if ($this->getSaveHandler()->isActive()) {
             session_destroy();
         }
     } else {
         // There is session data to store. Start the session if it is not already
         // started.
         if (!$this->getSaveHandler()->isActive()) {
             $this->start();
             if ($this->requestStack->getCurrentRequest()->isSecure() && $this->isMixedMode()) {
                 $insecure_session_name = $this->getInsecureName();
                 $params = session_get_cookie_params();
                 $expire = $params['lifetime'] ? REQUEST_TIME + $params['lifetime'] : 0;
                 $cookie_params = $this->requestStack->getCurrentRequest()->cookies;
                 setcookie($insecure_session_name, $cookie_params->get($insecure_session_name), $expire, $params['path'], $params['domain'], FALSE, $params['httponly']);
             }
         }
         // Write the session data.
         parent::save();
     }
     $this->startedLazy = FALSE;
 }
Example #16
0
 /**
  * {@inheritdoc}
  */
 public function regenerate($destroy = false, $lifetime = null)
 {
     parent::regenerate($destroy);
 }
Example #17
0
 /**
  * Session constructor.
  * @param array|String $options
  * ***********************************************************************************
  * #------------- [options] -------------#
  * List of options for $options array with their defaults.
  *
  * @see http://php.net/session.configuration for options
  * but we omit 'session.' from the beginning of the keys for convenience.
  *
  * ("auto_start", is not supported as it tells PHP to start a session before
  * PHP starts to execute user-land code. Setting during runtime has no effect).
  *
  * cache_limiter, "" (use "0" to prevent headers from being sent entirely).
  * cookie_domain, ""
  * cookie_httponly, ""
  * cookie_lifetime, "0"
  * cookie_path, "/"
  * cookie_secure, ""
  * entropy_file, ""
  * entropy_length, "0"
  * gc_divisor, "100"
  * gc_maxlifetime, "1440"
  * gc_probability, "1"
  * hash_bits_per_character, "4"
  * hash_function, "0"
  * name, "PHPSESSID"
  * referer_check, ""
  * serialize_handler, "php"
  * use_cookies, "1"
  * use_only_cookies, "1"
  * use_trans_sid, "0"
  * upload_progress.enabled, "1"
  * upload_progress.cleanup, "1"
  * upload_progress.prefix, "upload_progress_"
  * upload_progress.name, "PHP_SESSION_UPLOAD_PROGRESS"
  * upload_progress.freq, "1%"
  * upload_progress.min-freq, "1"
  * url_rewriter.tags, "a=href,area=href,frame=src,form=,fieldset="
  *
  *
  * #------------- [handler] -------------#
  * prefix, "sid_"
  * expiretime, 86400
  * ***********************************************************************************
  *
  * @param boolean $createNew Create new session id, destroy old session from cookie and storage.
  * @param null|String $driver
  * @param null|string $driverConfig
  */
 public function __construct($options, $createNew = false, $driver = null, $driverConfig = null)
 {
     is_string($options) && ($options = config($options));
     $options = $options ?: config(env("SESSION_DEFAULT_OPTIONS"));
     if (!$options || !$options['handler'] || !$options['options']) {
         throw new \RuntimeException("Invalid options: " . var_export($options, true));
     }
     $driver = $driver ?: env("SESSION_DRIVER", 'file');
     $driverConfig = $driverConfig ?: env("SESSION_DRIVER_CONFIG");
     $optionsHandler = $options['handler'];
     switch ($driver = strtolower($driver)) {
         case 'redis':
         case 'predis':
         case 'memcache':
         case 'memcached':
         case 'mongodb':
         case 'mongo':
         case 'pdo':
         case 'file':
             $handler = call_user_func_array([$this, "{$driver}SessionHandler"], [$driverConfig, $optionsHandler]);
             break;
         default:
             throw new \RuntimeException("The session driver not support.");
             break;
     }
     $optionsStorage = $options['options'];
     $storage = new NativeSessionStorage($optionsStorage, $handler);
     $attributes = new AttributeBag("_ips_attributes");
     if ($createNew) {
         $session_name = isset($options['options']['name']) ? $options['options']['name'] : "PHPSESSID";
         if (isset($_COOKIE[$session_name])) {
             $old_session_id = $_COOKIE[$session_name];
             $_COOKIE[$session_name] = null;
             @$storage->getSaveHandler()->destroy($old_session_id);
         }
     }
     parent::__construct($storage, $attributes);
 }