Skip to content

Commit 3bb3a0b

Browse files
committed
PSR-12 + deprecation cleanup
1 parent 51f2833 commit 3bb3a0b

11 files changed

Lines changed: 235 additions & 298 deletions

File tree

lib/Auth/LDAP.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

lib/Auth/Ldap.php

Lines changed: 81 additions & 73 deletions
Large diffs are not rendered by default.

lib/Auth/Process/AttributeAddFromLDAP.php

Lines changed: 15 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
<?php
22

3-
namespace SimpleSAML\Module\ldap\Auth\Process;
4-
5-
use SimpleSAML\Module\ldap\Auth\Ldap;
6-
7-
use Webmozart\Assert\Assert;
8-
93
/**
104
* Filter to add attributes to the identity by executing a query against an LDAP directory
115
*
@@ -38,6 +32,13 @@
3832
* @author Remy Blom <remy.blom@hku.nl>
3933
* @package SimpleSAMLphp
4034
*/
35+
36+
namespace SimpleSAML\Module\ldap\Auth\Process;
37+
38+
use SimpleSAML\Logger;
39+
use SimpleSAML\Module\ldap\Auth\Ldap;
40+
use Webmozart\Assert\Assert;
41+
4142
class AttributeAddFromLDAP extends BaseFilter
4243
{
4344
/**
@@ -72,55 +73,6 @@ class AttributeAddFromLDAP extends BaseFilter
7273
*/
7374
public function __construct($config, $reserved)
7475
{
75-
/*
76-
* For backwards compatibility, check for old config names
77-
* @TODO Remove after 2.0
78-
*/
79-
if (isset($config['ldap_host'])) {
80-
$config['ldap.hostname'] = $config['ldap_host'];
81-
}
82-
if (isset($config['ldap_port'])) {
83-
$config['ldap.port'] = $config['ldap_port'];
84-
}
85-
if (isset($config['ldap_bind_user'])) {
86-
$config['ldap.username'] = $config['ldap_bind_user'];
87-
}
88-
if (isset($config['ldap_bind_pwd'])) {
89-
$config['ldap.password'] = $config['ldap_bind_pwd'];
90-
}
91-
if (isset($config['userid_attribute'])) {
92-
$config['attribute.username'] = $config['userid_attribute'];
93-
}
94-
if (isset($config['ldap_search_base_dn'])) {
95-
$config['ldap.basedn'] = $config['ldap_search_base_dn'];
96-
}
97-
if (isset($config['ldap_search_filter'])) {
98-
$config['search.filter'] = $config['ldap_search_filter'];
99-
}
100-
if (isset($config['ldap_search_attribute'])) {
101-
$config['search.attribute'] = $config['ldap_search_attribute'];
102-
}
103-
if (isset($config['new_attribute_name'])) {
104-
$config['attribute.new'] = $config['new_attribute_name'];
105-
}
106-
107-
/*
108-
* Remove the old config names
109-
* @TODO Remove after 2.0
110-
*/
111-
unset(
112-
$config['ldap_host'],
113-
$config['ldap_port'],
114-
$config['ldap_bind_user'],
115-
$config['ldap_bind_pwd'],
116-
$config['userid_attribute'],
117-
$config['ldap_search_base_dn'],
118-
$config['ldap_search_filter'],
119-
$config['ldap_search_attribute'],
120-
$config['new_attribute_name']
121-
);
122-
123-
// Now that we checked for BC, run the parent constructor
12476
parent::__construct($config, $reserved);
12577

12678
// Get filter specific config options
@@ -154,10 +106,10 @@ public function process(&$request)
154106
$arrSearch = [];
155107
$arrReplace = [];
156108
foreach ($attributes as $attr => $val) {
157-
$arrSearch[] = '%'.$attr.'%';
109+
$arrSearch[] = '%' . $attr . '%';
158110

159111
if (strlen($val[0]) > 0) {
160-
$arrReplace[] = Ldap::escape_filter_value($val[0]);
112+
$arrReplace[] = Ldap::escapeFilterValue($val[0]);
161113
} else {
162114
$arrReplace[] = '';
163115
}
@@ -167,13 +119,15 @@ public function process(&$request)
167119
$filter = str_replace($arrSearch, $arrReplace, $this->search_filter);
168120

169121
if (strpos($filter, '%') !== false) {
170-
\SimpleSAML\Logger::info('AttributeAddFromLDAP: There are non-existing attributes in the search filter. ('.
171-
$this->search_filter.')');
122+
Logger::info(
123+
'AttributeAddFromLDAP: There are non-existing attributes in the search filter. (' .
124+
$this->search_filter . ')'
125+
);
172126
return;
173127
}
174128

175129
if (!in_array($this->attr_policy, ['merge', 'replace', 'add'], true)) {
176-
\SimpleSAML\Logger::warning("AttributeAddFromLDAP: 'attribute.policy' must be one of 'merge',".
130+
Logger::warning("AttributeAddFromLDAP: 'attribute.policy' must be one of 'merge'," .
177131
"'replace' or 'add'.");
178132
return;
179133
}
@@ -183,7 +137,7 @@ public function process(&$request)
183137
$ldap = $this->getLdap();
184138
} catch (\Exception $e) {
185139
// Added this warning in case $this->getLdap() fails
186-
\SimpleSAML\Logger::warning("AttributeAddFromLDAP: exception = ".$e);
140+
Logger::warning("AttributeAddFromLDAP: exception = " . $e);
187141
return;
188142
}
189143
// search for matching entries

0 commit comments

Comments
 (0)