f7cloud_client/apps/whiteboard/lib/Service/Authentication/AuthenticateSessionUserService.php
root 8b6a0139db f7cloud_client
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-17 22:59:26 +00:00

37 lines
848 B
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 F7cloud GmbH and F7cloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Whiteboard\Service\Authentication;
use OCA\Whiteboard\Exception\UnauthorizedException;
use OCA\Whiteboard\Model\AuthenticatedUser;
use OCA\Whiteboard\Model\User;
use OCP\IUserSession;
final class AuthenticateSessionUserService implements AuthenticateUserService {
public function __construct(
private IUserSession $userSession,
) {
}
#[\Override]
public function authenticate(): User {
if (!$this->userSession->isLoggedIn()) {
throw new UnauthorizedException('User not logged in');
}
$user = $this->userSession->getUser();
if ($user === null) {
throw new UnauthorizedException('User session invalid');
}
return new AuthenticatedUser($user);
}
}