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
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ private function getCredentials(IUser $user): array {
try {
$sessionCredentials = $this->credentialsStore->getLoginCredentials();

if ($sessionCredentials->getUID() !== $user->getUID()) {
// Can't take the credentials from the session as they are not the same user
throw new CredentialsUnavailableException();
}

$credentials = [
'user' => $sessionCredentials->getLoginName(),
'password' => $sessionCredentials->getPassword()
Expand Down
8 changes: 6 additions & 2 deletions apps/files_external/lib/Listener/StorePasswordListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@ public function handle(Event $event): void {
}

$stored = $this->credentialsManager->retrieve($event->getUser()->getUID(), LoginCredentials::CREDENTIALS_IDENTIFIER);
$update = isset($stored['password']) && $stored['password'] !== $event->getPassword();
if (!$update && $event instanceof UserLoggedInEvent) {
$update = isset($stored['user']) && $stored['user'] !== $event->getLoginName();
}

if ($stored && $stored['password'] !== $event->getPassword()) {
if ($stored && $update) {
$credentials = [
'user' => $stored['user'],
'user' => $event->getLoginName(),
'password' => $event->getPassword()
];

Expand Down
2 changes: 1 addition & 1 deletion lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ public function __construct($webRoot, \OC\Config $config) {

/** @var IEventDispatcher $dispatcher */
$dispatcher = $this->query(IEventDispatcher::class);
$dispatcher->dispatchTyped(new UserLoggedInEvent($user, $password, $isTokenLogin));
$dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin));
});
$userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) {
/** @var IEventDispatcher $dispatcher */
Expand Down
13 changes: 12 additions & 1 deletion lib/public/User/Events/UserLoggedInEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,18 @@ class UserLoggedInEvent extends Event {
/** @var bool */
private $isTokenLogin;

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

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

/**
Expand All @@ -60,6 +64,13 @@ public function getUser(): IUser {
return $this->user;
}

/**
* @since 21.0.0
*/
public function getLoginName(): string {
return $this->loginName;
}

/**
* @since 18.0.0
*/
Expand Down