ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
sspmod_ldap_ConfigHelper Class Reference
+ Collaboration diagram for sspmod_ldap_ConfigHelper:

Public Member Functions

 __construct ($config, $location)
 Constructor for this configuration parser. More...
 
 login ($username, $password, array $sasl_args=null)
 Attempt to log in using the given username and password. More...
 
 searchfordn ($attribute, $value, $allowZeroHits)
 Search for a DN. More...
 
 getAttributes ($dn, $attributes=null)
 

Private Attributes

 $location
 String with the location of this configuration. More...
 
 $hostname
 The hostname of the LDAP server. More...
 
 $enableTLS
 Whether we should use TLS/SSL when contacting the LDAP server. More...
 
 $debug
 
 $timeout
 
 $port
 
 $referrals
 Whether to follow referrals. More...
 
 $searchEnable
 Whether we need to search for the users DN. More...
 
 $searchUsername
 The username we should bind with before we can search for the user. More...
 
 $searchPassword
 The password we should bind with before we can search for the user. More...
 
 $searchBase
 Array with the base DN(s) for the search. More...
 
 $searchFilter
 Additional LDAP filter fields for the search. More...
 
 $searchAttributes
 The attributes which should match the username. More...
 
 $dnPattern
 The DN pattern we should use to create the DN from the username. More...
 
 $attributes
 The attributes we should fetch. More...
 
 $privRead
 The user cannot get all attributes, privileged reader required. More...
 
 $privUsername
 The DN we should bind with before we can get the attributes. More...
 
 $privPassword
 The password we should bind with before we can get the attributes. More...
 

Detailed Description

Definition at line 11 of file ConfigHelper.php.

Constructor & Destructor Documentation

◆ __construct()

sspmod_ldap_ConfigHelper::__construct (   $config,
  $location 
)

Constructor for this configuration parser.

Parameters
array$configConfiguration.
string$locationThe location of this configuration. Used for error reporting.

Definition at line 130 of file ConfigHelper.php.

131 {
132 assert('is_array($config)');
133 assert('is_string($location)');
134
135 $this->location = $location;
136
137 // Parse configuration
139
140 $this->hostname = $config->getString('hostname');
141 $this->enableTLS = $config->getBoolean('enable_tls', false);
142 $this->debug = $config->getBoolean('debug', false);
143 $this->timeout = $config->getInteger('timeout', 0);
144 $this->port = $config->getInteger('port', 389);
145 $this->referrals = $config->getBoolean('referrals', true);
146 $this->searchEnable = $config->getBoolean('search.enable', false);
147 $this->privRead = $config->getBoolean('priv.read', false);
148
149 if ($this->searchEnable) {
150 $this->searchUsername = $config->getString('search.username', null);
151 if ($this->searchUsername !== null) {
152 $this->searchPassword = $config->getString('search.password');
153 }
154
155 $this->searchBase = $config->getArrayizeString('search.base');
156 $this->searchFilter = $config->getString('search.filter', null);
157 $this->searchAttributes = $config->getArray('search.attributes');
158
159 } else {
160 $this->dnPattern = $config->getString('dnpattern');
161 }
162
163 // Are privs needed to get to the attributes?
164 if ($this->privRead) {
165 $this->privUsername = $config->getString('priv.username');
166 $this->privPassword = $config->getString('priv.password');
167 }
168
169 $this->attributes = $config->getArray('attributes', null);
170 }
static loadFromArray($config, $location='[ARRAY]', $instance=null)
Loads a configuration from the given array.
$location
String with the location of this configuration.

References $config, $location, and SimpleSAML_Configuration\loadFromArray().

+ Here is the call graph for this function:

Member Function Documentation

◆ getAttributes()

sspmod_ldap_ConfigHelper::getAttributes (   $dn,
  $attributes = null 
)

Definition at line 281 of file ConfigHelper.php.

282 {
283 if ($attributes == null) {
285 }
286
287 $ldap = new SimpleSAML_Auth_LDAP($this->hostname,
288 $this->enableTLS,
289 $this->debug,
290 $this->timeout,
291 $this->port,
292 $this->referrals);
293
294 /* Are privs needed to get the attributes? */
295 if ($this->privRead) {
296 /* Yes, rebind with privs */
297 if (!$ldap->bind($this->privUsername, $this->privPassword)) {
298 throw new Exception('Error authenticating using privileged DN & password.');
299 }
300 }
301 return $ldap->getAttributes($dn, $attributes);
302 }
$attributes
The attributes we should fetch.

References $attributes.

◆ login()

sspmod_ldap_ConfigHelper::login (   $username,
  $password,
array  $sasl_args = null 
)

Attempt to log in using the given username and password.

Will throw a SimpleSAML_Error_Error('WRONGUSERPASS') if the username or password is wrong. If there is a configuration problem, an Exception will be thrown.

Parameters
string$usernameThe username the user wrote.
string$passwordThe password the user wrote.
arrray$sasl_argsArray of SASL options for LDAP bind.
Returns
array Associative array with the users attributes.

Definition at line 184 of file ConfigHelper.php.

185 {
186 assert('is_string($username)');
187 assert('is_string($password)');
188
189 if (empty($password)) {
190 SimpleSAML\Logger::info($this->location . ': Login with empty password disallowed.');
191 throw new SimpleSAML_Error_Error('WRONGUSERPASS');
192 }
193
194 $ldap = new SimpleSAML_Auth_LDAP($this->hostname, $this->enableTLS, $this->debug, $this->timeout, $this->port, $this->referrals);
195
196 if (!$this->searchEnable) {
197 $ldapusername = addcslashes($username, ',+"\\<>;*');
198 $dn = str_replace('%username%', $ldapusername, $this->dnPattern);
199 } else {
200 if ($this->searchUsername !== null) {
201 if (!$ldap->bind($this->searchUsername, $this->searchPassword)) {
202 throw new Exception('Error authenticating using search username & password.');
203 }
204 }
205
206 $dn = $ldap->searchfordn($this->searchBase, $this->searchAttributes, $username, true, $this->searchFilter);
207 if ($dn === null) {
208 /* User not found with search. */
209 SimpleSAML\Logger::info($this->location . ': Unable to find users DN. username=\'' . $username . '\'');
210 throw new SimpleSAML_Error_Error('WRONGUSERPASS');
211 }
212 }
213
214 if (!$ldap->bind($dn, $password, $sasl_args)) {
215 SimpleSAML\Logger::info($this->location . ': '. $username . ' failed to authenticate. DN=' . $dn);
216 throw new SimpleSAML_Error_Error('WRONGUSERPASS');
217 }
218
219 /* In case of SASL bind, authenticated and authorized DN may differ */
220 if (isset($sasl_args)) {
221 $dn = $ldap->whoami($this->searchBase, $this->searchAttributes);
222 }
223
224 /* Are privs needed to get the attributes? */
225 if ($this->privRead) {
226 /* Yes, rebind with privs */
227 if (!$ldap->bind($this->privUsername, $this->privPassword)) {
228 throw new Exception('Error authenticating using privileged DN & password.');
229 }
230 }
231
232 return $ldap->getAttributes($dn, $this->attributes);
233 }
static info($string)
Definition: Logger.php:201
$password
Definition: pwgen.php:17

References $password, and SimpleSAML\Logger\info().

+ Here is the call graph for this function:

◆ searchfordn()

sspmod_ldap_ConfigHelper::searchfordn (   $attribute,
  $value,
  $allowZeroHits 
)

Search for a DN.

Parameters
string | array$attributeThe attribute name(s) searched for. If set to NULL, values from configuration is used.
string$valueThe attribute value searched for.
bool$allowZeroHitsDetermines if the method will throw an exception if no hits are found. Defaults to FALSE.
Returns
string The DN of the matching element, if found. If no element was found and $allowZeroHits is set to FALSE, an exception will be thrown; otherwise NULL will be returned.
Exceptions
SimpleSAML_Error_AuthSourceif:
  • LDAP search encounter some problems when searching cataloge
  • Not able to connect to LDAP server
SimpleSAML_Error_UserNotFoundif:
  • $allowZeroHits is FALSE and no result is found

Definition at line 258 of file ConfigHelper.php.

259 {
260 $ldap = new SimpleSAML_Auth_LDAP($this->hostname,
261 $this->enableTLS,
262 $this->debug,
263 $this->timeout,
264 $this->port,
265 $this->referrals);
266
267 if ($attribute == null) {
268 $attribute = $this->searchAttributes;
269 }
270
271 if ($this->searchUsername !== null) {
272 if (!$ldap->bind($this->searchUsername, $this->searchPassword)) {
273 throw new Exception('Error authenticating using search username & password.');
274 }
275 }
276
277 return $ldap->searchfordn($this->searchBase, $attribute,
278 $value, $allowZeroHits, $this->searchFilter);
279 }
$searchAttributes
The attributes which should match the username.

References $searchAttributes.

Field Documentation

◆ $attributes

sspmod_ldap_ConfigHelper::$attributes
private

The attributes we should fetch.

Can be NULL in which case we will fetch all attributes.

Definition at line 103 of file ConfigHelper.php.

Referenced by getAttributes().

◆ $debug

sspmod_ldap_ConfigHelper::$debug
private

Definition at line 37 of file ConfigHelper.php.

◆ $dnPattern

sspmod_ldap_ConfigHelper::$dnPattern
private

The DN pattern we should use to create the DN from the username.

Definition at line 97 of file ConfigHelper.php.

◆ $enableTLS

sspmod_ldap_ConfigHelper::$enableTLS
private

Whether we should use TLS/SSL when contacting the LDAP server.

Definition at line 29 of file ConfigHelper.php.

◆ $hostname

sspmod_ldap_ConfigHelper::$hostname
private

The hostname of the LDAP server.

Definition at line 23 of file ConfigHelper.php.

◆ $location

sspmod_ldap_ConfigHelper::$location
private

String with the location of this configuration.

Used for error reporting.

Definition at line 17 of file ConfigHelper.php.

Referenced by __construct().

◆ $port

sspmod_ldap_ConfigHelper::$port
private

Definition at line 52 of file ConfigHelper.php.

◆ $privPassword

sspmod_ldap_ConfigHelper::$privPassword
private

The password we should bind with before we can get the attributes.

Definition at line 121 of file ConfigHelper.php.

◆ $privRead

sspmod_ldap_ConfigHelper::$privRead
private

The user cannot get all attributes, privileged reader required.

Definition at line 109 of file ConfigHelper.php.

◆ $privUsername

sspmod_ldap_ConfigHelper::$privUsername
private

The DN we should bind with before we can get the attributes.

Definition at line 115 of file ConfigHelper.php.

◆ $referrals

sspmod_ldap_ConfigHelper::$referrals
private

Whether to follow referrals.

Definition at line 57 of file ConfigHelper.php.

◆ $searchAttributes

sspmod_ldap_ConfigHelper::$searchAttributes
private

The attributes which should match the username.

Definition at line 91 of file ConfigHelper.php.

Referenced by searchfordn().

◆ $searchBase

sspmod_ldap_ConfigHelper::$searchBase
private

Array with the base DN(s) for the search.

Definition at line 81 of file ConfigHelper.php.

◆ $searchEnable

sspmod_ldap_ConfigHelper::$searchEnable
private

Whether we need to search for the users DN.

Definition at line 63 of file ConfigHelper.php.

◆ $searchFilter

sspmod_ldap_ConfigHelper::$searchFilter
private

Additional LDAP filter fields for the search.

Definition at line 86 of file ConfigHelper.php.

◆ $searchPassword

sspmod_ldap_ConfigHelper::$searchPassword
private

The password we should bind with before we can search for the user.

Definition at line 75 of file ConfigHelper.php.

◆ $searchUsername

sspmod_ldap_ConfigHelper::$searchUsername
private

The username we should bind with before we can search for the user.

Definition at line 69 of file ConfigHelper.php.

◆ $timeout

sspmod_ldap_ConfigHelper::$timeout
private

Definition at line 45 of file ConfigHelper.php.


The documentation for this class was generated from the following file: