diff options
author | Christoph Wurst <christoph@owncloud.com> | 2016-06-17 12:08:48 +0200 |
---|---|---|
committer | Christoph Wurst <christoph@owncloud.com> | 2016-06-17 15:42:28 +0200 |
commit | c4149c59c2cfe83b5e4cd2b20b8ad4caf2341ca9 (patch) | |
tree | 961a9ad987518d31fce34c93b65d2d2bf1991433 /lib | |
parent | 491e2654ebed82044f84d3adcc5f845dc471ae06 (diff) | |
download | nextcloud-server-c4149c59c2cfe83b5e4cd2b20b8ad4caf2341ca9.tar.gz nextcloud-server-c4149c59c2cfe83b5e4cd2b20b8ad4caf2341ca9.zip |
use token last_activity instead of session value
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Authentication/Token/DefaultTokenProvider.php | 11 | ||||
-rw-r--r-- | lib/private/Authentication/Token/IProvider.php | 2 | ||||
-rw-r--r-- | lib/private/User/Session.php | 18 |
3 files changed, 10 insertions, 21 deletions
diff --git a/lib/private/Authentication/Token/DefaultTokenProvider.php b/lib/private/Authentication/Token/DefaultTokenProvider.php index 84effc5f875..03b8bb5da28 100644 --- a/lib/private/Authentication/Token/DefaultTokenProvider.php +++ b/lib/private/Authentication/Token/DefaultTokenProvider.php @@ -97,14 +97,17 @@ class DefaultTokenProvider implements IProvider { * @throws InvalidTokenException * @param IToken $token */ - public function updateToken(IToken $token) { + public function updateTokenActivity(IToken $token) { if (!($token instanceof DefaultToken)) { throw new InvalidTokenException(); } /** @var DefaultToken $token */ - $token->setLastActivity($this->time->getTime()); - - $this->mapper->update($token); + $now = $this->time->getTime(); + if ($token->getLastActivity() < ($now - 60)) { + // Update token only once per minute + $token->setLastActivity($now); + $this->mapper->update($token); + } } /** diff --git a/lib/private/Authentication/Token/IProvider.php b/lib/private/Authentication/Token/IProvider.php index fece7dcb567..e79ba8b30e5 100644 --- a/lib/private/Authentication/Token/IProvider.php +++ b/lib/private/Authentication/Token/IProvider.php @@ -76,7 +76,7 @@ interface IProvider { * * @param IToken $token */ - public function updateToken(IToken $token); + public function updateTokenActivity(IToken $token); /** * Get all token of a user diff --git a/lib/private/User/Session.php b/lib/private/User/Session.php index 0cebb3e0613..89148dcf8ec 100644 --- a/lib/private/User/Session.php +++ b/lib/private/User/Session.php @@ -237,8 +237,7 @@ class Session implements IUserSession, Emitter { $this->session->set('last_login_check', $now); } - // Session is valid, so the token can be refreshed - $this->updateToken($token); + $this->tokenProvider->updateTokenActivity($token); } /** @@ -541,7 +540,7 @@ class Session implements IUserSession, Emitter { $result = $this->loginWithToken($token->getUID()); if ($result) { // Login success - $this->updateToken($token); + $this->tokenProvider->updateTokenActivity($token); return true; } } @@ -552,19 +551,6 @@ class Session implements IUserSession, Emitter { } /** - * @param IToken $token - */ - private function updateToken(IToken $token) { - // To save unnecessary DB queries, this is only done once a minute - $lastTokenUpdate = $this->session->get('last_token_update') ? : 0; - $now = $this->timeFacory->getTime(); - if ($lastTokenUpdate < ($now - 60)) { - $this->tokenProvider->updateToken($token); - $this->session->set('last_token_update', $now); - } - } - - /** * Tries to login the user with auth token header * * @todo check remember me cookie |