Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions module/VuFind/src/VuFind/Auth/LoginTokenManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
use Laminas\View\Renderer\RendererInterface;
use VuFind\Cookie\CookieManager;
use VuFind\Db\Entity\UserEntityInterface;
use VuFind\Db\Service\LoginTokenServiceInterface;
use VuFind\Db\Service\UserServiceInterface;
use VuFind\Db\Table\LoginToken as LoginTokenTable;
use VuFind\Exception\Auth as AuthException;
use VuFind\Exception\LoginToken as LoginTokenException;
use VuFind\I18n\Translator\TranslatorAwareInterface;
Expand Down Expand Up @@ -102,19 +102,19 @@ class LoginTokenManager implements LoggerAwareInterface, TranslatorAwareInterfac
/**
* LoginToken constructor.
*
* @param Config $config Configuration
* @param UserServiceInterface $userService User database service
* @param LoginTokenTable $loginTokenTable Login Token table gateway
* @param CookieManager $cookieManager Cookie manager
* @param SessionManager $sessionManager Session manager
* @param Mailer $mailer Mailer
* @param RendererInterface $viewRenderer View Renderer
* @param callable $browscapCB Callback for creating Browscap
* @param Config $config Configuration
* @param UserServiceInterface $userService User database service
* @param LoginTokenServiceInterface $loginTokenService Login Token database service
* @param CookieManager $cookieManager Cookie manager
* @param SessionManager $sessionManager Session manager
* @param Mailer $mailer Mailer
* @param RendererInterface $viewRenderer View Renderer
* @param callable $browscapCB Callback for creating Browscap
*/
public function __construct(
protected Config $config,
protected UserServiceInterface $userService,
protected LoginTokenTable $loginTokenTable,
protected LoginTokenServiceInterface $loginTokenService,
protected CookieManager $cookieManager,
protected SessionManager $sessionManager,
protected Mailer $mailer,
Expand All @@ -138,7 +138,7 @@ public function tokenLogin(string $sessionId): ?UserEntityInterface
if ($cookie) {
try {
if (
($token = $this->loginTokenTable->matchToken($cookie))
($token = $this->loginTokenService->matchToken($cookie))
&& ($user = $this->userService->getUserById($token->user_id))
) {
// Queue token update to be done after everything else is
Expand Down Expand Up @@ -241,10 +241,10 @@ public function deleteTokenSeries(string $series, int $userId)
$this->cookieManager->clear($this->getCookieName());
}
$handler = $this->sessionManager->getSaveHandler();
foreach ($this->loginTokenTable->getBySeries($series) as $token) {
foreach ($this->loginTokenService->getBySeries($series) as $token) {
$handler->destroy($token->last_session_id);
}
$this->loginTokenTable->deleteBySeries($series);
$this->loginTokenService->deleteBySeries($series);
}

/**
Expand All @@ -257,12 +257,12 @@ public function deleteTokenSeries(string $series, int $userId)
*/
public function deleteUserLoginTokens($userId)
{
$userTokens = $this->loginTokenTable->getByUserId($userId, false);
$userTokens = $this->loginTokenService->getByUser($userId, false);
$handler = $this->sessionManager->getSaveHandler();
foreach ($userTokens as $t) {
$handler->destroy($t->last_session_id);
}
$this->loginTokenTable->deleteByUserId($userId);
$this->loginTokenService->deleteByUser($userId);
}

/**
Expand Down Expand Up @@ -294,7 +294,7 @@ public function deleteActiveToken()
{
$cookie = $this->getLoginTokenCookie();
if (!empty($cookie) && $cookie['series']) {
$this->loginTokenTable->deleteBySeries($cookie['series']);
$this->loginTokenService->deleteBySeries($cookie['series']);
}
$this->cookieManager->clear($this->getCookieName());
}
Expand Down Expand Up @@ -332,14 +332,14 @@ protected function createOrRotateToken(
try {
if ($series) {
$lenient = ($this->config->Authentication->lenient_token_rotation ?? true);
$this->loginTokenTable->deleteBySeries($series, $lenient ? $currentTokenId : null);
$this->loginTokenService->deleteBySeries($series, $lenient ? $currentTokenId : null);
$this->debug("Updating login token $token series $series for user {$userId}");
} else {
$series = bin2hex(random_bytes(32));
$this->debug("Creating login token $token series $series for user {$userId}");
}
$this->loginTokenTable->saveToken(
$userId,
$this->loginTokenService->saveToken(
$user,
$token,
$series,
$browser->browser,
Expand Down
11 changes: 5 additions & 6 deletions module/VuFind/src/VuFind/Auth/LoginTokenManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use Laminas\ServiceManager\Exception\ServiceNotFoundException;
use Psr\Container\ContainerExceptionInterface as ContainerException;
use Psr\Container\ContainerInterface;
use VuFind\Db\Service\LoginTokenServiceInterface;
use VuFind\Db\Service\UserServiceInterface;

/**
Expand Down Expand Up @@ -80,13 +81,11 @@ public function __invoke(
}
$this->container = $container;

$dbServiceManager = $container->get(\VuFind\Db\Service\PluginManager::class);
return new $requestedName(
$container->get(\VuFind\Config\PluginManager::class)
->get('config'),
$container->get(\VuFind\Db\Service\PluginManager::class)
->get(UserServiceInterface::class),
$container->get(\VuFind\Db\Table\PluginManager::class)
->get('logintoken'),
$container->get(\VuFind\Config\PluginManager::class)->get('config'),
$dbServiceManager->get(UserServiceInterface::class),
$dbServiceManager->get(LoginTokenServiceInterface::class),
$container->get(\VuFind\Cookie\CookieManager::class),
$container->get(\Laminas\Session\SessionManager::class),
$container->get(\VuFind\Mailer\Mailer::class),
Expand Down
179 changes: 179 additions & 0 deletions module/VuFind/src/VuFind/Db/Entity/LoginTokenEntityInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<?php

/**
* Entity model interface for login_token table
*
* PHP version 8
*
* Copyright (C) Villanova University 2024.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category VuFind
* @package Database
* @author Demian Katz <[email protected]>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development:plugins:database_gateways Wiki
*/

namespace VuFind\Db\Entity;

use DateTime;

/**
* Entity model interface for login_token table
*
* @category VuFind
* @package Database
* @author Demian Katz <[email protected]>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development:plugins:database_gateways Wiki
*/
interface LoginTokenEntityInterface extends EntityInterface
{
/**
* Getter for ID.
*
* @return int
*/
public function getId(): int;

/**
* Setter for User.
*
* @param UserEntityInterface $user User to set
*
* @return LoginTokenEntityInterface
*/
public function setUser(UserEntityInterface $user): LoginTokenEntityInterface;

/**
* User getter (only null if entity has not been populated yet).
*
* @return ?UserEntityInterface
*/
public function getUser(): ?UserEntityInterface;

/**
* Set token string.
*
* @param string $token Token
*
* @return LoginTokenEntityInterface
*/
public function setToken(string $token): LoginTokenEntityInterface;

/**
* Get token string.
*
* @return string
*/
public function getToken(): string;

/**
* Set series string.
*
* @param string $series Series
*
* @return LoginTokenEntityInterface
*/
public function setSeries(string $series): LoginTokenEntityInterface;

/**
* Get series string.
*
* @return string
*/
public function getSeries(): string;

/**
* Set last login date/time.
*
* @param DateTime $dateTime Last login date/time
*
* @return LoginTokenEntityInterface
*/
public function setLastLogin(DateTime $dateTime): LoginTokenEntityInterface;

/**
* Get last login date/time.
*
* @return DateTime
*/
public function getLastLogin(): DateTime;

/**
* Set browser details (or null for none).
*
* @param ?string $browser Browser details (or null for none)
*
* @return LoginTokenEntityInterface
*/
public function setBrowser(?string $browser): LoginTokenEntityInterface;

/**
* Get browser details (or null for none).
*
* @return ?string
*/
public function getBrowser(): ?string;

/**
* Set platform details (or null for none).
*
* @param ?string $platform Platform details (or null for none)
*
* @return LoginTokenEntityInterface
*/
public function setPlatform(?string $platform): LoginTokenEntityInterface;

/**
* Get platform details (or null for none).
*
* @return ?string
*/
public function getPlatform(): ?string;

/**
* Set expiration timestamp.
*
* @param int $expires Expiration timestamp
*
* @return LoginTokenEntityInterface
*/
public function setExpires(int $expires): LoginTokenEntityInterface;

/**
* Get expiration timestamp.
*
* @return int
*/
public function getExpires(): int;

/**
* Set last session ID (or null for none).
*
* @param ?string $sid Last session ID (or null for none)
*
* @return LoginTokenEntityInterface
*/
public function setLastSessionId(?string $sid): LoginTokenEntityInterface;

/**
* Get last session ID (or null for none).
*
* @return ?string
*/
public function getLastSessionId(): ?string;
}
Loading