Skip to content

Commit

Permalink
Merge pull request #910 from nextcloud/handle-loginexception-when-aut…
Browse files Browse the repository at this point in the history
…henticating-with-apache

Handle LoginException when authenticating with Apache
  • Loading branch information
blizzz authored Dec 3, 2024
2 parents 0c174af + 2e9f5bc commit f59e79c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
17 changes: 16 additions & 1 deletion appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

use OC\User\LoginException;
use OCA\User_SAML\GroupBackend;
use OCA\User_SAML\SAMLSettings;
use OCA\User_SAML\UserBackend;
Expand Down Expand Up @@ -63,7 +64,21 @@
return;
}

OC_User::handleApacheAuth();
try {
OC_User::handleApacheAuth();
} catch (LoginException $e) {
if ($request->getPathInfo() === '/apps/user_saml/saml/error') {
return;
}
$targetUrl = $urlGenerator->linkToRouteAbsolute(
'user_saml.SAML.genericError',
[
'message' => $e->getMessage()
]
);
header('Location: ' . $targetUrl);
exit();
}
}

if ($returnScript === true) {
Expand Down
10 changes: 10 additions & 0 deletions tests/integration/features/EnvironmentVariable.feature
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@ Feature: EnvironmentVariable
And The environment variable "REMOTE_USER" is set to "certainly-not-provisioned-user"
When I send a GET request to "http://localhost:8080/index.php/login"
Then I should be redirected to "http://localhost:8080/index.php/apps/user_saml/saml/notProvisioned"

Scenario: Authenticating using environment variable with SSO as a disabled user on backend
Given A local user with uid "provisioned-disabled-user" exists
And A local user with uid "provisioned-disabled-user" is disabled
And The setting "type" is set to "environment-variable"
And The setting "general-require_provisioned_account" is set to "1"
And The setting "general-uid_mapping" is set to "REMOTE_USER"
And The environment variable "REMOTE_USER" is set to "provisioned-disabled-user"
When I send a GET request to "http://localhost:8080/index.php/login"
Then I should be redirected to "http://localhost:8080/index.php/apps/user_saml/saml/error"
15 changes: 15 additions & 0 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,21 @@ public function aLocalUserWithUidExists($uid) {
);
}

/**
* @Given A local user with uid :uid is disabled
* @param string $uid
*/
public function aLocalUserWithUidIsDisabled($uid) {
shell_exec(
sprintf(
'OC_PASS=password %s %s user:disable %s',
PHP_BINARY,
__DIR__ . '/../../../../../../occ',
$uid
)
);
}

/**
* @Then I hack :uid into existence
*/
Expand Down

0 comments on commit f59e79c

Please sign in to comment.