Definition at line 12 of file SQL.php.
◆ __construct()
sspmod_sqlauth_Auth_Source_SQL::__construct |
( |
|
$info, |
|
|
|
$config |
|
) |
| |
Constructor for this authentication source.
- Parameters
-
array | $info | Information about this authentication source. |
array | $config | Configuration. |
Definition at line 47 of file SQL.php.
References $config, and $info.
49 assert(is_array(
$info));
56 foreach (array(
'dsn',
'username',
'password',
'query') as $param) {
57 if (!array_key_exists($param,
$config)) {
58 throw new Exception(
'Missing required attribute \'' . $param .
59 '\' for authentication source
' . $this->authId); 62 if (!is_string($config[$param])) { 63 throw new Exception('Expected parameter \
'' . $param .
64 '\' for authentication source
' . $this->authId . 65 ' to be
a string. Instead it was:
' . 66 var_export($config[$param], true)); 70 $this->dsn = $config['dsn
']; 71 $this->username = $config['username
']; 72 $this->password = $config['password
']; 73 $this->query = $config['query
']; 74 if (isset($config['options
'])) { 75 $this->options = $config['options
'];
◆ connect()
sspmod_sqlauth_Auth_Source_SQL::connect |
( |
| ) |
|
|
private |
Create a database connection.
- Returns
- PDO The database connection.
Definition at line 85 of file SQL.php.
88 $db =
new PDO($this->dsn, $this->username, $this->password, $this->options);
90 throw new Exception(
'sqlauth:' . $this->authId .
': - Failed to connect to \'' .
91 $this->dsn .
'\':
'. $e->getMessage()); 94 $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 96 $driver = explode(':
', $this->dsn, 2); 97 $driver = strtolower($driver[0]); 99 /* Driver specific initialization. */ 103 $db->exec("SET NAMES 'utf8mb4
'"); 107 $db->exec("SET NAMES 'UTF8
'");
◆ login()
sspmod_sqlauth_Auth_Source_SQL::login |
( |
|
$username, |
|
|
|
$password |
|
) |
| |
|
protected |
Attempt to log in using the given username and password.
On a successful login, this function should return the users attributes. On failure, it should throw an exception. If the error was caused by the user entering the wrong username or password, a SimpleSAML_Error_Error('WRONGUSERPASS') should be thrown.
Note that both the username and the password are UTF-8 encoded.
- Parameters
-
string | $username | The username the user wrote. |
string | $password | The password the user wrote. |
- Returns
- array Associative array with the users attributes.
Definition at line 128 of file SQL.php.
136 $sth = $db->prepare($this->query);
138 throw new Exception(
'sqlauth:' . $this->authId .
139 ': - Failed to prepare query: ' . $e->getMessage());
145 throw new Exception(
'sqlauth:' . $this->authId .
146 ': - Failed to execute query: ' . $e->getMessage());
150 $data = $sth->fetchAll(PDO::FETCH_ASSOC);
152 throw new Exception(
'sqlauth:' . $this->authId .
153 ': - Failed to fetch result set: ' . $e->getMessage());
157 ' rows from database');
159 if (count(
$data) === 0) {
162 ': No rows in result set. Probably wrong username/password.');
172 foreach ($row as
$name => $value) {
174 if ($value === null) {
178 $value = (string)$value;
$username
The username we should connect to the database with.
$password
The password we should connect to the database with.
connect()
Create a database connection.
if(array_key_exists('yes', $_REQUEST)) $attributes
◆ $dsn
sspmod_sqlauth_Auth_Source_SQL::$dsn |
|
private |
The DSN we should connect to.
Definition at line 17 of file SQL.php.
◆ $options
sspmod_sqlauth_Auth_Source_SQL::$options |
|
private |
The options that we should connect to the database with.
Definition at line 32 of file SQL.php.
◆ $password
sspmod_sqlauth_Auth_Source_SQL::$password |
|
private |
The password we should connect to the database with.
Definition at line 27 of file SQL.php.
◆ $query
sspmod_sqlauth_Auth_Source_SQL::$query |
|
private |
The query we should use to retrieve the attributes for the user.
The username and password will be available as :username and :password.
Definition at line 39 of file SQL.php.
◆ $username
sspmod_sqlauth_Auth_Source_SQL::$username |
|
private |
The username we should connect to the database with.
Definition at line 22 of file SQL.php.
The documentation for this class was generated from the following file:
- libs/composer/vendor/simplesamlphp/simplesamlphp/modules/sqlauth/lib/Auth/Source/SQL.php