Issue #2347799 by andypost, almaudoh, znerol: Remove bugged session-related methods from AccountInterface
parent
609018528f
commit
f559ff7829
|
@ -57,30 +57,6 @@ interface AccountInterface {
|
||||||
*/
|
*/
|
||||||
public function hasPermission($permission);
|
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.
|
* Returns TRUE if the account is authenticated.
|
||||||
*
|
*
|
||||||
|
@ -173,11 +149,4 @@ interface AccountInterface {
|
||||||
*/
|
*/
|
||||||
public function getLastAccessedTime();
|
public function getLastAccessedTime();
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the session hostname.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getHostname();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,13 +80,6 @@ class AccountProxy implements AccountProxyInterface {
|
||||||
return $this->getAccount()->getRoles($exclude_locked_roles);
|
return $this->getAccount()->getRoles($exclude_locked_roles);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getHostname() {
|
|
||||||
return $this->getAccount()->getHostname();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
@ -94,27 +87,6 @@ class AccountProxy implements AccountProxyInterface {
|
||||||
return $this->getAccount()->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}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -18,9 +18,6 @@ class AnonymousUserSession extends UserSession {
|
||||||
* Intentionally don't allow parameters to be passed in like UserSession.
|
* Intentionally don't allow parameters to be passed in like UserSession.
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
if (\Drupal::hasRequest()) {
|
|
||||||
$this->hostname = \Drupal::request()->getClientIp();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,32 +31,11 @@ class UserSession implements AccountInterface {
|
||||||
protected $roles = array(AccountInterface::ANONYMOUS_ROLE);
|
protected $roles = array(AccountInterface::ANONYMOUS_ROLE);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Session ID.
|
* The Unix timestamp when the user last accessed the site.
|
||||||
*
|
*
|
||||||
* @var string.
|
* @var string.
|
||||||
*/
|
*/
|
||||||
public $sid;
|
protected $access;
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of this account.
|
* The name of this account.
|
||||||
|
@ -93,13 +72,6 @@ class UserSession implements AccountInterface {
|
||||||
*/
|
*/
|
||||||
protected $timezone;
|
protected $timezone;
|
||||||
|
|
||||||
/**
|
|
||||||
* The hostname for this user session.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $hostname = '';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new user session.
|
* Constructs a new user session.
|
||||||
*
|
*
|
||||||
|
@ -144,27 +116,6 @@ class UserSession implements AccountInterface {
|
||||||
return $this->getRoleStorage()->isPermissionInRoles($permission, $this->getRoles());
|
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}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
@ -232,14 +183,7 @@ class UserSession implements AccountInterface {
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getLastAccessedTime() {
|
public function getLastAccessedTime() {
|
||||||
return $this->timestamp;
|
return $this->access;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getHostname() {
|
|
||||||
return $this->hostname;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -81,11 +81,6 @@ class Cookie implements AuthenticationProviderInterface {
|
||||||
|
|
||||||
// Check if the user data was found and the user is active.
|
// Check if the user data was found and the user is active.
|
||||||
if (!empty($values) && $values['status'] == 1) {
|
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.
|
// Add the user's roles.
|
||||||
$rids = $this->connection
|
$rids = $this->connection
|
||||||
->query('SELECT roles_target_id FROM {user__roles} WHERE entity_id = :uid', [':uid' => $values['uid']])
|
->query('SELECT roles_target_id FROM {user__roles} WHERE entity_id = :uid', [':uid' => $values['uid']])
|
||||||
|
|
|
@ -69,13 +69,6 @@ class User extends ContentEntityBase implements UserInterface {
|
||||||
*/
|
*/
|
||||||
protected static $anonymousUser;
|
protected static $anonymousUser;
|
||||||
|
|
||||||
/**
|
|
||||||
* The hostname for this user.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $hostname;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
@ -170,37 +163,6 @@ class User extends ContentEntityBase implements UserInterface {
|
||||||
return $roles;
|
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}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -21,42 +21,6 @@ use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
*/
|
*/
|
||||||
class AnonymousUserSessionTest extends UnitTestCase {
|
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.
|
* Tests the method getRoles exclude or include locked roles based in param.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue