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