Commit 1b34bc7e authored by Robert Lyon's avatar Robert Lyon Committed by Cecilia Vela Gurovic
Browse files

Bug 1691957: Allow SQL for SimpleSamlPhp datastore



As an alternative for memcache / redis

behatnotneeded

Change-Id: I8be8894f1cda6d0102db31475025236a5a4b86ca
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 213539e7
......@@ -38,6 +38,8 @@ foreach ($metadata_files as $file) {
// Fix up session handling config - to match Mahara
$memcache_config = array();
$redis_config = array('host' => '', 'port' => 6379, 'prefix' => '');
$sql_config = array('dsn' => '', 'username' => null, 'password' => null, 'prefix' => '');
if (empty(get_config('ssphpsessionhandler'))) {
if (PluginAuthSaml::is_memcache_configured()) {
$sessionhandler = 'memcache';
......@@ -47,12 +49,20 @@ if (empty(get_config('ssphpsessionhandler'))) {
$sessionhandler = 'redis';
$redis_config = PluginAuthSaml::get_redis_config();
}
else if (PluginAuthSaml::is_sql_configured()) {
$sessionhandler = 'sql';
$sql_config = PluginAuthSaml::get_sql_config();
}
else {
throw new AuthInstanceException(get_string('errornovalidsessionhandler', 'auth.saml'));
}
}
else {
$sessionhandler = get_config('ssphpsessionhandler');
$method = 'get_' . $sessionhandler . '_config';
if (method_exists('PluginAuthSaml', $method)) {
${$sessionhandler . "_config"} = call_static_method('PluginAuthSaml', $method);
}
}
/*
......@@ -503,18 +513,18 @@ $config = array (
* See http://www.php.net/manual/en/pdo.drivers.php for the various
* syntaxes.
*/
'store.sql.dsn' => 'sqlite:/path/to/sqlitedatabase.sq3',
'store.sql.dsn' => $sql_config['dsn'],
/*
* The username and password to use when connecting to the database.
*/
'store.sql.username' => null,
'store.sql.password' => null,
'store.sql.username' => $sql_config['username'],
'store.sql.password' => $sql_config['password'],
/*
* The prefix we should use on our tables.
*/
'store.sql.prefix' => 'SimpleSAMLphp',
'store.sql.prefix' => $sql_config['prefix'],
/*
* The hostname and port of the Redis datastore instance.
......
......@@ -802,11 +802,17 @@ class PluginAuthSaml extends PluginAuth {
return true;
}
if (get_config('ssphpsessionhandler') == 'sql' && self::is_sql_configured()) {
return true;
}
if (empty(get_config('ssphpsessionhandler'))) {
// Check Redis
$ishandler = self::is_redis_configured();
// And check Memcache if no Redis
$ishandler = $ishandler ? $ishandler : self::is_memcache_configured();
// And check Sql if no Memcache
$ishandler = $ishandler ? $ishandler : self::is_sql_configured();
return $ishandler;
}
......@@ -910,6 +916,25 @@ class PluginAuthSaml extends PluginAuth {
return $redis_servers;
}
public static function is_sql_configured() {
$config = PluginAuthSaml::get_sql_config();
try {
$connection = new PDO($config['dsn'], $config['username'], $config['password']);
return true;
}
catch (PDOException $e) {
return false;
}
}
public static function get_sql_config() {
return array('dsn' => get_config('ssphpsqldsn'),
'username' => get_config('ssphpsqlusername'),
'password' => get_config('ssphpsqlpassword'),
'prefix' => get_config('ssphpsqlprefix'),
);
}
public static function get_idps($xml) {
$xml = new SimpleXMLElement($xml);
$xml->registerXPathNamespace('md', 'urn:oasis:names:tc:SAML:2.0:metadata');
......
......@@ -721,19 +721,20 @@ $cfg->openbadgedisplayer_source = '{"backpack":"https://backpack.openbadges.org/
/**
* @global string $cfg->sessionhandler
* An alternative session handler for Mahara if you do not wish to use files.
* Specify the name of the session handler.
* Specify the name of the session handler. Will be used for SAML session handling unless $cfg->ssphpsessionhandler set
*/
$cfg->sessionhandler = 'file';
//$cfg->sessionhandler = 'memcached'; // also set the $cfg->memcacheservers setting if using this one
//$cfg->sessionhandler = 'redis'; // also set the $cfg->redis* ssettings if using this one
//$cfg->sessionhandler = 'redis'; // also set the $cfg->redis* settings if using this one
/**
* @global string $cfg->ssphpsessionhandler
* An alternative session handler for SimpleSAMLphp if you do not wish to use memcache.
* Specify the name of the session handler.
*/
// $cfg->ssphpsessionhandler = 'memcached';
// $cfg->ssphpsessionhandler = 'memcached'; // also set the $cfg->memcacheservers setting if using this one
// $cfg->ssphpsessionhandler = 'redis'; // also set the $cfg->redis* setting if using this one
// $cfg->ssphpsessionhandler = 'sql'; // also set the $cfg->ssphpsql* settings if using this one
/**
* Redis session handling
......@@ -742,6 +743,17 @@ $cfg->sessionhandler = 'file';
//$cfg->redismastergroup = 'mymaster';
//$cfg->redisprefix = 'mahara';
/**
* SQL session store configs for SimpleSAMLphp
* Specify the SQL database connection string, credentials and table prefix
*/
/*
$cfg->ssphpsqldsn = "mysql:host=localhost;dbname=simplesamlphp";
$cfg->ssphpsqlusername = null;
$cfg->ssphpsqlpassword = null;
$cfg->ssphpsqlprefix = 'ssphp';
*/
/**
* @global array $cfg->saml_custommappingfile
* A list of paths to custom attribute mapping files for SimpleSAMLphp IDP and SP
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment