1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: namespace Xoops\Auth;
13:
14: /**
15: * Authentication class factory
16: *
17: * @category Xoops\Auth
18: * @package Factory
19: * @author Pierre-Eric MENUET <pemphp@free.fr>
20: * @copyright 2000-2014 XOOPS Project (http://xoops.org)
21: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
22: * @link http://xoops.org
23: * @since 2.0
24: */
25: class Factory
26: {
27: /**
28: * Get a reference to the only instance of authentication class
29: *
30: * if the class has not been instantiated yet, this will also take
31: * care of that
32: *
33: * @param string $uname user name
34: * @param bool $_force internal use for tests
35: *
36: * @return AuthAbstract|bool Reference to the only instance of authentication class
37: */
38: public static function getAuthConnection($uname, $_force=false)
39: {
40: $xoops = \Xoops::getInstance();
41: static $auth_instance;
42: if (!isset($auth_instance) || (bool)$_force) {
43: /* @var $config_handler XoopsConfigHandler */
44: $authConfig = $xoops->getConfigs();
45: if (empty($authConfig['auth_method'])) { // If there is a config error, we use xoops
46: $xoops_auth_method = 'xoops';
47: } else {
48: $xoops_auth_method = $authConfig['auth_method'];
49: }
50: // Verify if uname allow to bypass LDAP auth
51: if (isset($authConfig['ldap_users_bypass']) && in_array($uname, $authConfig['ldap_users_bypass'])) {
52: $xoops_auth_method = 'xoops';
53: }
54:
55: $class = '\Xoops\Auth\\' . ucfirst($xoops_auth_method);
56: if (!class_exists($class)) {
57: trigger_error(\XoopsLocale::EF_CLASS_NOT_FOUND, E_USER_ERROR);
58: return false;
59: }
60: $dao = null;
61: switch ($xoops_auth_method) {
62: case 'xoops':
63: $dao = null;
64: break;
65: case 'ldap':
66: $dao = null;
67: break;
68: case 'ads':
69: $dao = null;
70: break;
71: }
72: $auth_instance = new $class($dao);
73: }
74: return $auth_instance;
75: }
76: }
77: