Passed
Push — 1.11.x ( bce6cd...c146d9 )
by Angel Fernando Quiroz
12:25
created

main/auth/cas/cas_var.inc.php (4 issues)

1
<?php
2
3
/* This file contains all the configuration variable for the cas module
4
 * In the future, these will be in the database
5
*/
6
7
if (api_is_cas_activated()) {
8
    require_once __DIR__.'/../../../vendor/apereo/phpcas/source/CAS.php';
9
10
    // Get the $cas array from app/config/auth.conf.php
11
    global $cas;
12
13
    if (is_array($cas) && array_key_exists('debug', $cas) && !empty($cas['debug'])) {
14
        phpCAS::setDebug($cas['debug']);
15
    }
16
17
    if (is_array($cas) && array_key_exists('verbose', $cas) && $cas['verbose']) {
18
        phpCAS::setVerbose(true);
19
    }
20
21
    if (!phpCAS::isInitialized()) {
22
        switch (api_get_setting('cas_protocol')) {
23
            case 'CAS1':
24
                $version = CAS_VERSION_1_0;
0 ignored issues
show
The constant CAS_VERSION_1_0 was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
25
                break;
26
            case 'CAS3':
27
                $version = CAS_VERSION_3_0;
0 ignored issues
show
The constant CAS_VERSION_3_0 was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
28
                break;
29
            case 'SAML':
30
                $version = SAML_VERSION_1_1;
0 ignored issues
show
The constant SAML_VERSION_1_1 was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
31
                break;
32
            case 'CAS2':
33
            default:
34
                $version = CAS_VERSION_2_0;
0 ignored issues
show
The constant CAS_VERSION_2_0 was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
35
        }
36
        $port = api_get_setting('cas_port');
37
        if (is_null($port)) {
38
            $port = 443;
39
        } else {
40
            $port = intval($port) ?: 443;
41
        }
42
        $uri = api_get_setting('cas_server_uri') ?: '';
43
        $hostname = api_get_setting('cas_server') ?: 'localhost';
44
45
        phpCAS::client($version, $hostname, $port, $uri);
46
47
        if (is_array($cas) && array_key_exists('noCasServerValidation', $cas) && $cas['noCasServerValidation']) {
48
            phpCAS::setNoCasServerValidation();
49
        }
50
51
        if (is_array($cas)) {
52
            if (array_key_exists('fixedServiceURL', $cas)) {
53
                $fixedServiceURL = $cas['fixedServiceURL'];
54
                if (is_string($fixedServiceURL)) {
55
                    phpCAS::setFixedServiceURL($fixedServiceURL);
56
                } elseif (is_bool($fixedServiceURL) && $fixedServiceURL) {
57
                    phpCAS::setFixedServiceURL(api_get_configuration_value('root_web'));
58
                }
59
            }
60
61
            if (isset($cas['saml_validate_url'])) {
62
                phpCAS::setServerSamlValidateURL($cas['saml_validate_url']);
63
            }
64
        }
65
    }
66
}
67