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\TestSuite as TestSuite; |
8
|
|
|
|
9
|
|
|
final class Negotiate extends \SimpleSAML\Module\monitor\TestCaseFactory |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var bool |
13
|
|
|
*/ |
14
|
|
|
private $xml = false; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var string|null |
18
|
|
|
*/ |
19
|
|
|
private $keytab = null; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var array |
23
|
|
|
*/ |
24
|
|
|
private $headers = array(); |
25
|
|
|
|
26
|
|
|
/* |
27
|
|
|
* @param TestData $testData |
28
|
|
|
* |
29
|
|
|
* @return void |
30
|
|
|
*/ |
31
|
|
|
protected function initialize($testData) |
32
|
|
|
{ |
33
|
|
|
$this->keytab = $testData->getInput('keytab'); |
34
|
|
|
|
35
|
|
|
$query = \SimpleSAML\Utils\HTTP::getSelfURL(); |
36
|
|
|
parse_str($query, $query); |
37
|
|
|
|
38
|
|
|
$this->xml = isSet($query['xml']) && ((bool)$query['xml'] === true); |
39
|
|
|
$this->headers = apache_request_headers(); |
40
|
|
|
|
41
|
|
|
parent::initialize($testData); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/* |
45
|
|
|
* @return void |
46
|
|
|
*/ |
47
|
|
|
protected function invokeTest() |
48
|
|
|
{ |
49
|
|
|
if ($this->xml === false) { |
50
|
|
|
$auth = new \KRB5NegotiateAuth($this->keytab); |
51
|
|
|
try { |
52
|
|
|
$reply = @$auth->doAuthentication(); |
53
|
|
|
} catch (\Exception $e) { |
54
|
|
|
// Fallthru |
55
|
|
|
$this->setState(State::WARNING); |
56
|
|
|
$this->addMessage(State::WARNING, 'Authentication', 'Kerberos token validation', $e->getMessage()); |
57
|
|
|
return; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
if (!isSet($this->headers['Authorization']) || empty($this->headers['Authorization'])) { |
61
|
|
|
$this->setState(State::SKIPPED); |
62
|
|
|
$this->addMessage(State::SKIPPED, 'Authentication', 'Kerberos token validation', 'Unable to authenticate; no token provided'); |
63
|
|
|
} else if ($reply) { |
64
|
|
|
$this->setState(State::OK); |
65
|
|
|
$this->addMessage(State::OK, 'Authentication', 'Kerberos token validation', 'Succesfully authenticated as ' . $auth->getAuthenticatedUser()); |
66
|
|
|
} else { |
67
|
|
|
$this->setState(State::WARNING); |
68
|
|
|
$this->addMessage(State::WARNING, 'Authentication', 'Kerberos token validation', "Something went wrong"); |
69
|
|
|
} |
70
|
|
|
} else { |
71
|
|
|
$this->setState(State::SKIPPED); |
72
|
|
|
$this->addMessage(State::SKIPPED, 'Authentication', 'Kerberos token validation', 'Unable to authenticate'); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
if (!function_exists('apache_request_headers')) { |
78
|
|
|
function apache_request_headers() |
|
|
|
|
79
|
|
|
{ |
80
|
|
|
$arh = array(); |
81
|
|
|
$rx_http = '/\AHTTP_/'; |
|
|
|
|
82
|
|
|
foreach ($_SERVER as $key => $val) { |
83
|
|
|
if (preg_match($rx_http, $key)) { |
|
|
|
|
84
|
|
|
$arh_key = preg_replace($rx_http, '', $key); |
|
|
|
|
85
|
|
|
$rx_matches = array(); |
|
|
|
|
86
|
|
|
// do some nasty string manipulations to restore the original letter case |
87
|
|
|
// this should work in most cases |
88
|
|
|
$rx_matches = explode('_', $arh_key); |
|
|
|
|
89
|
|
|
if ((count($rx_matches) > 0) && (strlen($arh_key) > 2)) { |
|
|
|
|
90
|
|
|
foreach ($rx_matches as $ak_key => $ak_val) { |
|
|
|
|
91
|
|
|
$rx_matches[$ak_key] = ucfirst($ak_val); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
$arh_key = implode('-', $rx_matches); |
|
|
|
|
94
|
|
|
} |
95
|
|
|
$arh[$arh_key] = $val; |
|
|
|
|
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
return $arh; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.