diff --git a/config-templates/config.php b/config-templates/config.php index 12dc7eb67606f6030d3eb06649307f1413f28d31..5833e48ebd76f8a49e618010a30e44fe4aac5cdc 100644 --- a/config-templates/config.php +++ b/config-templates/config.php @@ -1,7 +1,7 @@ <?php -/* +/* * The configuration of SimpleSAMLphp - * + * */ $config = array( @@ -60,7 +60,7 @@ $config = array( * - 'temdir': Saving temporary files. SimpleSAMLphp will attempt to create * this directory if it doesn't exist. * When specified as a relative path, this is relative to the SimpleSAMLphp - * root directory. + * root directory. */ 'certdir' => 'cert/', 'loggingdir' => 'log/', @@ -377,6 +377,7 @@ $config = array( */ 'database.username' => 'simplesamlphp', 'database.password' => 'secret', + 'database.options' => array(), /* * (Optional) Table prefix diff --git a/docs/simplesamlphp-customauth.md b/docs/simplesamlphp-customauth.md index 8f7c30f9fd5e3826307cb70d758ac80933438377..8238ba695b3dfbfafd23a356e6420ed3084cd43a 100644 --- a/docs/simplesamlphp-customauth.md +++ b/docs/simplesamlphp-customauth.md @@ -253,9 +253,10 @@ The class follows: */ private $dsn; - /* The database username & password. */ + /* The database username, password & options. */ private $username; private $password; + private $options; public function __construct($info, $config) { parent::__construct($info, $config); @@ -272,6 +273,12 @@ The class follows: throw new Exception('Missing or invalid password option in config.'); } $this->password = $config['password']; + if (isset($config['options']) { + if (!is_array($config['options])) { + throw new Exception('Missing or invalid options option in config.'); + } + $this->options = $config['options']; + } } /** @@ -294,7 +301,7 @@ The class follows: protected function login($username, $password) { /* Connect to the database. */ - $db = new PDO($this->dsn, $this->username, $this->password); + $db = new PDO($this->dsn, $this->username, $this->password, $this->options); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); /* Ensure that we are operating with UTF-8 encoding. diff --git a/lib/SimpleSAML/Store/SQL.php b/lib/SimpleSAML/Store/SQL.php index 614a7f7b8840cfb0b79174a5a16b9ef577e7b587..ec46c24ce98bb2c36fb470496a8d9f8c02204060 100755 --- a/lib/SimpleSAML/Store/SQL.php +++ b/lib/SimpleSAML/Store/SQL.php @@ -55,9 +55,10 @@ class SQL extends Store $dsn = $config->getString('store.sql.dsn'); $username = $config->getString('store.sql.username', null); $password = $config->getString('store.sql.password', null); + $options = $config->getArray('store.sql.options', null); $this->prefix = $config->getString('store.sql.prefix', 'simpleSAMLphp'); - $this->pdo = new \PDO($dsn, $username, $password); + $this->pdo = new \PDO($dsn, $username, $password, $options); $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $this->driver = $this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME); diff --git a/modules/consent/lib/Consent/Store/Database.php b/modules/consent/lib/Consent/Store/Database.php index d23f2c6a14bed23e9ac350d4fb8245986306591e..82017a2157f48aea11bc5049c34449dde4f26693 100644 --- a/modules/consent/lib/Consent/Store/Database.php +++ b/modules/consent/lib/Consent/Store/Database.php @@ -37,6 +37,11 @@ class sspmod_consent_Consent_Store_Database extends sspmod_consent_Store */ private $_password; + /** + * Options for the database; + */ + private $_options; + /** * Table with consent. */ @@ -98,6 +103,14 @@ class sspmod_consent_Consent_Store_Database extends sspmod_consent_Store $this->_password = null; } + if (array_key_exists('options', $config)) { + if (!is_array($config['options'])) { + throw new Exception('consent:Database - \'options\' is supposed to be an array.'); + } + $this->_options = $config['options']; + } else { + $this->_options = null; + } if (array_key_exists('table', $config)) { if (!is_string($config['table'])) { throw new Exception('consent:Database - \'table\' is supposed to be a string.'); @@ -380,7 +393,7 @@ class sspmod_consent_Consent_Store_Database extends sspmod_consent_Store // Get total number of consents $st = $this->_execute('SELECT COUNT(*) AS no FROM '.$this->_table, array()); - + if ($st === false) { return array(); } @@ -395,7 +408,7 @@ class sspmod_consent_Consent_Store_Database extends sspmod_consent_Store 'FROM (SELECT DISTINCT hashed_user_id FROM '.$this->_table.' ) AS foo', array() ); - + if ($st === false) { return array(); } @@ -409,7 +422,7 @@ class sspmod_consent_Consent_Store_Database extends sspmod_consent_Store 'SELECT COUNT(*) AS no FROM (SELECT DISTINCT service_id FROM '.$this->_table.') AS foo', array() ); - + if ($st === false) { return array(); } @@ -437,8 +450,13 @@ class sspmod_consent_Consent_Store_Database extends sspmod_consent_Store if (isset($this->_timeout)) { $driver_options[PDO::ATTR_TIMEOUT] = $this->_timeout; } + if (isset($this->_options)) { + $this->_options = array_merge($driver_options, $this->_options); + } else { + $this->_options = $driver_options; + } - $this->_db = new PDO($this->_dsn, $this->_username, $this->_password, $driver_options); + $this->_db = new PDO($this->_dsn, $this->_username, $this->_password, $this->_options); return $this->_db; } diff --git a/modules/sqlauth/lib/Auth/Source/SQL.php b/modules/sqlauth/lib/Auth/Source/SQL.php index a99f496ce03eeba41ed2ed36f6d9ab9e4b894cc9..6cb5c831be95550dbd948dccced81eff33d4a641 100644 --- a/modules/sqlauth/lib/Auth/Source/SQL.php +++ b/modules/sqlauth/lib/Auth/Source/SQL.php @@ -26,6 +26,11 @@ class sspmod_sqlauth_Auth_Source_SQL extends sspmod_core_Auth_UserPassBase */ private $password; + /** + * The options that we should connect to the database with. + */ + private $options; + /** * The query we should use to retrieve the attributes for the user. * @@ -66,6 +71,9 @@ class sspmod_sqlauth_Auth_Source_SQL extends sspmod_core_Auth_UserPassBase $this->username = $config['username']; $this->password = $config['password']; $this->query = $config['query']; + if (isset($config['options'])) { + $this->options = $config['options']; + } } @@ -77,7 +85,7 @@ class sspmod_sqlauth_Auth_Source_SQL extends sspmod_core_Auth_UserPassBase private function connect() { try { - $db = new PDO($this->dsn, $this->username, $this->password); + $db = new PDO($this->dsn, $this->username, $this->password, $this->options); } catch (PDOException $e) { throw new Exception('sqlauth:' . $this->authId . ': - Failed to connect to \'' . $this->dsn . '\': '. $e->getMessage());