From f559ff78294a4c2b4aa7cc2935b49281cbfe858b Mon Sep 17 00:00:00 2001
From: xjm <xjm@65776.no-reply.drupal.org>
Date: Sat, 25 Apr 2015 19:59:51 -0500
Subject: [PATCH] Issue #2347799 by andypost, almaudoh, znerol: Remove bugged
 session-related methods from AccountInterface

---
 .../Drupal/Core/Session/AccountInterface.php  | 31 ----------
 core/lib/Drupal/Core/Session/AccountProxy.php | 28 ---------
 .../Core/Session/AnonymousUserSession.php     |  3 -
 core/lib/Drupal/Core/Session/UserSession.php  | 62 +------------------
 .../src/Authentication/Provider/Cookie.php    |  5 --
 core/modules/user/src/Entity/User.php         | 38 ------------
 .../Core/Session/AnonymousUserSessionTest.php | 36 -----------
 7 files changed, 3 insertions(+), 200 deletions(-)

diff --git a/core/lib/Drupal/Core/Session/AccountInterface.php b/core/lib/Drupal/Core/Session/AccountInterface.php
index a52195c46091..fa437c0205c6 100644
--- a/core/lib/Drupal/Core/Session/AccountInterface.php
+++ b/core/lib/Drupal/Core/Session/AccountInterface.php
@@ -57,30 +57,6 @@ public function getRoles($exclude_locked_roles = FALSE);
    */
   public function hasPermission($permission);
 
-  /**
-   * Returns the session ID.
-   *
-   * @return string|null
-   *   The session ID or NULL if this user does not have an active session.
-   */
-  public function getSessionId();
-
-  /**
-   * Returns the secure session ID.
-   *
-   * @return string|null
-   *   The session ID or NULL if this user does not have an active secure session.
-   */
-  public function getSecureSessionId();
-
-  /**
-   * Returns the session data.
-   *
-   * @return array
-   *   Array with the session data that belongs to this object.
-   */
-  public function getSessionData();
-
   /**
    * Returns TRUE if the account is authenticated.
    *
@@ -173,11 +149,4 @@ public function getTimeZone();
    */
   public function getLastAccessedTime();
 
-  /**
-   * Returns the session hostname.
-   *
-   * @return string
-   */
-  public function getHostname();
-
 }
diff --git a/core/lib/Drupal/Core/Session/AccountProxy.php b/core/lib/Drupal/Core/Session/AccountProxy.php
index eae71e7731db..ff5c4f4b513e 100644
--- a/core/lib/Drupal/Core/Session/AccountProxy.php
+++ b/core/lib/Drupal/Core/Session/AccountProxy.php
@@ -80,13 +80,6 @@ public function getRoles($exclude_locked_roles = FALSE) {
     return $this->getAccount()->getRoles($exclude_locked_roles);
   }
 
-  /**
-   * {@inheritdoc}
-   */
-  public function getHostname() {
-    return $this->getAccount()->getHostname();
-  }
-
   /**
    * {@inheritdoc}
    */
@@ -94,27 +87,6 @@ public function hasPermission($permission) {
     return $this->getAccount()->hasPermission($permission);
   }
 
-  /**
-   * {@inheritdoc}
-   */
-  public function getSessionId() {
-    return $this->getAccount()->getSessionId();
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function getSecureSessionId() {
-    return $this->getAccount()->getSecureSessionId();
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function getSessionData() {
-    return $this->getAccount()->getSessionData();
-  }
-
   /**
    * {@inheritdoc}
    */
diff --git a/core/lib/Drupal/Core/Session/AnonymousUserSession.php b/core/lib/Drupal/Core/Session/AnonymousUserSession.php
index 56e065ccf0d0..de0527d394dc 100644
--- a/core/lib/Drupal/Core/Session/AnonymousUserSession.php
+++ b/core/lib/Drupal/Core/Session/AnonymousUserSession.php
@@ -18,9 +18,6 @@ class AnonymousUserSession extends UserSession {
    * Intentionally don't allow parameters to be passed in like UserSession.
    */
   public function __construct() {
-    if (\Drupal::hasRequest()) {
-      $this->hostname = \Drupal::request()->getClientIp();
-    }
   }
 
 }
diff --git a/core/lib/Drupal/Core/Session/UserSession.php b/core/lib/Drupal/Core/Session/UserSession.php
index 6181f244ebcf..ce4b5081dc09 100644
--- a/core/lib/Drupal/Core/Session/UserSession.php
+++ b/core/lib/Drupal/Core/Session/UserSession.php
@@ -31,32 +31,11 @@ class UserSession implements AccountInterface {
   protected $roles = array(AccountInterface::ANONYMOUS_ROLE);
 
   /**
-   * Session ID.
+   * The Unix timestamp when the user last accessed the site.
    *
    * @var string.
    */
-  public $sid;
-
-  /**
-   * Secure session ID.
-   *
-   * @var string.
-   */
-  public $ssid;
-
-  /**
-   * Session data.
-   *
-   * @var array.
-   */
-  public $session;
-
-  /**
-   * The Unix timestamp when this session last requested a page.
-   *
-   * @var string.
-   */
-  protected $timestamp;
+  protected $access;
 
   /**
    * The name of this account.
@@ -93,13 +72,6 @@ class UserSession implements AccountInterface {
    */
   protected $timezone;
 
-  /**
-   * The hostname for this user session.
-   *
-   * @var string
-   */
-  protected $hostname = '';
-
   /**
    * Constructs a new user session.
    *
@@ -144,27 +116,6 @@ public function hasPermission($permission) {
     return $this->getRoleStorage()->isPermissionInRoles($permission, $this->getRoles());
   }
 
-  /**
-   * {@inheritdoc}
-   */
-  public function getSecureSessionId() {
-    return $this->ssid;
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function getSessionData() {
-    return $this->session;
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function getSessionId() {
-    return $this->sid;
-  }
-
   /**
    * {@inheritdoc}
    */
@@ -232,14 +183,7 @@ public function getTimeZone() {
    * {@inheritdoc}
    */
   public function getLastAccessedTime() {
-    return $this->timestamp;
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function getHostname() {
-    return $this->hostname;
+    return $this->access;
   }
 
   /**
diff --git a/core/modules/user/src/Authentication/Provider/Cookie.php b/core/modules/user/src/Authentication/Provider/Cookie.php
index bac9e15396ca..22ac903705ab 100644
--- a/core/modules/user/src/Authentication/Provider/Cookie.php
+++ b/core/modules/user/src/Authentication/Provider/Cookie.php
@@ -81,11 +81,6 @@ protected function getUserFromSession(SessionInterface $session) {
 
       // Check if the user data was found and the user is active.
       if (!empty($values) && $values['status'] == 1) {
-        // UserSession::getLastAccessedTime() returns session save timestamp,
-        // while User::getLastAccessedTime() returns the user 'access'
-        // timestamp. This ensures they are synchronized.
-        $values['timestamp'] = $values['access'];
-
         // Add the user's roles.
         $rids = $this->connection
           ->query('SELECT roles_target_id FROM {user__roles} WHERE entity_id = :uid', [':uid' => $values['uid']])
diff --git a/core/modules/user/src/Entity/User.php b/core/modules/user/src/Entity/User.php
index 1a78c98a9875..fa4db6ffef56 100644
--- a/core/modules/user/src/Entity/User.php
+++ b/core/modules/user/src/Entity/User.php
@@ -69,13 +69,6 @@ class User extends ContentEntityBase implements UserInterface {
    */
   protected static $anonymousUser;
 
-  /**
-   * The hostname for this user.
-   *
-   * @var string
-   */
-  protected $hostname;
-
   /**
    * {@inheritdoc}
    */
@@ -170,37 +163,6 @@ public function getRoles($exclude_locked_roles = FALSE) {
     return $roles;
   }
 
-  /**
-   * {@inheritdoc}
-   */
-  public function getSecureSessionId() {
-    return NULL;
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function getSessionData() {
-    return array();
-  }
-  /**
-   * {@inheritdoc}
-   */
-  public function getSessionId() {
-    return NULL;
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function getHostname() {
-    if (!isset($this->hostname) && \Drupal::hasRequest()) {
-      $this->hostname = \Drupal::request()->getClientIp();
-    }
-
-    return $this->hostname;
-  }
-
   /**
    * {@inheritdoc}
    */
diff --git a/core/tests/Drupal/Tests/Core/Session/AnonymousUserSessionTest.php b/core/tests/Drupal/Tests/Core/Session/AnonymousUserSessionTest.php
index 4ac0c76ce6db..043e17ecf0c1 100644
--- a/core/tests/Drupal/Tests/Core/Session/AnonymousUserSessionTest.php
+++ b/core/tests/Drupal/Tests/Core/Session/AnonymousUserSessionTest.php
@@ -21,42 +21,6 @@
  */
 class AnonymousUserSessionTest extends UnitTestCase {
 
-  /**
-   * Tests creating an AnonymousUserSession when the request is available.
-   *
-   * @covers ::__construct
-   */
-  public function testAnonymousUserSessionWithRequest() {
-    $request = $this->getMock('Symfony\Component\HttpFoundation\Request');
-    $request->expects($this->once())
-      ->method('getClientIp')
-      ->will($this->returnValue('test'));
-    $container = new ContainerBuilder();
-    $requestStack = new RequestStack();
-    $requestStack->push($request);
-    $container->set('request_stack', $requestStack);
-    \Drupal::setContainer($container);
-
-    $anonymous_user = new AnonymousUserSession();
-
-    $this->assertSame('test', $anonymous_user->getHostname());
-  }
-
-  /**
-   * Tests creating an AnonymousUserSession when the request is not available.
-   *
-   * @covers ::__construct
-   */
-  public function testAnonymousUserSessionWithNoRequest() {
-    $container = new ContainerBuilder();
-
-    \Drupal::setContainer($container);
-
-    $anonymous_user = new AnonymousUserSession();
-
-    $this->assertSame('', $anonymous_user->getHostname());
-  }
-
   /**
    * Tests the method getRoles exclude or include locked roles based in param.
    *
-- 
GitLab