Skip to content

Commit 2031cd0

Browse files
committed
Remove deprecation warnings for SSP 1.17
1 parent 6a41370 commit 2031cd0

5 files changed

Lines changed: 119 additions & 122 deletions

File tree

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@ This module provides the _sqlattribs:AttributeFromSQL_ auth proc filter,
5151
which can be used as follows:
5252

5353
```php
54-
50 => array(
54+
50 => [
5555
'class' => 'sqlattribs:AttributeFromSQL',
5656
'attribute' => 'eduPersonPrincipalName',
57-
'limit' => array('eduPersonEntitlement', 'eduPersonAffiliation'),
57+
'limit' => ['eduPersonEntitlement', 'eduPersonAffiliation'],
5858
'replace' => false,
59-
'database' => array(
59+
'database' => [
6060
'dsn' => 'mysql:host=localhost;dbname=simplesamlphp',
6161
'username' => 'yourDbUsername',
6262
'password' => 'yourDbPassword',
6363
'table' => 'AttributeFromSQL',
64-
),
65-
),
64+
],
65+
],
6666
```
6767

6868
Where the parameters are as follows:
@@ -110,29 +110,29 @@ multi-valued attribute. Thus assuming the user _user@example.org_
110110
started with attributes of:
111111

112112
```php
113-
$attributes = array(
113+
$attributes = [
114114
'eduPersonPrincipalName' => 'user@example.org',
115-
'eduPersonAffiliation' => array('member'),
115+
'eduPersonAffiliation' => ['member'],
116116
'displayName' => 'Example User',
117-
),
117+
],
118118
```
119119

120120
The the above SQL table and example auth proc filter would lead to a
121121
combined attribute set of:
122122

123123
```php
124-
$attributes = array(
124+
$attributes = [
125125
'eduPersonPrincipalName' => 'user@example.org',
126126
'displayName' => 'Example User',
127-
'eduPersonEntitlement' => array(
127+
'eduPersonEntitlement' => [
128128
'urn:mace:exampleIdP.org:demoservice:demo-admin',
129129
'urn:mace:grnet.gr:eduroam:admin',
130-
),
131-
'eduPersonAffiliation' => array(
130+
],
131+
'eduPersonAffiliation' => [
132132
'member',
133133
'faculty',
134-
),
135-
),
134+
],
135+
],
136136
```
137137

138138
Note that because the the `limit` parameter, the mail attribute was not added. And because `replace` was false, _eduPersonAffiliation_ was merged. It is assumed that this SP has an Entity Id of `https://sp.example.org/shibboleth-sp` - other SPs would not see the SP-specific _eduPersonEntitlement_ attribute.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"simplesamlphp/composer-module-installer": "^1.1"
1515
},
1616
"require-dev": {
17-
"simplesamlphp/simplesamlphp": ">=1.15",
17+
"simplesamlphp/simplesamlphp": ">=1.17",
1818
"phpunit/phpunit": "~4.8"
1919
},
2020
"autoload-dev": {

lib/Auth/Process/AttributeFromSQL.php

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
<?php
22

3+
namespace SimpleSAML\Module\sqlattribs\Auth\Process;
4+
35
/**
46
* Filter to add attributes from a SQL data source
57
*
68
* This filter allows you to add attributes from a SQL datasource
79
*
810
* @author Guy Halse http://orcid.org/0000-0002-9388-8592
9-
* @copyright Copyright (c) 2016, SAFIRE - South African Identity Federation
11+
* @copyright Copyright (c) 2019, SAFIRE - South African Identity Federation
1012
* @license https://github.com/safire-ac-za/simplesamlphp-module-sqlattribs/blob/master/LICENSE MIT License
1113
* @package SimpleSAMLphp
1214
*/
13-
class sspmod_sqlattribs_Auth_Process_AttributeFromSQL extends SimpleSAML_Auth_ProcessingFilter
15+
class AttributeFromSQL extends \SimpleSAML\Auth\ProcessingFilter
1416
{
1517
/** @var string The DSN we should connect to. */
1618
private $dsn = 'mysql:host=localhost;dbname=simplesamlphp';
@@ -41,7 +43,7 @@ class sspmod_sqlattribs_Auth_Process_AttributeFromSQL extends SimpleSAML_Auth_Pr
4143
*
4244
* @param array $config Configuration information about this filter.
4345
* @param mixed $reserved For future use.
44-
* @throws SimpleSAML_Error_Exception
46+
* @throws \SimpleSAML\Error\Exception
4547
*/
4648
public function __construct($config, $reserved)
4749
{
@@ -52,7 +54,7 @@ public function __construct($config, $reserved)
5254
$this->attribute = $config['attribute'];
5355
}
5456
if (!is_string($this->attribute) || !$this->attribute) {
55-
throw new SimpleSAML_Error_Exception('AttributeFromSQL: attribute name not valid');
57+
throw new \SimpleSAML\Error\Exception('AttributeFromSQL: attribute name not valid');
5658
}
5759

5860
if (array_key_exists('database', $config)) {
@@ -70,10 +72,10 @@ public function __construct($config, $reserved)
7072
}
7173
}
7274
if (!is_string($this->dsn) || !$this->dsn) {
73-
throw new SimpleSAML_Error_Exception('AttributeFromSQL: invalid database DSN given');
75+
throw new \SimpleSAML\Error\Exception('AttributeFromSQL: invalid database DSN given');
7476
}
7577
if (!is_string($this->table) || !$this->table) {
76-
throw new SimpleSAML_Error_Exception('AttributeFromSQL: invalid database table');
78+
throw new \SimpleSAML\Error\Exception('AttributeFromSQL: invalid database table');
7779
}
7880

7981
if (array_key_exists('replace', $config)) {
@@ -82,7 +84,7 @@ public function __construct($config, $reserved)
8284

8385
if (array_key_exists('limit', $config)) {
8486
if (!is_array($config['limit'])) {
85-
throw new SimpleSAML_Error_Exception('AttributeFromSQL: limit must be an array of attribute names');
87+
throw new \SimpleSAML\Error\Exception('AttributeFromSQL: limit must be an array of attribute names');
8688
}
8789
$this->limit = $config['limit'];
8890
}
@@ -95,18 +97,18 @@ public function __construct($config, $reserved)
9597
/**
9698
* Create a database connection.
9799
*
98-
* @return PDO The database connection.
99-
* @throws SimpleSAML_Error_Exception
100+
* @return \PDO The database connection.
101+
* @throws \SimpleSAML\Error\Exception
100102
*/
101103
private function connect()
102104
{
103105
try {
104-
$db = new PDO($this->dsn, $this->username, $this->password);
105-
} catch (PDOException $e) {
106-
throw new SimpleSAML_Error_Exception('AttributeFromSQL: Failed to connect to \'' .
106+
$db = new \PDO($this->dsn, $this->username, $this->password);
107+
} catch (\PDOException $e) {
108+
throw new \SimpleSAML\Error\Exception('AttributeFromSQL: Failed to connect to \'' .
107109
$this->dsn . '\': ' . $e->getMessage());
108110
}
109-
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
111+
$db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
110112

111113
$driver = explode(':', $this->dsn, 2);
112114
$driver = strtolower($driver[0]);
@@ -129,7 +131,7 @@ private function connect()
129131
*
130132
* Logic is largely the same as (and lifted from) sqlauth:sql
131133
* @param mixed &$request
132-
* @throws SimpleSAML_Error_Exception
134+
* @throws \SimpleSAML\Error\Exception
133135
*/
134136
public function process(&$request)
135137
{
@@ -140,34 +142,34 @@ public function process(&$request)
140142
$attributes =& $request['Attributes'];
141143

142144
if (!array_key_exists($this->attribute, $attributes)) {
143-
SimpleSAML\Logger::info('AttributeFromSQL: attribute \'' . $this->attribute . '\' not set, declining');
145+
\SimpleSAML\Logger::info('AttributeFromSQL: attribute \'' . $this->attribute . '\' not set, declining');
144146
return;
145147
}
146148

147149
$db = $this->connect();
148150

149151
try {
150152
$sth = $db->prepare('SELECT `attribute`,`value` FROM ' . $this->table . ' WHERE `uid`=? AND (`sp`=\'%\' OR `sp`=?)' . ($this->ignoreExpiry ? '' : ' AND `expires`>CURRENT_DATE') . ';');
151-
} catch (PDOException $e) {
152-
throw new SimpleSAML_Error_Exception('AttributeFromSQL: prepare() failed: ' . $e->getMessage());
153+
} catch (\PDOException $e) {
154+
throw new \SimpleSAML\Error\Exception('AttributeFromSQL: prepare() failed: ' . $e->getMessage());
153155
}
154156

155157
try {
156-
$res = $sth->execute(array($attributes[$this->attribute][0], $request["Destination"]["entityid"]));
157-
} catch (PDOException $e) {
158-
throw new SimpleSAML_Error_Exception('AttributeFromSQL: execute(' . $attributes[$this->attribute][0] .
158+
$res = $sth->execute([$attributes[$this->attribute][0], $request["Destination"]["entityid"]]);
159+
} catch (\PDOException $e) {
160+
throw new \SimpleSAML\Error\Exception('AttributeFromSQL: execute(' . $attributes[$this->attribute][0] .
159161
', ' . $request["Destination"]["entityid"] . ') failed: ' . $e->getMessage());
160162
}
161163

162164
try {
163-
$data = $sth->fetchAll(PDO::FETCH_ASSOC);
165+
$data = $sth->fetchAll(\PDO::FETCH_ASSOC);
164166

165-
} catch (PDOException $e) {
166-
throw new SimpleSAML_Error_Exception('AttributeFromSQL: fetchAll() failed: ' . $e->getMessage());
167+
} catch (\PDOException $e) {
168+
throw new \SimpleSAML\Error\Exception('AttributeFromSQL: fetchAll() failed: ' . $e->getMessage());
167169
}
168170

169171
if (count($data) === 0) {
170-
SimpleSAML\Logger::info('AttributeFromSQL: no additional attributes for ' . $this->attribute . '=\'' . $attributes[$this->attribute][0] . '\'');
172+
\SimpleSAML\Logger::info('AttributeFromSQL: no additional attributes for ' . $this->attribute . '=\'' . $attributes[$this->attribute][0] . '\'');
171173
return;
172174
}
173175

@@ -177,7 +179,7 @@ public function process(&$request)
177179
*/
178180
foreach ($data as $row) {
179181
if (empty($row['attribute']) || $row['value'] === null) {
180-
SimpleSAML\Logger::debug('AttributeFromSQL: skipping invalid attribute/value tuple: ' . var_export($row, true));
182+
\SimpleSAML\Logger::debug('AttributeFromSQL: skipping invalid attribute/value tuple: ' . var_export($row, true));
181183
continue;
182184
}
183185

@@ -186,17 +188,17 @@ public function process(&$request)
186188

187189
/* Limit the attribute set returned */
188190
if ($this->limit !== null && !in_array($name, $this->limit, true)) {
189-
SimpleSAML\Logger::notice('AttributeFromSQL: skipping unwanted attribute ' . $name . ' [limited to: ' . var_export($this->limit, true) . ']');
191+
\SimpleSAML\Logger::notice('AttributeFromSQL: skipping unwanted attribute ' . $name . ' [limited to: ' . var_export($this->limit, true) . ']');
190192
continue;
191193
}
192194

193195
if (!array_key_exists($name, $attributes) || $this->replace === true) {
194-
$attributes[$name] = array();
196+
$attributes[$name] = [];
195197
}
196198

197199
if (in_array($value, $attributes[$name], true)) {
198200
/* Value already exists in attribute. */
199-
SimpleSAML\Logger::debug('AttributeFromSQL: skipping duplicate attribute/value tuple ' . $name . '=\'' . $value . '\'');
201+
\SimpleSAML\Logger::debug('AttributeFromSQL: skipping duplicate attribute/value tuple ' . $name . '=\'' . $value . '\'');
200202
continue;
201203
}
202204

tests/_autoload_modules.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
<?php
2-
3-
/**
4-
* This file implements a trimmed down version of the SSP module aware autoloader that can be used in tests.
5-
*
6-
* @author Patrick Radtke
7-
*/
8-
92
/**
10-
* Autoload function for local SimpleSAMLphp modules.
3+
* This file implements a trimmed down version of the SSP module aware autoloader that can be used in tests..
114
*
125
* @param string $className Name of the class.
136
*/
@@ -20,14 +13,13 @@ function SimpleSAML_test_module_autoload($className)
2013
}
2114

2215
$modNameEnd = strpos($className, '_', $modulePrefixLength);
23-
$moduleClass = substr($className, $modNameEnd + 1);
16+
$module = substr($className, $modulePrefixLength, $modNameEnd - $modulePrefixLength);
17+
$path = explode('_', substr($className, $modNameEnd + 1));
18+
$file = dirname(dirname(__FILE__)).'/lib/'.join('/', $path).'.php';
2419

25-
$file = dirname(dirname(__FILE__)) . '/lib/' . str_replace('_', '/', $moduleClass) . '.php';
26-
27-
if (file_exists($file)) {
28-
require_once($file);
20+
if (!file_exists($file)) {
21+
return;
2922
}
23+
require_once($file);
3024
}
31-
3225
spl_autoload_register('SimpleSAML_test_module_autoload');
33-

0 commit comments

Comments
 (0)