Skip to content

Commit

Permalink
Dev Fixed recovery for incorrect authentication / authorization confi…
Browse files Browse the repository at this point in the history
…guration.
  • Loading branch information
SamMousa committed Apr 10, 2015
1 parent 9e4dc6a commit 2dfd2b0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
3 changes: 2 additions & 1 deletion application/controllers/PluginsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,10 @@ public function actionConfigureAuth() {
}
$authenticationPlugins = $request->getParam('authenticationPlugins');
if (is_array($authenticationPlugins) && array_intersect($authenticationPlugins, array_keys(App()->pluginManager->getAuthenticators())) == $authenticationPlugins) {
SettingGlobal::set('authenticationPlugins', $authenticationPlugins);
\SettingGlobal::set('authenticationPlugins', $authenticationPlugins);
App()->user->setFlash('success', gT('Authorization and authentication configuration updated.'));
}

}
$this->redirect(['plugins/index']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private function renderJs($output, $pos)
private function combineAndCompress($type, $urls, $pos)
{
$this->fileUrl or $this->fileUrl = $this->getCoreScriptUrl();
$this->basePath or $this->basePath = realpath($_SERVER['DOCUMENT_ROOT']);
$this->basePath or $this->basePath = \Yii::getPathOfAlias('webroot');
$this->filePath or $this->filePath = $this->basePath.$this->fileUrl;

$optionsHash = ($type == 'js') ? md5($this->basePath . $this->compressJs . $this->ttlDays . $this->prefix)
Expand Down
15 changes: 11 additions & 4 deletions application/libraries/PluginManager/PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ class PluginManager extends \CApplicationComponent{
public function init() {
PluginConfig::$pluginManager = $this;
$this->loadPlugins();
if (count($this->getAuthenticators(true)) == 0 && $reload = true && null === $this->enablePlugin('ls_core_plugins_AuthDb')) {
throw new \Exception("No authentication plugins available.");
if (count($this->getAuthenticators(true)) == 0) {

// Enable auth db.
$result = $this->enablePlugin('ls_core_plugins_AuthDb');
if (!$result) {
throw new \Exception("No authentication plugins available.");
}
};
if ($this->getAuthorizer() == null && $reload = true && null === $this->enablePlugin('ls_core_plugins_PermissionDb')) {
throw new \Exception("No authorization plugin available.");
Expand Down Expand Up @@ -272,15 +277,17 @@ public function getAuthenticators($activeOnly = false) {
return $plugin instanceOf iAuthenticationPlugin;
});
if ($activeOnly) {
$authPlugins = \SettingGlobal::get('authenticationPlugins', []);
// If no active plugins are in the configuration we give enable AuthDb.
$authPlugins = \SettingGlobal::get('authenticationPlugins', ['ls_core_plugins_AuthDb']);
$result = array_intersect_key($result, array_flip($authPlugins));
}
return $result;
}

public function getAuthorizer() {
$authorizers = $this->getAuthorizers(true);
$authPlugin = \SettingGlobal::get('authorizationPlugin');
// If not set use PermissionDb.
$authPlugin = \SettingGlobal::get('authorizationPlugin', 'ls_core_plugins_PermissionDb');
if (isset($authorizers[$authPlugin])) {
return $authorizers[$authPlugin];
}
Expand Down
2 changes: 2 additions & 0 deletions application/models/SettingGlobal.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public function setName($value) {
public function setValue($value) {
if (is_array($value)) {
$this->stg_value = "__JSON__" . json_encode($value);
} else {
$this->stg_value = $value;
}
}
public static function get($name, $default = null) {
Expand Down
2 changes: 1 addition & 1 deletion application/views/plugins/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
echo TbHtml::closeTag('div');
echo TbHtml::endForm();

var_dump($modules);

?>

</div>

0 comments on commit 2dfd2b0

Please sign in to comment.