Skip to content

Commit f59e79c

Browse files
authored
Merge pull request #910 from nextcloud/handle-loginexception-when-authenticating-with-apache
Handle LoginException when authenticating with Apache
2 parents 0c174af + 2e9f5bc commit f59e79c

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

appinfo/app.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-License-Identifier: AGPL-3.0-or-later
55
*/
66

7+
use OC\User\LoginException;
78
use OCA\User_SAML\GroupBackend;
89
use OCA\User_SAML\SAMLSettings;
910
use OCA\User_SAML\UserBackend;
@@ -63,7 +64,21 @@
6364
return;
6465
}
6566

66-
OC_User::handleApacheAuth();
67+
try {
68+
OC_User::handleApacheAuth();
69+
} catch (LoginException $e) {
70+
if ($request->getPathInfo() === '/apps/user_saml/saml/error') {
71+
return;
72+
}
73+
$targetUrl = $urlGenerator->linkToRouteAbsolute(
74+
'user_saml.SAML.genericError',
75+
[
76+
'message' => $e->getMessage()
77+
]
78+
);
79+
header('Location: ' . $targetUrl);
80+
exit();
81+
}
6782
}
6883

6984
if ($returnScript === true) {

tests/integration/features/EnvironmentVariable.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,13 @@ Feature: EnvironmentVariable
2727
And The environment variable "REMOTE_USER" is set to "certainly-not-provisioned-user"
2828
When I send a GET request to "http://localhost:8080/index.php/login"
2929
Then I should be redirected to "http://localhost:8080/index.php/apps/user_saml/saml/notProvisioned"
30+
31+
Scenario: Authenticating using environment variable with SSO as a disabled user on backend
32+
Given A local user with uid "provisioned-disabled-user" exists
33+
And A local user with uid "provisioned-disabled-user" is disabled
34+
And The setting "type" is set to "environment-variable"
35+
And The setting "general-require_provisioned_account" is set to "1"
36+
And The setting "general-uid_mapping" is set to "REMOTE_USER"
37+
And The environment variable "REMOTE_USER" is set to "provisioned-disabled-user"
38+
When I send a GET request to "http://localhost:8080/index.php/login"
39+
Then I should be redirected to "http://localhost:8080/index.php/apps/user_saml/saml/error"

tests/integration/features/bootstrap/FeatureContext.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,21 @@ public function aLocalUserWithUidExists($uid) {
493493
);
494494
}
495495

496+
/**
497+
* @Given A local user with uid :uid is disabled
498+
* @param string $uid
499+
*/
500+
public function aLocalUserWithUidIsDisabled($uid) {
501+
shell_exec(
502+
sprintf(
503+
'OC_PASS=password %s %s user:disable %s',
504+
PHP_BINARY,
505+
__DIR__ . '/../../../../../../occ',
506+
$uid
507+
)
508+
);
509+
}
510+
496511
/**
497512
* @Then I hack :uid into existence
498513
*/

0 commit comments

Comments
 (0)