This repository has been archived by the owner on Nov 25, 2020. It is now read-only.
/
class.CoreAuthLoader.php
115 lines (105 loc) · 5.78 KB
/
class.CoreAuthLoader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/*
* Copyright 2007-2011 Charles du Jeu <contact (at) cdujeu.me>
* This file is part of AjaXplorer.
*
* AjaXplorer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AjaXplorer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with AjaXplorer. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <http://www.ajaxplorer.info/>.
*/
defined('AJXP_EXEC') or die( 'Access not allowed');
/**
* Config loader overrider
* @package AjaXplorer_Plugins
* @subpackage Core
*/
class CoreAuthLoader extends AJXP_Plugin{
/**
* @var AbstractAuthDriver
*/
protected static $authStorageImpl;
public function getConfigs(){
$configs = parent::getConfigs();
$configs["ALLOW_GUEST_BROWSING"] = !isSet($_SERVER["HTTP_AJXP_FORCE_LOGIN"]) && ($configs["ALLOW_GUEST_BROWSING"] === "true" || $configs["ALLOW_GUEST_BROWSING"] === true || intval($configs["ALLOW_GUEST_BROWSING"]) == 1);
// FORCE CASE INSENSITIVY FOR SQL BASED DRIVERS
if(isSet($configs["MASTER_INSTANCE_CONFIG"]) && $configs["MASTER_INSTANCE_CONFIG"]["instance_name"] == "auth.sql"){
$configs["CASE_SENSITIVE"] = false;
}
if(isSet($configs["SLAVE_INSTANCE_CONFIG"]) && !empty($configs["SLAVE_INSTANCE_CONFIG"]) && $configs["SLAVE_INSTANCE_CONFIG"]["instance_name"] == "auth.sql"){
$configs["CASE_SENSITIVE"] = false;
}
return $configs;
}
public function getAuthImpl(){
if(!isSet(self::$authStorageImpl)){
if(!isSet($this->pluginConf["MASTER_INSTANCE_CONFIG"])){
throw new Exception("Please set up at least one MASTER_INSTANCE_CONFIG in core.auth options");
}
$masterName = is_array($this->pluginConf["MASTER_INSTANCE_CONFIG"]) ? $this->pluginConf["MASTER_INSTANCE_CONFIG"]["instance_name"] : $this->pluginConf["MASTER_INSTANCE_CONFIG"];
$masterName = str_replace("auth.", "", $masterName);
if(!empty($this->pluginConf["SLAVE_INSTANCE_CONFIG"])){
$slaveName = is_array($this->pluginConf["SLAVE_INSTANCE_CONFIG"]) ? $this->pluginConf["SLAVE_INSTANCE_CONFIG"]["instance_name"] : $this->pluginConf["SLAVE_INSTANCE_CONFIG"];
$slaveName = str_replace("auth.", "", $slaveName);
// Manually set up a multi config
$userBase = $this->pluginConf["MULTI_USER_BASE_DRIVER"];
if($userBase == "master") $baseName = $masterName;
else if($userBase == "slave") $baseName = $slaveName;
else $baseName = "";
$mLabel = ""; $sLabel = "";$separator = "";
if($this->pluginConf["MULTI_MODE"]["instance_name"] == "USER_CHOICE"){
$mLabel = $this->pluginConf["MULTI_MODE"]["MULTI_MASTER_LABEL"];
$sLabel = $this->pluginConf["MULTI_MODE"]["MULTI_SLAVE_LABEL"];
$separator = $this->pluginConf["MULTI_MODE"]["MULTI_USER_ID_SEPARATOR"];
}
$newOptions = array(
"instance_name" => "auth.multi",
"MODE" => $this->pluginConf["MULTI_MODE"]["instance_name"],
"MASTER_DRIVER" => $masterName,
"USER_BASE_DRIVER" => $baseName,
"USER_ID_SEPARATOR" => $separator,
"TRANSMIT_CLEAR_PASS" => $this->pluginConf["TRANSMIT_CLEAR_PASS"],
"DRIVERS" => array(
$masterName => array(
"NAME" => $masterName,
"LABEL" => $mLabel,
"OPTIONS" => $this->pluginConf["MASTER_INSTANCE_CONFIG"]
),
$slaveName => array(
"NAME" => $slaveName,
"LABEL" => $sLabel,
"OPTIONS" => $this->pluginConf["SLAVE_INSTANCE_CONFIG"]
),
)
);
// MERGE BASIC AUTH OPTIONS FROM MASTER
$masterMainAuthOptions = array();
$keys = array("TRANSMIT_CLEAR_PASS", "AUTOCREATE_AJXPUSER", "LOGIN_REDIRECT", "AJXP_ADMIN_LOGIN");
if(is_array($this->pluginConf["MASTER_INSTANCE_CONFIG"])){
foreach($keys as $key){
if(isSet($this->pluginConf["MASTER_INSTANCE_CONFIG"][$key])){
$masterMainAuthOptions[$key] = $this->pluginConf["MASTER_INSTANCE_CONFIG"][$key];
}
}
}
$newOptions = array_merge($newOptions, $masterMainAuthOptions);
self::$authStorageImpl = ConfService::instanciatePluginFromGlobalParams($newOptions, "AbstractAuthDriver");
AJXP_PluginsService::getInstance()->setPluginUniqueActiveForType("auth", self::$authStorageImpl->getName(), self::$authStorageImpl);
}else{
self::$authStorageImpl = ConfService::instanciatePluginFromGlobalParams($this->pluginConf["MASTER_INSTANCE_CONFIG"], "AbstractAuthDriver");
AJXP_PluginsService::getInstance()->setPluginUniqueActiveForType("auth", self::$authStorageImpl->getName());
}
}
return self::$authStorageImpl;
}
}