summaryrefslogtreecommitdiffstats
path: root/modules/setup/application/forms/AuthenticationPage.php
blob: 52e3c66f81b977170574a80ced0ac688786be213 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/* Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */

namespace Icinga\Module\Setup\Forms;

use Icinga\Authentication\User\ExternalBackend;
use Icinga\Web\Form;
use Icinga\Application\Platform;

/**
 * Wizard page to choose an authentication backend
 */
class AuthenticationPage extends Form
{
    /**
     * Initialize this page
     */
    public function init()
    {
        $this->setRequiredCue(null);
        $this->setName('setup_authentication_type');
        $this->setTitle($this->translate('Authentication', 'setup.page.title'));
        $this->addDescription($this->translate(
            'Please choose how you want to authenticate when accessing Icinga Web 2.'
            . ' Configuring backend specific details follows in a later step.'
        ));
    }

    /**
     * @see Form::createElements()
     */
    public function createElements(array $formData)
    {
        if (isset($formData['type']) && $formData['type'] === 'external') {
            list($username, $_) = ExternalBackend::getRemoteUserInformation();
            if ($username === null) {
                $this->info(
                    $this->translate(
                        'You\'re currently not authenticated using any of the web server\'s authentication '
                        . 'mechanisms. Make sure you\'ll configure such, otherwise you\'ll not be able to '
                        . 'log into Icinga Web 2.'
                    ),
                    false
                );
            }
        }

        $backendTypes = array();
        if (Platform::hasMysqlSupport() || Platform::hasPostgresqlSupport()) {
            $backendTypes['db'] = $this->translate('Database');
        }
        if (Platform::extensionLoaded('ldap')) {
            $backendTypes['ldap'] = 'LDAP';
        }
        $backendTypes['external'] = $this->translate('External');

        $this->addElement(
            'select',
            'type',
            array(
                'required'      => true,
                'autosubmit'    => true,
                'label'         => $this->translate('Authentication Type'),
                'description'   => $this->translate('The type of authentication to use when accessing Icinga Web 2'),
                'multiOptions'  => $backendTypes
            )
        );
    }
}