Passed
Push — master ( 002669...959dd8 )
by Tim
01:55
created

AuthSources::convertAuthSourceData()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 12
c 0
b 0
f 0
nc 16
nop 1
dl 0
loc 19
rs 8.8571
1
<?php
2
3
namespace SimpleSAML\Module\monitor\TestSuite;
4
5
use \SimpleSAML_Configuration as ApplicationConfiguration;
6
use \SimpleSAML\Module\monitor\TestConfiguration as TestConfiguration;
7
use \SimpleSAML\Module\monitor\TestData as TestData;
8
9
final class AuthSources extends \SimpleSAML\Module\monitor\TestSuiteFactory
10
{
11
    /**
12
     * @var array|bool
13
     */
14
    private $checkAuthSources = true;
0 ignored issues
show
introduced by
The private property $checkAuthSources is not used, and could be removed.
Loading history...
15
16
    /**
17
     * @var ApplicationConfiguration
18
     */
19
    private $authSourceConfig;
20
21
    /**
22
     * @var string
23
     */
24
    private $authSourceId = '';
25
26
    /**
27
     * @param TestConfiguration $configuration
28
     */
29
    public function __construct($configuration, $authSourceId)
30
    {
31
        $this->authSourceId = $authSourceId;
32
33
        $this->authSourceConfig = $configuration->getAuthSourceConfig();
34
        $this->setCategory('Authentication sources');
35
36
        parent::__construct($configuration);
37
    }
38
39
    /**
40
     * @return void
41
     */
42
    public function invokeTest()
43
    {
44
        $configuration = $this->getConfiguration();
45
        $authSourceData = $this->authSourceConfig->getValue($this->authSourceId);
46
        $input = array(
47
            'authSourceId' => $authSourceId,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $authSourceId does not exist. Did you maybe mean $authSourceData?
Loading history...
48
            'authSourceData' => $authSourceData
49
        );
50
        $testData = new TestData($input);
51
52
        switch ($authSourceData[0]) {
53
            case 'ldap:LDAP':
54
                $ldapTest = new AuthSource\Ldap($configuration, $testData);
55
                $this->addTestResults($ldapTest->getTestResults());
56
                break;
57
            case 'negotiate:Negotiate':
58
                $negoTest = new AuthSource\Negotiate($configuration, $testData);
59
                $this->addTestResults($negoTest->getTestResults());
60
61
                // We need to do some convertions from Negotiate > LDAP
62
                $this->convertAuthSourceData($authSourceData);
63
                $testData->setInput($authSourceData, 'authSourceData');
64
65
                $ldapTest = new AuthSource\Ldap($configuration, $testData);
66
                $this->addTestResults($ldapTest->getTestResults());
67
                break;
68
            case 'multiauth:MultiAuth':
69
                // Relies on other authSources
70
                continue;
71
            default:
72
                // Not implemented
73
                continue;
74
        }
75
76
        $this->calculateState();
77
    }
78
79
    /**
80
     * @param array $authSourceData
81
     *
82
     * @return void
83
     */
84
    private function convertAuthSourceData(&$authSourceData)
85
    {
86
        // LDAP and Negotiate authSources use different names for equal properties
87
        // Hopefully this function can go away in SSP 2.0
88
        if (isSet($authSourceData['debugLDAP'])) {
89
            $authSourceData['debug'] = $authSourceData['debugLDAP'];
90
            unset($authSourceData['debugLDAP']);
91
        }
92
        if (isSet($authSourceData['adminUser'])) {
93
            $authSourceData['search.username'] = $authSourceData['adminUser'];
94
            unset($authSourceData['adminUser']);
95
        }
96
        if (isSet($authSourceData['adminPassword'])) {
97
            $authSourceData['search.password'] = $authSourceData['adminPassword'];
98
            unset($authSourceData['adminPassword']);
99
        }
100
        if (isSet($authSourceData['base'])) {
101
            $authSourceData['search.base'] = $authSourceData['base'];
102
            unset($authSourceData['base']);
103
        }
104
    }
105
}
106