Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions apps/files_external/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
use OCP\Group\Events\UserAddedEvent;
use OCP\Group\Events\UserRemovedEvent;
use OCP\User\Events\PasswordUpdatedEvent;
use OCP\User\Events\PostLoginEvent;
use OCP\User\Events\UserCreatedEvent;
use OCP\User\Events\UserDeletedEvent;
use OCP\User\Events\UserLoggedInEvent;
Expand Down Expand Up @@ -92,7 +91,7 @@ public function register(IRegistrationContext $context): void {
$context->registerEventListener(UserCreatedEvent::class, MountCacheService::class);
$context->registerEventListener(UserAddedEvent::class, MountCacheService::class);
$context->registerEventListener(UserRemovedEvent::class, MountCacheService::class);
$context->registerEventListener(PostLoginEvent::class, MountCacheService::class);
$context->registerEventListener(UserLoggedInEvent::class, MountCacheService::class);

$context->registerEventListener(UserLoggedInEvent::class, StorePasswordListener::class);
$context->registerEventListener(PasswordUpdatedEvent::class, StorePasswordListener::class);
Expand Down
6 changes: 3 additions & 3 deletions apps/files_external/lib/Service/MountCacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
use OCP\Group\Events\UserRemovedEvent;
use OCP\IGroup;
use OCP\IUser;
use OCP\User\Events\PostLoginEvent;
use OCP\User\Events\UserCreatedEvent;
use OCP\User\Events\UserLoggedInEvent;

/**
* Listens to config events and update the mounts for the applicable users
*
* @template-implements IEventListener<StorageCreatedEvent|StorageDeletedEvent|StorageUpdatedEvent|BeforeGroupDeletedEvent|UserCreatedEvent|UserAddedEvent|UserRemovedEvent|PostLoginEvent|Event>
* @template-implements IEventListener<StorageCreatedEvent|StorageDeletedEvent|StorageUpdatedEvent|BeforeGroupDeletedEvent|UserCreatedEvent|UserAddedEvent|UserRemovedEvent|UserLoggedInEvent|Event>
*/
class MountCacheService implements IEventListener {
private CappedMemoryCache $storageRootCache;
Expand Down Expand Up @@ -69,7 +69,7 @@ public function handle(Event $event): void {
if ($event instanceof UserCreatedEvent) {
$this->handleUserCreated($event->getUser());
}
if ($event instanceof PostLoginEvent) {
if ($event instanceof UserLoggedInEvent) {
$this->onLogin($event->getUser());
}
}
Expand Down
4 changes: 2 additions & 2 deletions apps/user_ldap/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
use OCP\IUserManager;
use OCP\Notification\IManager as INotificationManager;
use OCP\Share\IManager as IShareManager;
use OCP\User\Events\PostLoginEvent;
use OCP\User\Events\UserLoggedInEvent;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -75,7 +75,7 @@ function (ContainerInterface $c) {
// the instance is specific to a lazy bound Access instance, thus cannot be shared.
false
);
$context->registerEventListener(PostLoginEvent::class, LoginListener::class);
$context->registerEventListener(UserLoggedInEvent::class, LoginListener::class);
$context->registerEventListener(LoadAdditionalBackendEvent::class, LoadAdditionalBackendListener::class);
$context->registerSetupCheck(LdapInvalidUuids::class);
$context->registerSetupCheck(LdapConnection::class);
Expand Down
6 changes: 3 additions & 3 deletions apps/user_ldap/lib/LoginListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
use OCP\IUser;
use OCP\Notification\IManager as INotificationManager;
use OCP\Server;
use OCP\User\Events\PostLoginEvent;
use OCP\User\Events\UserLoggedInEvent;
use Psr\Log\LoggerInterface;

/**
* @template-implements IEventListener<PostLoginEvent>
* @template-implements IEventListener<UserLoggedInEvent>
*/
class LoginListener implements IEventListener {
public function __construct(
Expand All @@ -44,7 +44,7 @@ public function __construct(

#[\Override]
public function handle(Event $event): void {
if ($event instanceof PostLoginEvent) {
if ($event instanceof UserLoggedInEvent) {
$this->onPostLogin($event->getUser());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
use OC\Authentication\Token\Manager;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\User\Events\PostLoginEvent;
use OCP\User\Events\UserLoggedInEvent;

/**
* @template-implements IEventListener<PostLoginEvent>
* @template-implements IEventListener<UserLoggedInEvent>
*/
class UserLoggedInListener implements IEventListener {
public function __construct(
Expand All @@ -25,7 +25,7 @@ public function __construct(

#[\Override]
public function handle(Event $event): void {
if (!($event instanceof PostLoginEvent)) {
if (!($event instanceof UserLoggedInEvent)) {
return;
}

Expand Down
3 changes: 1 addition & 2 deletions lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@
use OCP\Teams\ITeamManager;
use OCP\Translation\ITranslationManager;
use OCP\User\Events\BeforeUserDeletedEvent;
use OCP\User\Events\PostLoginEvent;
use OCP\User\Events\UserChangedEvent;
use OCP\User\Events\UserDeletedEvent;
use OCP\User\Events\UserLoggedInEvent;
Expand Down Expand Up @@ -1121,7 +1120,7 @@ private function connectDispatcher(): void {
/** @var IEventDispatcher $eventDispatcher */
$eventDispatcher = $this->get(IEventDispatcher::class);
$eventDispatcher->addServiceListener(LoginFailed::class, LoginFailedListener::class);
$eventDispatcher->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class);
$eventDispatcher->addServiceListener(UserLoggedInEvent::class, UserLoggedInListener::class);
$eventDispatcher->addServiceListener(UserLoggedInEvent::class, Store::class);
$eventDispatcher->addServiceListener(UserLoggedInWithCookieEvent::class, Store::class);
$eventDispatcher->addServiceListener(UserChangedEvent::class, UserChangedListener::class);
Expand Down
7 changes: 7 additions & 0 deletions lib/private/User/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use OCP\User\Events\BeforeUserLoggedOutEvent;
use OCP\User\Events\PostLoginEvent;
use OCP\User\Events\UserFirstTimeLoggedInEvent;
use OCP\User\Events\UserLoggedInEvent;
use OCP\User\Events\UserLoggedInWithCookieEvent;
use OCP\User\Events\UserLoggedOutEvent;
use OCP\Util;
Expand Down Expand Up @@ -360,6 +361,12 @@ public function completeLogin(IUser $user, array $loginDetails, $regenerateSessi
$loginDetails['password'],
$isToken
));
$this->dispatcher->dispatchTyped(new UserLoggedInEvent(
$user,
$loginDetails['loginName'],
$loginDetails['password'],
$isToken
));
$this->manager->emit('\OC\User', 'postLogin', [
$user,
$loginDetails['loginName'],
Expand Down
30 changes: 13 additions & 17 deletions lib/private/legacy/OC_User.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
use OCP\Server;
use OCP\Session\Exceptions\SessionNotAvailableException;
use OCP\User\Events\BeforeUserLoggedInEvent;
use OCP\User\Events\UserLoggedInEvent;
use OCP\UserInterface;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -147,23 +146,31 @@ public static function loginWithApache(IApacheBackend $backend): bool {
/** @var Session $userSession */
$userSession = Server::get(IUserSession::class);
$dispatcher = Server::get(IEventDispatcher::class);
$request = Server::get(IRequest::class);
$user = $userSession->getUser();

if ($userSession->getUser() && !$userSession->getUser()->isEnabled()) {
if (!$user) {
// Should not happen except from bad code or configuration
throw new \OCP\User\Exceptions\UserNotFoundException('User ' . $uid . ' not found');
}
if (!$user->isEnabled()) {
$message = Server::get(IFactory::class)->get('lib')->t('Account disabled');
throw new DisabledUserException($message);
}
$userSession->setLoginName($uid);
$request = Server::get(IRequest::class);

$password = null;
if ($backend instanceof IProvideUserSecretBackend) {
$password = $backend->getCurrentUserSecret();
}

$dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password, $backend));

$user = $userSession->getUser();
$userSession->completeLogin($user, ['loginName' => $uid, 'password' => $password ?? '']);
$userSession->createSessionToken($request, $uid, $uid, $password);
$userSession->completeLogin(
$user,
['loginName' => $uid, 'password' => $password ?? ''],
regenerateSessionId:false,
);
$userSession->createRememberMeToken($user);

if (empty($password)) {
Expand All @@ -180,17 +187,6 @@ public static function loginWithApache(IApacheBackend $backend): bool {
// simply skip updating the token when is it missing
}
}

// first call the UserLoggedIn event, the login-process needs to be
// completed before we can safely create the user's folder.
// For example encryption needs to initialize the users keys first
// before we can create the user folder with the skeleton files
$dispatcher->dispatchTyped(new UserLoggedInEvent(
$user,
$uid,
null,
false)
);
}
return true;
}
Expand Down
1 change: 1 addition & 0 deletions lib/public/User/Events/PostLoginEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

/**
* @since 18.0.0
* @deprecated 36.0.0 Use UserLoggedInEvent instead
*/
class PostLoginEvent extends Event {
/** @var IUser */
Expand Down
23 changes: 6 additions & 17 deletions lib/public/User/Events/UserLoggedInEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,16 @@
* @since 18.0.0
*/
class UserLoggedInEvent extends Event {
/** @var IUser */
private $user;

/** @var string|null */
private $password;

/** @var bool */
private $isTokenLogin;

/** @var string */
private $loginName;

/**
* @since 18.0.0
*/
public function __construct(IUser $user, string $loginName, ?string $password, bool $isTokenLogin) {
public function __construct(
private IUser $user,
private string $loginName,
private ?string $password,
private bool $isTokenLogin,
) {
parent::__construct();
$this->user = $user;
$this->password = $password;
$this->isTokenLogin = $isTokenLogin;
$this->loginName = $loginName;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions tests/lib/User/SessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use OCP\Security\ISecureRandom;
use OCP\User\Events\BeforeUserLoggedInEvent;
use OCP\User\Events\PostLoginEvent;
use OCP\User\Events\UserLoggedInEvent;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\ExpectationFailedException;
Expand Down Expand Up @@ -194,10 +195,10 @@ public function testLoginValidPasswordEnabled(): void {
$userSession->expects($this->once())
->method('prepareUserLogin');

$this->dispatcher->expects($this->once())
$this->dispatcher->expects($this->exactly(2))
->method('dispatchTyped')
->with(
$this->callback(function (PostLoginEvent $e): bool {
$this->callback(function (PostLoginEvent|UserLoggedInEvent $e): bool {
return $e->getUser()->getUID() === 'foo'
&& $e->getPassword() === 'bar'
&& $e->isTokenLogin() === false;
Expand Down
Loading