Issues (2037)

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
        $serviceBaseUrl = '';
45
46
        if (is_array($cas)) {
47
            if (array_key_exists('service_base_url', $cas)) {
48
                $serviceBaseUrl = $cas['service_base_url'];
49
            }
50
        }
51
52
        phpCAS::client($version, $hostname, $port, $uri, $serviceBaseUrl);
53
54
        if (is_array($cas) && array_key_exists('noCasServerValidation', $cas) && $cas['noCasServerValidation']) {
55
            phpCAS::setNoCasServerValidation();
56
        }
57
58
        if (is_array($cas)) {
59
            if (array_key_exists('fixedServiceURL', $cas)) {
60
                $fixedServiceURL = $cas['fixedServiceURL'];
61
                if (is_string($fixedServiceURL)) {
62
                    phpCAS::setFixedServiceURL($fixedServiceURL);
63
                } elseif (is_bool($fixedServiceURL) && $fixedServiceURL) {
64
                    phpCAS::setFixedServiceURL(api_get_configuration_value('root_web'));
65
                }
66
            }
67
68
            if (isset($cas['saml_validate_url'])) {
69
                phpCAS::setServerSamlValidateURL($cas['saml_validate_url']);
70
            }
71
        }
72
    }
73
}
74