-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: get authsources configuration from database
- Loading branch information
Showing
3 changed files
with
62 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,56 @@ | ||
<?php | ||
<?php | ||
|
||
$config = array( | ||
'admin' => array( | ||
'core:AdminPassword', | ||
), | ||
use SimpleSAML\Configuration; | ||
use SimpleSAML\Database; | ||
|
||
{{AUTHSOURCE_SPID}} | ||
define('AUTHSOURCES_DATABASE_TABLE', 'authsources'); | ||
|
||
$ssp_config = Configuration::getInstance(); | ||
$authsources_storage = $ssp_config->getString('authsources.storage', 'file'); | ||
|
||
if($authsources_storage=='database') { | ||
$db = Database::getInstance(); | ||
$authsources_database_table = $ssp_config->getString('authsources.database_table', AUTHSOURCES_DATABASE_TABLE); | ||
// create table if not exists | ||
$db->write(sprintf(" | ||
CREATE TABLE IF NOT EXISTS $authsources_database_table ( | ||
`id` VARCHAR(255) PRIMARY KEY NOT NULL, | ||
`entity_data` JSON NOT NULL, | ||
`_disabled` enum('N','Y') NOT NULL DEFAULT 'N' | ||
); | ||
")); | ||
// get config from database | ||
$statement = $db->read("SELECT `id`, `entity_data` FROM `" . $authsources_database_table . "` WHERE `_disabled`='N'"); | ||
$authsources = $statement->fetchAll(); | ||
{{AUTHSOURCE_CIE}} | ||
); | ||
$config = [ | ||
// This is a authentication source which handles admin authentication. | ||
'admin' => [ | ||
// The default is to use core:AdminPassword, but it can be replaced with | ||
// any authentication source. | ||
'core:AdminPassword', | ||
], | ||
]; | ||
// compile config | ||
foreach($authsources as $as) { | ||
$config[$as['id']] = json_decode($as['entity_data'], true); | ||
} | ||
|
||
} else { | ||
$config = array( | ||
'admin' => array( | ||
'core:AdminPassword', | ||
), | ||
{{AUTHSOURCE_SPID}} | ||
|
||
{{AUTHSOURCE_CIE}} | ||
); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters