Issues (3083)

htdocs/class/auth/authfactory.php (3 issues)

1
<?php
2
/**
3
 * Authentification class factory
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
13
 * @license             GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html)
14
 * @package             kernel
15
 * @subpackage          auth
16
 * @since               2.0
17
 * @author              Pierre-Eric MENUET <[email protected]>
18
 */
19
20
defined('XOOPS_ROOT_PATH') || exit('Restricted access');
21
22
/**
23
 *
24
 * @package             kernel
25
 * @subpackage          auth
26
 * @description         Authentification class factory
27
 * @author              Pierre-Eric MENUET <[email protected]>
28
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
29
 */
30
class XoopsAuthFactory
31
{
32
    /**
33
     * Get a reference to the only instance of authentication class
34
     *
35
     * if the class has not been instantiated yet, this will also take
36
     * care of that
37
     *
38
     * @static
39
     *
40
     * @param string $uname used to lookup in LDAP bypass config
41
     *
42
     * @return object Reference to the only instance of authentication class
43
     */
44
    public static function getAuthConnection($uname)
45
    {
46
        static $auth_instance;
47
        if (!isset($auth_instance)) {
48
            /** @var XoopsConfigHandler $config_handler */
49
            $config_handler = xoops_getHandler('config');
50
            $authConfig     = $config_handler->getConfigsByCat(XOOPS_CONF_AUTH);
51
52
            include_once $GLOBALS['xoops']->path('class/auth/auth.php');
53
54
            if (empty($authConfig['auth_method'])) { // If there is a config error, we use xoops
55
                $xoops_auth_method = 'xoops';
56
            } else {
57
                $xoops_auth_method = $authConfig['auth_method'];
58
            }
59
            // Verify if uname allows to bypass LDAP auth
60
            if (in_array($uname, $authConfig['ldap_users_bypass'])) {
61
                $xoops_auth_method = 'xoops';
62
            }
63
64
            $ret = include_once $GLOBALS['xoops']->path('class/auth/auth_' . $xoops_auth_method . '.php');
65
            if ($ret == false) {
66
                return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type object.
Loading history...
67
            }
68
69
            $class = 'XoopsAuth' . ucfirst($xoops_auth_method);
70
            if (!class_exists($class)) {
71
                $GLOBALS['xoopsLogger']->triggerError($class, _XO_ER_CLASSNOTFOUND, __FILE__, __LINE__, E_USER_ERROR);
72
73
                return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type object.
Loading history...
74
            }
75
            switch ($xoops_auth_method) {
76
                case 'xoops':
77
                    $dao = XoopsDatabaseFactory::getDatabaseConnection();
78
                    break;
79
                case 'ldap':
80
                    $dao = null;
81
                    break;
82
                case 'ads':
83
                    $dao = null;
84
                    break;
85
            }
86
            $auth_instance = new $class($dao);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $dao does not seem to be defined for all execution paths leading up to this point.
Loading history...
87
        }
88
89
        return $auth_instance;
90
    }
91
}
92