Passed
Push — master ( 4541b1...3f3f73 )
by Tim
01:48
created

Negotiate   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 8 3
B invokeTest() 0 26 5
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 KRB5NegotiateAuth
13
     */
14
    private $handle;
15
16
    /**
17
     * @var string|null
18
     */
19
    private $authorization;
20
21
    /*
22
     * @param TestData $testData
23
     *
24
     * @return void
25
     */
26
    protected function initialize($testData)
27
    {
28
        $this->handle = $testData->getInputItem('handle');
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
        try {
44
            $reply = @$this->handle->doAuthentication();
45
        } catch (\Exception $error) {
46
            // Fallthru
47
        }
48
49
        if (isSet($error)) {
50
            $testResult->setState(State::WARNING);
51
            $testResult->setMessage($error->getMessage());
52
        } else if ($reply === true) {
53
            $testResult->setState(State::OK);
54
            $testResult->setMessage('Succesfully authenticated as '.$this->handle->getAuthenticatedUser());
55
        } else if (is_null($this->authorization)) {
56
            // Either misconfiguration of the browser, or user not authenticated at a KDC
57
            $testResult->setState(State::SKIPPED);
58
            $testResult->setMessage('Unable to authenticate; no token provided');
59
        } else { // $reply === false
60
            $testResult->setState(State::WARNING);
61
            $testResult->setMessage("Something went wrong and we couldn't tell why");
62
        }
63
64
        $this->setTestResult($testResult);
65
    }
66
}
67