Skip to content

Commit a159dbd

Browse files
authored
Merge pull request #20 from nathanjrobertson/sql2
Support aggregation of attributes from multiple databases
2 parents c52234b + 2d7157b commit a159dbd

25 files changed

+2790
-133
lines changed

.github/workflows/php.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ jobs:
217217
with:
218218
# Should be the lowest supported version
219219
php-version: '8.2'
220-
extensions: ctype, date, dom, fileinfo, filter, hash, intl, mbstring, openssl, pcre, pdo, posix, spl, xml
220+
extensions: ctype, date, dom, fileinfo, filter, hash, intl, mbstring, openssl, pcre, pdo, posix, spl, xml, zip
221221
tools: composer
222222
coverage: none
223223

@@ -237,7 +237,7 @@ jobs:
237237
restore-keys: ${{ runner.os }}-composer-
238238

239239
- name: Install Composer dependencies
240-
run: composer install --no-progress --prefer-dist --optimize-autoloader
240+
run: composer install --no-progress --prefer-dist --optimize-autoloader --ignore-platform-req=ext-posix
241241

242242
- name: Security check for locked dependencies
243243
run: composer audit

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@
3030
},
3131
"autoload-dev": {
3232
"psr-4": {
33-
"SimpleSAML\\Test\\Utils\\": "vendor/simplesamlphp/simplesamlphp/tests/Utils"
33+
"SimpleSAML\\Test\\Utils\\": "vendor/simplesamlphp/simplesamlphp/tests/Utils",
34+
"SimpleSAML\\Test\\Module\\sqlauth\\Auth\\Source\\": "tests/src/Auth/Source/"
3435
}
3536
},
3637
"require": {
3738
"php": "^8.2",
3839
"ext-pdo": "*",
3940

4041
"simplesamlphp/assert": "~1.9.1",
41-
"simplesamlphp/composer-module-installer": "~1.5.0",
42+
"simplesamlphp/composer-module-installer": "~1.6.0",
4243
"simplesamlphp/simplesamlphp": "^2.2"
4344
},
4445
"require-dev": {

docs/sql.md

Lines changed: 492 additions & 55 deletions
Large diffs are not rendered by default.

phpstan-baseline-dev.neon

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
parameters:
22
ignoreErrors:
33
-
4-
message: '#^Parameter \#1 \$array of function asort expects array, string given\.$#'
5-
identifier: argument.type
6-
count: 4
7-
path: tests/src/Auth/Source/PasswordVerifyTest.php
4+
message: '#^Property SimpleSAML\\Test\\Module\\sqlauth\\Auth\\Source\\SQL2MultipleAuthTest\:\:\$config type has no value type specified in iterable type array\.$#'
5+
identifier: missingType.iterableValue
6+
count: 1
7+
path: tests/src/Auth/Source/SQL2MultipleAuthTest.php
88

99
-
10-
message: '#^Property SimpleSAML\\Test\\Module\\sqlauth\\Auth\\Source\\PasswordVerifyTest\:\:\$config \(array\<string, string\|null\>\) does not accept array\<string, list\<string\>\|string\|null\>\.$#'
11-
identifier: assign.propertyType
12-
count: 4
13-
path: tests/src/Auth/Source/PasswordVerifyTest.php
10+
message: '#^Property SimpleSAML\\Test\\Module\\sqlauth\\Auth\\Source\\SQL2NonExistentDbTest\:\:\$config type has no value type specified in iterable type array\.$#'
11+
identifier: missingType.iterableValue
12+
count: 1
13+
path: tests/src/Auth/Source/SQL2NonExistentDbTest.php
1414

1515
-
16-
message: '#^Parameter \#1 \$array of function asort expects array, mixed given\.$#'
17-
identifier: argument.type
18-
count: 4
19-
path: tests/src/Auth/Source/SQLTest.php
20-
21-
-
22-
message: '#^Property SimpleSAML\\Test\\Module\\sqlauth\\Auth\\Source\\SQLTest\:\:\$config \(array\<string, string\|null\>\) does not accept array\<string, list\<string\>\|string\|null\>\.$#'
23-
identifier: assign.propertyType
24-
count: 4
25-
path: tests/src/Auth/Source/SQLTest.php
16+
message: '#^Property SimpleSAML\\Test\\Module\\sqlauth\\Auth\\Source\\SQL2SimpleTest\:\:\$config type has no value type specified in iterable type array\.$#'
17+
identifier: missingType.iterableValue
18+
count: 1
19+
path: tests/src/Auth/Source/SQL2SimpleTest.php
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\Module\sqlauth\Auth\Source;
6+
7+
/**
8+
* @package SimpleSAMLphp
9+
*/
10+
11+
class PasswordVerify1Compat extends SQL2
12+
{
13+
/**
14+
* Constructor for this authentication source.
15+
*
16+
* @param array $info Information about this authentication source.
17+
* @param array $config Configuration.
18+
*/
19+
public function __construct(array $info, array $config)
20+
{
21+
/* Transform PasswordVerify (version 1) config to SQL2 config
22+
* Version 1 supported only one database, but multiple queries. The first query was defined
23+
* to be the "authentication query", all subsequent queries were "attribute queries".
24+
*/
25+
$v2config = [
26+
'sqlauth:SQL2',
27+
'databases' => [
28+
'default' => [
29+
'dsn' => $config['dsn'],
30+
'username' => $config['username'],
31+
'password' => $config['password'],
32+
],
33+
],
34+
35+
'auth_queries' => [
36+
'default' => [
37+
'database' => 'default',
38+
'query' => is_array($config['query']) ? $config['query'][0] : $config['query'],
39+
'password_verify_hash_column' => 'passwordhash',
40+
],
41+
],
42+
];
43+
44+
if (array_key_exists('username_regex', $config)) {
45+
$v2config['auth_queries']['default']['username_regex'] = $config['username_regex'];
46+
}
47+
48+
// Override the default passwordhash column if configured
49+
if (array_key_exists('passwordhash_column', $config)) {
50+
$v2config['auth_queries']['default']['password_verify_hash_column'] = $config['passwordhash_column'];
51+
}
52+
53+
$numQueries = is_array($config['query']) ? count($config['query']) : 0;
54+
if ($numQueries > 1) {
55+
$v2config['attr_queries'] = [];
56+
for ($i = 1; $i < $numQueries; $i++) {
57+
$v2config['attr_queries']['query' . $i] = [
58+
'database' => 'default',
59+
'query' => $config['query'][$i],
60+
];
61+
}
62+
}
63+
64+
// Copy other config keys that are not specific to SQL1 (eg. core:login_links)
65+
foreach (array_keys($config) as $key) {
66+
if (in_array($key, ['dsn', 'username', 'password', 'query', 'username_regex', 'passwordhashcolumn'])) {
67+
continue;
68+
}
69+
70+
$v2config[$key] = $config[$key];
71+
}
72+
73+
parent::__construct($info, $v2config);
74+
}
75+
}

src/Auth/Source/SQL1Compat.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\Module\sqlauth\Auth\Source;
6+
7+
/**
8+
* @package SimpleSAMLphp
9+
*/
10+
11+
class SQL1Compat extends SQL2
12+
{
13+
/**
14+
* Constructor for this authentication source.
15+
*
16+
* @param array $info Information about this authentication source.
17+
* @param array $config Configuration.
18+
*/
19+
public function __construct(array $info, array $config)
20+
{
21+
/* Transform SQL (version 1) config to SQL2 config
22+
* Version 1 supported only one database, but multiple queries. The first query was defined
23+
* to be the "authentication query", all subsequent queries were "attribute queries".
24+
*/
25+
$v2config = [
26+
'sqlauth:SQL2',
27+
'databases' => [
28+
'default' => [
29+
'dsn' => $config['dsn'],
30+
'username' => $config['username'],
31+
'password' => $config['password'],
32+
],
33+
],
34+
35+
'auth_queries' => [
36+
'default' => [
37+
'database' => 'default',
38+
'query' => is_array($config['query']) ? $config['query'][0] : $config['query'],
39+
],
40+
],
41+
];
42+
43+
if (array_key_exists('username_regex', $config)) {
44+
$v2config['auth_queries']['default']['username_regex'] = $config['username_regex'];
45+
}
46+
47+
$numQueries = is_array($config['query']) ? count($config['query']) : 0;
48+
if ($numQueries > 1) {
49+
$v2config['attr_queries'] = [];
50+
for ($i = 1; $i < $numQueries; $i++) {
51+
$v2config['attr_queries']['query' . $i] = [
52+
'database' => 'default',
53+
'query' => $config['query'][$i],
54+
];
55+
}
56+
}
57+
58+
// Copy other config keys that are not specific to SQL1 (eg. core:login_links)
59+
foreach (array_keys($config) as $key) {
60+
if (in_array($key, ['dsn', 'username', 'password', 'query', 'username_regex'])) {
61+
continue;
62+
}
63+
64+
$v2config[$key] = $config[$key];
65+
}
66+
67+
parent::__construct($info, $v2config);
68+
}
69+
}

0 commit comments

Comments
 (0)