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 |
13
|
|
|
*/ |
14
|
|
|
private $connection; |
15
|
|
|
|
16
|
|
|
/* |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
private $username; |
20
|
|
|
|
21
|
|
|
/* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
private $password; |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
/* |
29
|
|
|
* @param TestData $testData |
30
|
|
|
* |
31
|
|
|
* @return void |
32
|
|
|
*/ |
33
|
|
|
protected function initialize($testData) |
34
|
|
|
{ |
35
|
|
|
$this->connection = $testData->getInputItem('connection'); |
36
|
|
|
$authSourceData = $testData->getInputItem('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
|
|
|
public function invokeTest() |
49
|
|
|
{ |
50
|
|
|
try { |
51
|
|
|
$bind = $this->connection->bind($this->username, $this->password); |
52
|
|
|
} catch (\Exception $error) { |
53
|
|
|
// Fallthru |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$testResult = new TestResult('LDAP Bind', $this->username); |
57
|
|
|
if (isSet($error)) { |
58
|
|
|
$msg = str_replace('Library - LDAP bind(): ', '', $error->getMessage()); |
59
|
|
|
$testResult->setState(State::FATAL); |
60
|
|
|
} elseif ($bind === true) { |
61
|
|
|
$msg = 'Bind succesful'; |
62
|
|
|
$testResult->setState(State::OK); |
63
|
|
|
} else { |
64
|
|
|
$msg = 'Authentication failed'; |
65
|
|
|
$testResult->setState(State::ERROR); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$testResult->setMessage($msg); |
69
|
|
|
$this->setTestResult($testResult); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|