Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(idps): Allow to filter idps based on trusted domains #815

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
}

$multipleUserBackEnds = $samlSettings->allowMultipleUserBackEnds();
$configuredIdps = $samlSettings->getListOfIdps();
$configuredIdps = $samlSettings->getListOfIdps($request);
$showLoginOptions = ($multipleUserBackEnds || count($configuredIdps) > 1) && $type === 'saml';

if ($redirectSituation === true && $showLoginOptions) {
Expand Down Expand Up @@ -152,7 +152,7 @@
[
'requesttoken' => $csrfToken->getEncryptedValue(),
'originalUrl' => $originalUrl,
'idp' => array_keys($configuredIdps)[0] ?? '',
'idp' => array_key_first($configuredIdps) ?? '',
]
);
header('Location: '.$targetUrl);
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/SAMLController.php
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ public function selectUserBackEnd(string $redirectUrl): Http\TemplateResponse {
*/
private function getIdps(string $redirectUrl): array {
$result = [];
$idps = $this->samlSettings->getListOfIdps();
$idps = $this->samlSettings->getListOfIdps($this->request);
foreach ($idps as $idpId => $displayName) {
$result[] = [
'url' => $this->getSSOUrl($redirectUrl, (string)$idpId),
Expand Down
12 changes: 11 additions & 1 deletion lib/SAMLSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class SAMLSettings {
// IdP-specific keys
public const IDP_CONFIG_KEYS = [
'general-idp0_display_name',
'general-custom_hosts',
'general-uid_mapping',
'idp-entityId',
'idp-singleLogoutService.responseUrl',
Expand Down Expand Up @@ -95,11 +96,20 @@ public function __construct(
* @return array<int, string>
* @throws Exception
*/
public function getListOfIdps(): array {
public function getListOfIdps(?\OCP\IRequest $request = null): array {
$serverHost = !is_null($request) ? $request->getServerHost() : null;

$this->ensureConfigurationsLoaded();

$result = [];
foreach ($this->configurations as $configID => $config) {
// Filter configs which don't match the trusted host in the request
if (!empty($serverHost)) {
$customHosts = key_exists('general-custom_hosts', $config) ? array_map('trim', explode(',', $config['general-custom_hosts'])) : [];
if (!in_array($serverHost, $customHosts)) {
continue;
}
}
// no fancy array_* method, because there might be thousands
$result[$configID] = $config['general-idp0_display_name'] ?? '';
}
Expand Down
4 changes: 4 additions & 0 deletions lib/Settings/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public function getForm() {
'type' => 'line',
'required' => true,
],
'custom_hosts' => [
'text' => $this->l10n->t('Hostnames associated with this provider (e.g. nextcloud.a.com, nextcloud.b.com).'),
'type' => 'line',
],
'require_provisioned_account' => [
'text' => $this->l10n->t('Only allow authentication if an account exists on some other backend (e.g. LDAP).'),
'type' => 'checkbox',
Expand Down
Loading