Completed
Push — master ( 221a92...54c722 )
by Tim
01:43
created

Negotiate   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 70
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 3

2 Methods

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