1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SimpleSAML\Module\Monitor\TestCase\AuthSource; |
4
|
|
|
|
5
|
|
|
use SimpleSAML\Module\Monitor\State; |
6
|
|
|
use SimpleSAML\Module\Monitor\TestData; |
7
|
|
|
use SimpleSAML\Module\Monitor\TestResult; |
8
|
|
|
|
9
|
|
|
final class Negotiate extends \SimpleSAML\Module\Monitor\TestCaseFactory |
10
|
|
|
{ |
11
|
|
|
/** @var \KRB5NegotiateAuth */ |
12
|
|
|
private $handle; |
13
|
|
|
|
14
|
|
|
/** @var string|null */ |
15
|
|
|
private $authorization; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
/* |
19
|
|
|
* @param \SimpleSAML\Module\Monitor\TestData $testData |
20
|
|
|
* |
21
|
|
|
* @return void |
22
|
|
|
*/ |
23
|
|
|
protected function initialize(TestData $testData): void |
24
|
|
|
{ |
25
|
|
|
$this->handle = $testData->getInputItem('handle'); |
26
|
|
|
|
27
|
|
|
$authorization = $testData->getInputItem('authorization'); |
28
|
|
|
$this->authorization = (is_null($authorization) || empty($authorization)) ? null : $authorization; |
29
|
|
|
|
30
|
|
|
parent::initialize($testData); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
/* |
35
|
|
|
* @return void |
36
|
|
|
*/ |
37
|
|
|
public function invokeTest(): void |
38
|
|
|
{ |
39
|
|
|
$testResult = new TestResult('Authentication', 'Kerberos token validation'); |
40
|
|
|
|
41
|
|
|
try { |
42
|
|
|
$reply = @$this->handle->doAuthentication(); |
43
|
|
|
} catch (\Exception $error) { |
44
|
|
|
// Fallthru |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
if (isset($error)) { |
48
|
|
|
$testResult->setState(State::WARNING); |
49
|
|
|
$testResult->setMessage($error->getMessage()); |
50
|
|
|
} elseif ($reply === true) { |
51
|
|
|
$testResult->setState(State::OK); |
52
|
|
|
$testResult->setMessage('Succesfully authenticated as ' . $this->handle->getAuthenticatedUser()); |
53
|
|
|
} elseif (is_null($this->authorization)) { |
54
|
|
|
// Either misconfiguration of the browser, or user not authenticated at a KDC |
55
|
|
|
$testResult->setState(State::SKIPPED); |
56
|
|
|
$testResult->setMessage('Unable to authenticate; no token provided'); |
57
|
|
|
} else { // $reply === false |
58
|
|
|
$testResult->setState(State::WARNING); |
59
|
|
|
$testResult->setMessage("Something went wrong and we couldn't tell why"); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$this->setTestResult($testResult); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|