From 5122629bb0ff59a1688029d65e919ce31db8eced Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Tue, 8 Oct 2019 11:01:53 +0200 Subject: Make renewSessionToken return the new token Avoids directly getting the token again. We just inserted it so it and have all the info. So that query is just a waste. Signed-off-by: Roeland Jago Douma --- lib/private/Authentication/Token/DefaultTokenProvider.php | 5 ++++- lib/private/Authentication/Token/IProvider.php | 3 ++- lib/private/Authentication/Token/Manager.php | 7 ++++--- lib/private/Authentication/Token/PublicKeyTokenProvider.php | 6 ++++-- 4 files changed, 14 insertions(+), 7 deletions(-) (limited to 'lib/private/Authentication') diff --git a/lib/private/Authentication/Token/DefaultTokenProvider.php b/lib/private/Authentication/Token/DefaultTokenProvider.php index 98609a3f14b..6bd7c2c6dc8 100644 --- a/lib/private/Authentication/Token/DefaultTokenProvider.php +++ b/lib/private/Authentication/Token/DefaultTokenProvider.php @@ -196,8 +196,9 @@ class DefaultTokenProvider implements IProvider { * @param string $oldSessionId * @param string $sessionId * @throws InvalidTokenException + * @return IToken */ - public function renewSessionToken(string $oldSessionId, string $sessionId) { + public function renewSessionToken(string $oldSessionId, string $sessionId): IToken { $token = $this->getToken($oldSessionId); $newToken = new DefaultToken(); @@ -214,6 +215,8 @@ class DefaultTokenProvider implements IProvider { $newToken->setLastActivity($this->time->getTime()); $this->mapper->insert($newToken); $this->mapper->delete($token); + + return $newToken; } /** diff --git a/lib/private/Authentication/Token/IProvider.php b/lib/private/Authentication/Token/IProvider.php index 860b93e16c2..ba8df30eb8d 100644 --- a/lib/private/Authentication/Token/IProvider.php +++ b/lib/private/Authentication/Token/IProvider.php @@ -84,8 +84,9 @@ interface IProvider { * @param string $sessionId * @throws InvalidTokenException * @throws \RuntimeException when OpenSSL reports a problem + * @return IToken The new token */ - public function renewSessionToken(string $oldSessionId, string $sessionId); + public function renewSessionToken(string $oldSessionId, string $sessionId): IToken; /** * Invalidate (delete) the given session token diff --git a/lib/private/Authentication/Token/Manager.php b/lib/private/Authentication/Token/Manager.php index 76c0dfb8695..ea94efce54d 100644 --- a/lib/private/Authentication/Token/Manager.php +++ b/lib/private/Authentication/Token/Manager.php @@ -158,14 +158,15 @@ class Manager implements IProvider { * @param string $oldSessionId * @param string $sessionId * @throws InvalidTokenException + * @return IToken */ - public function renewSessionToken(string $oldSessionId, string $sessionId) { + public function renewSessionToken(string $oldSessionId, string $sessionId): IToken { try { - $this->publicKeyTokenProvider->renewSessionToken($oldSessionId, $sessionId); + return $this->publicKeyTokenProvider->renewSessionToken($oldSessionId, $sessionId); } catch (ExpiredTokenException $e) { throw $e; } catch (InvalidTokenException $e) { - $this->defaultTokenProvider->renewSessionToken($oldSessionId, $sessionId); + return $this->defaultTokenProvider->renewSessionToken($oldSessionId, $sessionId); } } diff --git a/lib/private/Authentication/Token/PublicKeyTokenProvider.php b/lib/private/Authentication/Token/PublicKeyTokenProvider.php index 4ef9afb3442..624e2c0cadc 100644 --- a/lib/private/Authentication/Token/PublicKeyTokenProvider.php +++ b/lib/private/Authentication/Token/PublicKeyTokenProvider.php @@ -129,7 +129,7 @@ class PublicKeyTokenProvider implements IProvider { return $token; } - public function renewSessionToken(string $oldSessionId, string $sessionId) { + public function renewSessionToken(string $oldSessionId, string $sessionId): IToken { $this->cache->clear(); $token = $this->getToken($oldSessionId); @@ -144,7 +144,7 @@ class PublicKeyTokenProvider implements IProvider { $password = $this->decryptPassword($token->getPassword(), $privateKey); } - $this->generateToken( + $newToken = $this->generateToken( $sessionId, $token->getUID(), $token->getLoginName(), @@ -155,6 +155,8 @@ class PublicKeyTokenProvider implements IProvider { ); $this->mapper->delete($token); + + return $newToken; } public function invalidateToken(string $token) { -- cgit v1.2.3