|
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 <[email protected]> |
|
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
|
5 |
|
public static function getAuthConnection($uname, $_force=false) |
|
39
|
|
|
{ |
|
40
|
5 |
|
$xoops = \Xoops::getInstance(); |
|
41
|
5 |
|
static $auth_instance; |
|
42
|
5 |
|
if (!isset($auth_instance) || (bool)$_force) { |
|
43
|
|
|
/* @var $config_handler XoopsConfigHandler */ |
|
44
|
5 |
|
$authConfig = $xoops->getConfigs(); |
|
45
|
5 |
|
if (empty($authConfig['auth_method'])) { // If there is a config error, we use xoops |
|
46
|
|
|
$xoops_auth_method = 'xoops'; |
|
47
|
|
|
} else { |
|
48
|
5 |
|
$xoops_auth_method = $authConfig['auth_method']; |
|
49
|
|
|
} |
|
50
|
|
|
// Verify if uname allow to bypass LDAP auth |
|
51
|
5 |
|
if (isset($authConfig['ldap_users_bypass']) && in_array($uname, $authConfig['ldap_users_bypass'])) { |
|
52
|
2 |
|
$xoops_auth_method = 'xoops'; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
5 |
|
$class = '\Xoops\Auth\\' . ucfirst($xoops_auth_method); |
|
56
|
5 |
|
if (!class_exists($class)) { |
|
57
|
|
|
trigger_error(\XoopsLocale::EF_CLASS_NOT_FOUND, E_USER_ERROR); |
|
58
|
|
|
return false; |
|
59
|
|
|
} |
|
60
|
5 |
|
$dao = null; |
|
61
|
5 |
|
switch ($xoops_auth_method) { |
|
62
|
5 |
|
case 'xoops': |
|
63
|
3 |
|
$dao = null; |
|
64
|
3 |
|
break; |
|
65
|
2 |
|
case 'ldap': |
|
66
|
1 |
|
$dao = null; |
|
67
|
1 |
|
break; |
|
68
|
1 |
|
case 'ads': |
|
69
|
1 |
|
$dao = null; |
|
70
|
1 |
|
break; |
|
71
|
|
|
} |
|
72
|
5 |
|
$auth_instance = new $class($dao); |
|
73
|
|
|
} |
|
74
|
5 |
|
return $auth_instance; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|