Skip to content

Commit 2efb811

Browse files
authored
Merge pull request #34947 from nextcloud/backport/34804/stable24
[stable24] Skip general login with email for non-valid addresses and LDAP
2 parents 68a643d + 91a4444 commit 2efb811

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

lib/private/Authentication/Login/EmailLoginCommand.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,21 @@ public function __construct(IUserManager $userManager) {
3838

3939
public function process(LoginData $loginData): LoginResult {
4040
if ($loginData->getUser() === false) {
41+
if (!filter_var($loginData->getUsername(), FILTER_VALIDATE_EMAIL)) {
42+
return $this->processNextOrFinishSuccessfully($loginData);
43+
}
44+
4145
$users = $this->userManager->getByEmail($loginData->getUsername());
4246
// we only allow login by email if unique
4347
if (count($users) === 1) {
48+
49+
// FIXME: This is a workaround to still stick to configured LDAP login filters
50+
// this can be removed once the email login is properly implemented in the local user backend
51+
// as described in https://github.com/nextcloud/server/issues/5221
52+
if ($users[0]->getBackendClassName() === 'LDAP') {
53+
return $this->processNextOrFinishSuccessfully($loginData);
54+
}
55+
4456
$username = $users[0]->getUID();
4557
if ($username !== $loginData->getUsername()) {
4658
$user = $this->userManager->checkPassword(

tests/lib/Authentication/Login/EmailLoginCommandTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function testProcessAlreadyLoggedIn() {
5555

5656
public function testProcessNotAnEmailLogin() {
5757
$data = $this->getFailedLoginData();
58-
$this->userManager->expects($this->once())
58+
$this->userManager->expects($this->never())
5959
->method('getByEmail')
6060
->with($this->username)
6161
->willReturn([]);
@@ -67,9 +67,10 @@ public function testProcessNotAnEmailLogin() {
6767

6868
public function testProcessDuplicateEmailLogin() {
6969
$data = $this->getFailedLoginData();
70+
$data->setUsername('user@example.com');
7071
$this->userManager->expects($this->once())
7172
->method('getByEmail')
72-
->with($this->username)
73+
->with('user@example.com')
7374
->willReturn([
7475
$this->createMock(IUser::class),
7576
$this->createMock(IUser::class),

0 commit comments

Comments
 (0)