Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
Authentication and Session Handling
Browse files Browse the repository at this point in the history
  • Loading branch information
fbergkemper authored and Marco van Wieringen committed Dec 17, 2014
1 parent 3db2263 commit 199ef41
Show file tree
Hide file tree
Showing 53 changed files with 1,735 additions and 754 deletions.
13 changes: 6 additions & 7 deletions config/application.config.php
Expand Up @@ -3,7 +3,7 @@
/**
*
* bareos-webui - Bareos Web-Frontend
*
*
* @link https://github.com/bareos/bareos-webui for the canonical source repository
* @copyright Copyright (c) 2013-2014 dass-IT GmbH (http://www.dass-it.de/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
Expand All @@ -28,7 +28,7 @@
// Use the $env value to dtermine which module to load
$modules = array(
'Application',
'Dashboard',
'Dashboard',
'Director',
'Fileset',
'Pool',
Expand All @@ -43,6 +43,7 @@
'Admin',
'User',
'Install',
'Auth',
);

/*
Expand All @@ -51,20 +52,18 @@
}
*/

// to display all errors use:
// to display all errors use:

/*
if($env == 'development') {
$modules[] = 'ZendDeveloperTools'; // you may comment only this line out if ZendDeveloperTools are not installed e.g.
//$modules[] = 'ZendDeveloperTools'; // you may comment only this line out if ZendDeveloperTools are not installed e.g.
error_reporting(E_ALL);
ini_set("display_errors", 1);
}
*/

return array(
// This should be an array of module namespaces used in the application.
'modules' => $modules,

// These are various options for the listeners attached to the ModuleManager
'module_listener_options' => array(
// This should be an array of paths in which modules reside.
Expand Down
22 changes: 19 additions & 3 deletions config/autoload/global.php
Expand Up @@ -3,7 +3,7 @@
/**
*
* bareos-webui - Bareos Web-Frontend
*
*
* @link https://github.com/bareos/bareos-webui for the canonical source repository
* @copyright Copyright (c) 2013-2014 dass-IT GmbH (http://www.dass-it.de/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
Expand Down Expand Up @@ -43,8 +43,24 @@
),
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter'
=> 'Zend\Db\Adapter\AdapterServiceFactory',
'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
),
'abstract_factories' => array(
// to allow other adapters to be called by $sm->get('adaptername')
'Zend\Db\Adapter\AdapterAbstractServiceFactory',
),
),
'session' => array(
'config' => array(
'class' => 'Zend\Session\Config\SessionConfig',
'options' => array(
'name' => 'Bareos-WebUI',
),
),
'storage' => 'Zend\Session\Storage\SessionArrayStorage',
'validators' => array(
'Zend\Session\Validator\RemoteAddr',
'Zend\Session\Validator\HttpUserAgent',
),
),
);
76 changes: 47 additions & 29 deletions config/autoload/local.php.dist
Expand Up @@ -38,35 +38,53 @@

return array(
'db' => array(
// Set your database driver here: Pdo_Mysql, Pdo_Pgsql, Mysqli or Pgsql
'driver' => 'Pdo_Pgsql',
// Set your database here
'dbname' => 'bareos',
// Set your hostname here
'host' => 'localhost',
// Set your username here
'username' => 'bareos_webui',
// Set your password here
'password' => '',
'adapters' => array(
'localhost' => array(
'driver' => 'Pdo_Pgsql',
'dbname' => 'bareos',
'host' => 'localhost',
'username' => 'bareos',
'password' => '',
),
/*
'remote-dir' => array(
'driver' => 'Pdo_Pgsql',
'dbname' => 'bareos',
'host' => 'remote-db-server',
'username' => 'bareos',
'password' => '',
),
*/
),
),
'director' => array(
// Director hostname or ip address
'host' => '127.0.0.1',
// Director port
'port' => '9101',
// Director password
'password' => '',
// Director named console
'console_name' => null,
// TLS parameter
'tls_verify_peer' => false,
'server_can_do_tls' => false,
'server_requires_tls' => false,
'client_can_do_tls' => true,
'client_requires_tls' => false,
'ca_file' => null,
'cert_file' => null,
'cert_file_passphrase' => null,
'allowed_cns' => null,
'directors' => array (
'localhost' => array(
'host' => 'localhost',
'port' => '9101',
'tls_verify_peer' => false,
'server_can_do_tls' => false,
'server_requires_tls' => false,
'client_can_do_tls' => false,
'client_requires_tls' => false,
'ca_file' => null,
'cert_file' => null,
'cert_file_passphrase' => null,
'allowed_cns' => null,
),
/*
'remote-dir' => array(
'host' => 'FQDN remote dir',
'port' => '9101',
'tls_verify_peer' => false,
'server_can_do_tls' => false,
'server_requires_tls' => false,
'client_can_do_tls' => false,
'client_requires_tls' => false,
'ca_file' => null,
'cert_file' => null,
'cert_file_passphrase' => null,
'allowed_cns' => null,
),
*/
),
);
102 changes: 101 additions & 1 deletion module/Application/Module.php
Expand Up @@ -11,6 +11,9 @@

use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
use Zend\Session\SessionManager;
use Zend\Session\Container;
use Bareos\BSock\BareosBsock;

class Module
{
Expand All @@ -19,6 +22,7 @@ public function onBootstrap(MvcEvent $e)
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$this->initSession($e);
}

public function getConfig()
Expand All @@ -35,9 +39,105 @@ public function getAutoloaderConfig()
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
'Bareos' => __DIR__ .'/../../vendor/Bareos/library/Bareos',
'Bareos' => __DIR__ .'/../../vendor/Bareos/library/Bareos',
),
),
);
}

public function initSession($e)
{
$session = $e->getApplication()->getServiceManager()->get('Zend\Session\SessionManager');
$session->start();

$container = new Container('bareos');

if(!isset($container->init)) {

$serviceManager = $e->getApplication()->getServiceManager();
$request = $serviceManager->get('Request');

$session->regenerateId(true);
$container->init = 1;
$container->remoteAddr = $request->getServer()->get('REMOTE_ADDR');
$container->httpUserAgent = $request->getServer()->get('HTTP_USER_AGENT');
$container->username = "";
$container->authenticated = false;

$config = $serviceManager->get('Config');

if(!isset($config['session'])) {
return;
}

$sessionConfig = $config['session'];

if (isset($sessionConfig['validators'])) {
$chain = $session->getValidatorChain();
foreach ($sessionConfig['validators'] as $validator) {
switch ($validator) {
case 'Zend\Session\Validator\HttpUserAgent':
$validator = new $validator($container->httpUserAgent);
break;
case 'Zend\Session\Validator\RemoteAddr':
$validator = new $validator($container->remoteAddr);
break;
default:
$validator = new $validator();
}
$chain->attach('session.validate', array($validator, 'isValid'));
}
}

}

}

public function getServiceConfig()
{
return array(
'factories' => array(
'Zend\Session\SessionManager' => function ($sm) {
$config = $sm->get('config');

if (isset($config['session'])) {

$session = $config['session'];

$sessionConfig = null;

if(isset($session['config'])) {
$class = isset($session['config']['class']) ? $session['config']['class'] : 'Zend\Session\Config\SessionConfig';
$options = isset($session['config']['options']) ? $session['config']['options'] : array();
$sessionConfig = new $class();
$sessionConfig->setOptions($options);
}

$sessionStorage = null;

if (isset($session['storage'])) {
$class = $session['storage'];
$sessionStorage = new $class();
}

$sessionSaveHandler = null;

if (isset($session['save_handler'])) {
// class should be fetched from service manager since it will require constructor arguments
$sessionSaveHandler = $sm->get($session['save_handler']);
}

$sessionManager = new SessionManager($sessionConfig, $sessionStorage, $sessionSaveHandler);

} else {
$sessionManager = new SessionManager();
}

Container::setDefaultManager($sessionManager);
return $sessionManager;
}
),
);
}

}

0 comments on commit 199ef41

Please sign in to comment.