1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SimpleSAML\Module\monitor\TestCase\AuthSource\Ldap; |
4
|
|
|
|
5
|
|
|
use \SimpleSAML\Module\monitor\State as State; |
6
|
|
|
use \SimpleSAML\Module\monitor\TestData as TestData; |
7
|
|
|
use \SimpleSAML\Module\monitor\TestResult as TestResult; |
8
|
|
|
|
9
|
|
|
final class Bind extends \SimpleSAML\Module\monitor\TestCaseFactory |
10
|
|
|
{ |
11
|
|
|
/* |
12
|
|
|
* @var \SimpleSAML_Auth_LDAP|null |
13
|
|
|
*/ |
14
|
|
|
private $connection = null; |
15
|
|
|
|
16
|
|
|
/* |
17
|
|
|
* @var string|null |
18
|
|
|
*/ |
19
|
|
|
private $username = null; |
20
|
|
|
|
21
|
|
|
/* |
22
|
|
|
* @var string|null |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
private $password = null; |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
/* |
29
|
|
|
* @param TestData $testData |
30
|
|
|
* |
31
|
|
|
* @return void |
32
|
|
|
*/ |
33
|
|
|
protected function initialize($testData) |
34
|
|
|
{ |
35
|
|
|
$this->connection = $testData->getInput('connection'); |
36
|
|
|
$authSourceData = $testData->getInput('authSourceData'); |
37
|
|
|
|
38
|
|
|
$this->username = $authSourceData['search.username']; |
39
|
|
|
$this->password = $authSourceData['search.password']; |
40
|
|
|
|
41
|
|
|
parent::initialize($testData); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/* |
46
|
|
|
* @return void |
47
|
|
|
*/ |
48
|
|
|
protected function invokeTest() |
49
|
|
|
{ |
50
|
|
|
$testResult = new TestResult('LDAP Bind', $this->username); |
51
|
|
|
$connection = $this->connection; |
52
|
|
|
|
53
|
|
|
try { |
54
|
|
|
$bind = $connection->bind($this->username, $this->password); |
55
|
|
|
} catch (\Exception $e) { |
56
|
|
|
// Fallthru |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if (isSet($error)) { |
|
|
|
|
60
|
|
|
$msg = str_replace('Library - LDAP bind(): ', '', $error->getMessage()); |
61
|
|
|
$state = State::FATAL; |
62
|
|
|
} elseif ($bind === true) { |
63
|
|
|
$msg = 'Bind succesful'; |
64
|
|
|
$state = State::OK; |
65
|
|
|
} else { |
66
|
|
|
$msg = ldap_error($connection).' ('.ldap_errno($connection).')'; |
67
|
|
|
$state = State::ERROR; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$testResult->setMessage($msg); |
71
|
|
|
$testResult->setState($state); |
72
|
|
|
|
73
|
|
|
$this->setTestResult($testResult); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
This check looks for calls to
isset(...)
orempty()
on variables that are yet undefined. These calls will always produce the same result and can be removed.This is most likely caused by the renaming of a variable or the removal of a function/method parameter.