Commit 5f8d03fe authored by Wolfgang Knopki's avatar Wolfgang Knopki
Browse files

added compatibility with simplesamlphp 1.19

parent 8e8e5b35
......@@ -12,8 +12,13 @@
* @package simpleSAMLphp
* @version $Id$
*/
class sspmod_sqlauthBcrypt_Auth_Source_SQL extends sspmod_core_Auth_UserPassBase {
/*class sspmod_sqlauthBcrypt_Auth_Source_SQL extends sspmod_core_Auth_UserPassBase {*/
namespace SimpleSAML\Module\sqlauthbcrypt\Auth\Source;
class sql extends \SimpleSAML\Module\core\Auth\UserPassBase {
/**
* The DSN we should connect to.
......@@ -68,12 +73,12 @@ class sspmod_sqlauthBcrypt_Auth_Source_SQL extends sspmod_core_Auth_UserPassBase
/* Make sure that all required parameters are present. */
foreach (array('dsn', 'username', 'password', 'query', 'pepper') as $param) {
if (!array_key_exists($param, $config)) {
throw new Exception('Missing required attribute \'' . $param .
throw new \Exception('Missing required attribute \'' . $param .
'\' for authentication source ' . $this->authId);
}
if (!is_string($config[$param])) {
throw new Exception('Expected parameter \'' . $param .
throw new \Exception('Expected parameter \'' . $param .
'\' for authentication source ' . $this->authId .
' to be a string. Instead it was: ' .
var_export($config[$param], TRUE));
......@@ -96,13 +101,13 @@ class sspmod_sqlauthBcrypt_Auth_Source_SQL extends sspmod_core_Auth_UserPassBase
*/
private function connect() {
try {
$db = new PDO($this->dsn, $this->username, $this->password);
} catch (PDOException $e) {
throw new Exception('sqlauthBcrypt:' . $this->authId .
$db = new \PDO($this->dsn, $this->username, $this->password);
} catch (\PDOException $e) {
throw new \Exception('sqlauthBcrypt:' . $this->authId .
': - Failed to connect to \'' . $this->dsn . '\': '. $e->getMessage());
}
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$driver = explode(':', $this->dsn, 2);
......@@ -137,7 +142,7 @@ class sspmod_sqlauthBcrypt_Auth_Source_SQL extends sspmod_core_Auth_UserPassBase
* @param string $password The password the user wrote.
* @return array Associative array with the users attributes.
*/
protected function login($username, $password) {
protected function login(string $username,string $password):array {
assert('is_string($username)');
assert('is_string($password)');
......@@ -145,33 +150,33 @@ class sspmod_sqlauthBcrypt_Auth_Source_SQL extends sspmod_core_Auth_UserPassBase
try {
$sth = $db->prepare($this->query);
} catch (PDOException $e) {
throw new Exception('sqlauthBcrypt:' . $this->authId .
} catch (\PDOException $e) {
throw new \Exception('sqlauthBcrypt:' . $this->authId .
': - Failed to prepare query: ' . $e->getMessage());
}
try {
$res = $sth->execute(array('username' => $username));
} catch (PDOException $e) {
throw new Exception('sqlauthBcrypt:' . $this->authId .
} catch ( \PDOException $e) {
throw new \Exception('sqlauthBcrypt:' . $this->authId .
': - Failed to execute query: ' . $e->getMessage());
}
try {
$data = $sth->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
throw new Exception('sqlauth:' . $this->authId .
$data = $sth->fetchAll(\PDO::FETCH_ASSOC);
} catch (\PDOException $e) {
throw new \Exception('sqlauth:' . $this->authId .
': - Failed to fetch result set: ' . $e->getMessage());
}
SimpleSAML_Logger::info('sqlauthBcrypt:' . $this->authId .
\SimpleSAML\Logger::info('sqlauthBcrypt:' . $this->authId .
': Got ' . count($data) . ' rows from database');
if (count($data) === 0) {
/* No rows returned - invalid username */
SimpleSAML_Logger::error('sqlauthBcrypt:' . $this->authId .
\SimpleSAML\Logger::error('sqlauthBcrypt:' . $this->authId .
': No rows in result set. Wrong username or sqlauthBcrypt is misconfigured.');
throw new SimpleSAML_Error_Error('WRONGUSERPASS');
throw new \SimpleSAML\Error\Error('WRONGUSERPASS');
}
/* Validate stored password hash (must be in first row of resultset) */
......@@ -179,9 +184,9 @@ class sspmod_sqlauthBcrypt_Auth_Source_SQL extends sspmod_core_Auth_UserPassBase
if ($password_hash !== crypt($password.$this->pepper, $password_hash)) {
/* Invalid password */
SimpleSAML_Logger::error('sqlauthBcrypt:' . $this->authId .
\SimpleSAML\Logger::error('sqlauthBcrypt:' . $this->authId .
': Hash does not match. Wrong password or sqlauthBcrypt is misconfigured.');
throw new SimpleSAML_Error_Error('WRONGUSERPASS');
throw new \SimpleSAML\Error\Error('WRONGUSERPASS');
}
/* Extract attributes. We allow the resultset to consist of multiple rows. Attributes
......@@ -216,7 +221,7 @@ class sspmod_sqlauthBcrypt_Auth_Source_SQL extends sspmod_core_Auth_UserPassBase
}
}
SimpleSAML_Logger::info('sqlauthBcrypt:' . $this->authId .
\SimpleSAML\Logger::info('sqlauthBcrypt:' . $this->authId .
': Attributes: ' . implode(',', array_keys($attributes)));
return $attributes;
......@@ -225,3 +230,4 @@ class sspmod_sqlauthBcrypt_Auth_Source_SQL extends sspmod_core_Auth_UserPassBase
}
?>
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