Skip to content

Commit

Permalink
Refs #65, re-use tryNormalAuth (after renaming it) so token_auth will…
Browse files Browse the repository at this point in the history
… be set.
  • Loading branch information
diosmosis committed Nov 26, 2014
1 parent d6ca7e7 commit 91b755e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
9 changes: 7 additions & 2 deletions Auth/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,14 @@ protected function getUserForLogin()
return $this->userForLogin;
}

protected function tryNormalAuth($onlySuperUsers = true)
protected function tryFallbackAuth($onlySuperUsers = true, Auth $auth = null)
{
$auth = new \Piwik\Plugins\Login\Auth();
if (empty($auth)) {
$auth = new \Piwik\Plugins\Login\Auth();
} else {
Log::debug("Auth\\Base::%s: trying fallback auth with auth implementation '%s'", __FUNCTION__, get_class($auth));
}

$auth->setLogin($this->login);
if (!empty($this->password)) {
Log::debug("Auth\\Base::%s: trying normal auth with user password", __FUNCTION__);
Expand Down
2 changes: 1 addition & 1 deletion Auth/LdapAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private function authenticateByPassword()
} else {
// if LDAP auth failed, try normal auth. if we have a login for a superuser, let it through.
// this way, LoginLdap can be managed even if no users exist in LDAP.
$result = $this->tryNormalAuth($onlySuperUsers = true);
$result = $this->tryFallbackAuth($onlySuperUsers = true);

if (!$result->wasAuthenticationSuccessful()
&& !empty($ldapException)
Expand Down
2 changes: 1 addition & 1 deletion Auth/SynchronizedAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class SynchronizedAuth extends Base
public function authenticate()
{
try {
$result = $this->tryNormalAuth($onlySuperUsers = false);
$result = $this->tryFallbackAuth($onlySuperUsers = false);
if ($result->wasAuthenticationSuccessful()) {
return $result;
}
Expand Down
11 changes: 1 addition & 10 deletions Auth/WebServerAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function authenticate()
if (empty($webServerAuthUser)) {
Log::debug("using web server authentication, but REMOTE_USER server variable not found.");

return $this->useFallbackAuth();
return $this->tryFallbackAuth($onlySuperUsers = false, $this->fallbackAuth);
} else {
$this->login = preg_replace('/@.*/', '', $webServerAuthUser);
$this->password = '';
Expand Down Expand Up @@ -174,13 +174,4 @@ public static function makeConfigured()

return $result;
}

private function useFallbackAuth()
{
Log::debug("WebServerAuth::useFallbackAuth(): attempting fallback auth with '%s'", get_class($this->fallbackAuth));

$this->fallbackAuth->setLogin($this->login);
$this->fallbackAuth->setPassword($this->password);
return $this->fallbackAuth->authenticate();
}
}

0 comments on commit 91b755e

Please sign in to comment.