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