AccountProxy.php in Restrict Login or Role Access by IP Address 8.4
File
src/Session/AccountProxy.php
View source
<?php
namespace Drupal\restrict_by_ip\Session;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\restrict_by_ip\RoleFirewallInterface;
class AccountProxy implements AccountProxyInterface {
protected $original;
protected $roleFirewall;
public function __construct(AccountProxyInterface $original, RoleFirewallInterface $role_firewall) {
$this->original = $original;
$this->roleFirewall = $role_firewall;
}
public function getRoles($exclude_locked_roles = FALSE) {
$roles = $this->original
->getRoles($exclude_locked_roles);
$remove_roles = $this->roleFirewall
->rolesToRemove();
return array_diff($roles, $remove_roles);
}
public function hasPermission($permission) {
if ((int) $this
->id() === 1) {
return TRUE;
}
return $this
->getRoleStorage()
->isPermissionInRoles($permission, $this
->getRoles());
}
public function setAccount(AccountInterface $account) {
$this->original
->setAccount($account);
}
public function getAccount() {
return $this->original
->getAccount();
}
public function id() {
return $this->original
->id();
}
public function isAuthenticated() {
return $this->original
->isAuthenticated();
}
public function isAnonymous() {
return $this->original
->isAnonymous();
}
public function getPreferredLangcode($fallback_to_default = TRUE) {
return $this->original
->getPreferredLangcode($fallback_to_default);
}
public function getPreferredAdminLangcode($fallback_to_default = TRUE) {
return $this->original
->getPreferredAdminLangcode($fallback_to_default);
}
public function getUsername() {
return $this->original
->getUsername();
}
public function getAccountName() {
return $this->original
->getAccountName();
}
public function getDisplayName() {
return $this->original
->getDisplayName();
}
public function getEmail() {
return $this->original
->getEmail();
}
public function getTimeZone() {
return $this->original
->getTimeZone();
}
public function getLastAccessedTime() {
return $this->original
->getLastAccessedTime();
}
public function setInitialAccountId($account_id) {
$this->original
->setInitialAccountId($account_id);
}
protected function getRoleStorage() {
return \Drupal::entityManager()
->getStorage('user_role');
}
}
Classes
Name |
Description |
AccountProxy |
When the current user is loaded, remove any roles that are restricted based
on IP whitelists. Proxy all other method calls to the original current_user
service. |