1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SimpleSAML\Module\monitor\TestSuite; |
4
|
|
|
|
5
|
|
|
use \SimpleSAML_Configuration as ApplicationConfiguration; |
6
|
|
|
use \SimpleSAML\Module\monitor\TestConfiguration as TestConfiguration; |
7
|
|
|
use \SimpleSAML\Module\monitor\TestData as TestData; |
8
|
|
|
|
9
|
|
|
final class AuthSources extends \SimpleSAML\Module\monitor\TestSuiteFactory |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var array|bool |
13
|
|
|
*/ |
14
|
|
|
private $checkAuthSources = true; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var ApplicationConfiguration |
18
|
|
|
*/ |
19
|
|
|
private $authSourceConfig; |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param TestConfiguration $configuration |
24
|
|
|
*/ |
25
|
|
|
public function __construct($configuration) |
26
|
|
|
{ |
27
|
|
|
$moduleConfig = $configuration->getModuleConfig(); |
28
|
|
|
|
29
|
|
|
$this->authSourceConfig = $configuration->getAuthSourceConfig(); |
30
|
|
|
$this->checkAuthSources = $moduleConfig->getValue('checkAuthSources', true); |
31
|
|
|
|
32
|
|
|
parent::__construct($configuration); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return void |
38
|
|
|
*/ |
39
|
|
|
protected function invokeTestSuite() |
40
|
|
|
{ |
41
|
|
|
if ($this->checkAuthSources === true) { |
42
|
|
|
$authSources = $this->authSourceConfig->getOptions(); |
43
|
|
|
} else if (is_array($this->checkAuthSources)) { |
44
|
|
|
$authSources = array_intersect($this->authSourceConfig->getOptions(), $this->checkAuthSources); |
45
|
|
|
} else { // false or invalid value |
46
|
|
|
return; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$configuration = $this->getConfiguration(); |
50
|
|
|
foreach ($authSources as $authSourceId) { |
51
|
|
|
$authSourceData = $this->authSourceConfig->getValue($authSourceId); |
52
|
|
|
$input = array( |
53
|
|
|
'authSourceId' => $authSourceId, |
54
|
|
|
'authSourceData' => $authSourceData |
55
|
|
|
); |
56
|
|
|
$testData = new TestData($input); |
57
|
|
|
|
58
|
|
|
switch ($authSourceData[0]) { |
59
|
|
|
case 'ldap:LDAP': |
60
|
|
|
$test = new AuthSource\Ldap($configuration, $testData); |
61
|
|
|
$testResult = $test->getTestResult(); |
|
|
|
|
62
|
|
|
$this->addTestResult($test->getTestResult()); |
63
|
|
|
//$this->addMessages($test->getMessages(), $authSourceId); |
|
|
|
|
64
|
|
|
break; |
65
|
|
|
case 'negotiate:Negotiate': |
66
|
|
|
$test = new AuthSource\Negotiate($configuration, $testData); |
67
|
|
|
$testResult = $test->getTestResult(); |
|
|
|
|
68
|
|
|
$this->addTestResult($test->getTestResult()); |
69
|
|
|
//$this->addMessages($test->getMessages(), $authSourceId); |
|
|
|
|
70
|
|
|
|
71
|
|
|
// We need to do some convertions from Negotiate > LDAP |
72
|
|
|
$this->convertAuthSourceData($authSourceData); |
73
|
|
|
$testData->setInput($authSourceData, 'authSourceData'); |
74
|
|
|
|
75
|
|
|
$ldapTest = new AuthSource\Ldap($configuration, $testData); |
|
|
|
|
76
|
|
|
$testResult = $test->getTestResult(); |
|
|
|
|
77
|
|
|
$this->addTestResult($test->getTestResult()); |
78
|
|
|
//$this->addMessages($ldapTest->getMessages(), $authSourceId); |
|
|
|
|
79
|
|
|
break; |
80
|
|
|
case 'multiauth:MultiAuth': |
81
|
|
|
// Relies on other authSources |
82
|
|
|
continue 2; |
83
|
|
|
default: |
84
|
|
|
// Not implemented |
85
|
|
|
continue 2; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$this->calculateState(); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param array $authSourceData |
95
|
|
|
* |
96
|
|
|
* @return void |
97
|
|
|
*/ |
98
|
|
|
private function convertAuthSourceData(&$authSourceData) |
99
|
|
|
{ |
100
|
|
|
// LDAP and Negotiate authSources use different names for equal properties |
101
|
|
|
// Hopefully this function can go away in SSP 2.0 |
102
|
|
|
if (isSet($authSourceData['debugLDAP'])) { |
103
|
|
|
$authSourceData['debug'] = $authSourceData['debugLDAP']; |
104
|
|
|
unset($authSourceData['debugLDAP']); |
105
|
|
|
} |
106
|
|
|
if (isSet($authSourceData['adminUser'])) { |
107
|
|
|
$authSourceData['search.username'] = $authSourceData['adminUser']; |
108
|
|
|
unset($authSourceData['adminUser']); |
109
|
|
|
} |
110
|
|
|
if (isSet($authSourceData['adminPassword'])) { |
111
|
|
|
$authSourceData['search.password'] = $authSourceData['adminPassword']; |
112
|
|
|
unset($authSourceData['adminPassword']); |
113
|
|
|
} |
114
|
|
|
if (isSet($authSourceData['base'])) { |
115
|
|
|
$authSourceData['search.base'] = $authSourceData['base']; |
116
|
|
|
unset($authSourceData['base']); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.