Commit 0b807696 authored by catch's avatar catch

Issue #2241461 by Berdir, juampy: Locale + basic_auth results in current_user circular reference.

parent 1e15efd7
......@@ -45,11 +45,11 @@ class BasicAuth implements AuthenticationProviderInterface {
protected $flood;
/**
* The user storage.
* The entity manager.
*
* @var \Drupal\user\UserStorageInterface
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $userStorage;
protected $entityManager;
/**
* Constructs a HTTP basic authentication provider object.
......@@ -67,7 +67,7 @@ public function __construct(ConfigFactoryInterface $config_factory, UserAuthInte
$this->configFactory = $config_factory;
$this->userAuth = $user_auth;
$this->flood = $flood;
$this->userStorage = $entity_manager->getStorage('user');
$this->entityManager = $entity_manager;
}
/**
......@@ -94,7 +94,7 @@ public function authenticate(Request $request) {
// in to many different user accounts. We have a reasonably high limit
// since there may be only one apparent IP for all users at an institution.
if ($this->flood->isAllowed('basic_auth.failed_login_ip', $flood_config->get('ip_limit'), $flood_config->get('ip_window'))) {
$accounts = $this->userStorage->loadByProperties(array('name' => $username, 'status' => 1));
$accounts = $this->entityManager->getStorage('user')->loadByProperties(array('name' => $username, 'status' => 1));
$account = reset($accounts);
if ($account) {
if ($flood_config->get('uid_only')) {
......@@ -114,7 +114,7 @@ public function authenticate(Request $request) {
$uid = $this->userAuth->authenticate($username, $password);
if ($uid) {
$this->flood->clear('basic_auth.failed_login_user', $identifier);
return $this->userStorage->load($uid);
return $this->entityManager->getStorage('user')->load($uid);
}
else {
// Register a per-user failed login event.
......
......@@ -52,6 +52,10 @@ protected function setUpLanguage() {
public function testInstaller() {
$this->assertUrl('user/1');
$this->assertResponse(200);
// Ensure that we can enable basic_auth on a non-english site.
$this->drupalPostForm('admin/modules', array('modules[Web services][basic_auth][enable]' => TRUE), t('Save configuration'));
$this->assertResponse(200);
}
}
......@@ -17,11 +17,11 @@
class UserAuth implements UserAuthInterface {
/**
* The user storage.
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $storage;
protected $entityManager;
/**
* The password service.
......@@ -39,7 +39,7 @@ class UserAuth implements UserAuthInterface {
* The password service.
*/
public function __construct(EntityManagerInterface $entity_manager, PasswordInterface $password_checker) {
$this->storage = $entity_manager->getStorage('user');
$this->entityManager = $entity_manager;
$this->passwordChecker = $password_checker;
}
......@@ -50,7 +50,7 @@ public function authenticate($username, $password) {
$uid = FALSE;
if (!empty($username) && !empty($password)) {
$account_search = $this->storage->loadByProperties(array('name' => $username));
$account_search = $this->entityManager->getStorage('user')->loadByProperties(array('name' => $username));
if ($account = reset($account_search)) {
if ($this->passwordChecker->check($password, $account)) {
......
......@@ -80,8 +80,7 @@ public function setUp() {
$this->userStorage = $this->getMock('Drupal\Core\Entity\EntityStorageInterface');
$entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
// Getting the user storage should only happen once per test.
$entity_manager->expects($this->once())
$entity_manager->expects($this->any())
->method('getStorage')
->with('user')
->will($this->returnValue($this->userStorage));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment