forked from simplesamlphp/simplesamlphp-module-sqlauth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordVerify1Compat.php
More file actions
75 lines (64 loc) · 2.49 KB
/
PasswordVerify1Compat.php
File metadata and controls
75 lines (64 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
declare(strict_types=1);
namespace SimpleSAML\Module\sqlauth\Auth\Source;
/**
* @package SimpleSAMLphp
*/
class PasswordVerify1Compat extends SQL2
{
/**
* Constructor for this authentication source.
*
* @param array $info Information about this authentication source.
* @param array $config Configuration.
*/
public function __construct(array $info, array $config)
{
/* Transform PasswordVerify (version 1) config to SQL2 config
* Version 1 supported only one database, but multiple queries. The first query was defined
* to be the "authentication query", all subsequent queries were "attribute queries".
*/
$v2config = [
'sqlauth:SQL2',
'databases' => [
'default' => [
'dsn' => $config['dsn'],
'username' => $config['username'],
'password' => $config['password'],
],
],
'auth_queries' => [
'default' => [
'database' => 'default',
'query' => is_array($config['query']) ? $config['query'][0] : $config['query'],
'password_verify_hash_column' => 'passwordhash',
],
],
];
if (array_key_exists('username_regex', $config)) {
$v2config['auth_queries']['default']['username_regex'] = $config['username_regex'];
}
// Override the default passwordhash column if configured
if (array_key_exists('passwordhash_column', $config)) {
$v2config['auth_queries']['default']['password_verify_hash_column'] = $config['passwordhash_column'];
}
$numQueries = is_array($config['query']) ? count($config['query']) : 0;
if ($numQueries > 1) {
$v2config['attr_queries'] = [];
for ($i = 1; $i < $numQueries; $i++) {
$v2config['attr_queries']['query' . $i] = [
'database' => 'default',
'query' => $config['query'][$i],
];
}
}
// Copy other config keys that are not specific to SQL1 (eg. core:login_links)
foreach (array_keys($config) as $key) {
if (in_array($key, ['dsn', 'username', 'password', 'query', 'username_regex', 'passwordhashcolumn'])) {
continue;
}
$v2config[$key] = $config[$key];
}
parent::__construct($info, $v2config);
}
}