Skip to content
Snippets Groups Projects
Commit 658e710a authored by Sebastian Kehr's avatar Sebastian Kehr :rowboat_tone2:
Browse files

refs #16948 [fid] optionally allow to override fidis base url via request parameters

* forbid base url overrides by default and allow in alpha environments
* override base url via separate mvc event listener
* print effective fidis base url in footer
parent 6ccd1448
Branches
Tags
No related merge requests found
[Parent_Config]
relative_path=../../../config/vufind/fid.ini
[Client]
baseUrlOverrideAllowed = true
\ No newline at end of file
[Client]
baseUrl = http://172.18.113.133/bbi-alpha.3
baseUrlOverrideAllowed = false
baseUrlOverridePattern = "^https://fid-api.finc.info/"
baseUrl = https://fid-api.finc.info/staging/fid
xdebug_trusted_proxies[] = 139.18.25.87
[Security]
......
......@@ -33,6 +33,7 @@ use fid\Helper\TranslatorDelegator;
use fid\Hydrator\OrderHydrator;
use fid\Hydrator\UserHydrator;
use fid\Hydrator\UserHydratorDelegatorFactory;
use fid\Listener\BaseUrlListener;
use fid\Listener\ErrorListener;
use fid\Listener\ErrorListenerFactory;
use fid\Listener\LocaleListener;
......@@ -61,15 +62,15 @@ use Zend\ServiceManager\Factory\InvokableFactory;
$config = [
'forms' => [
'user-init-form' => require 'user-init-form.php',
'user-create-form' => require 'user-create-form.php',
'user-update-form' => require 'user-update-form.php',
'admin-edit-form' => require 'admin-edit-form.php',
'fid-acquisition-form' => require 'fid-acquisition-form.php',
'user-init-form' => require 'user-init-form.php',
'user-create-form' => require 'user-create-form.php',
'user-update-form' => require 'user-update-form.php',
'admin-edit-form' => require 'admin-edit-form.php',
'fid-acquisition-form' => require 'fid-acquisition-form.php',
'fid-acquisition-subito-partial-copy-form' => require 'fid-acquisition-subito-partial-copy-form.php',
PasswordResetModel::class => require 'password-reset-form.php',
PasswordChangeModel::class => require 'password-change-form.php',
UsernameChangeModel::class => require 'username-change-form.php',
PasswordResetModel::class => require 'password-reset-form.php',
PasswordChangeModel::class => require 'password-change-form.php',
UsernameChangeModel::class => require 'username-change-form.php',
],
'filters' => [
'factories' => [
......@@ -78,7 +79,7 @@ $config = [
],
'hydrators' => [
'factories' => [
UserHydrator::class => InvokableFactory::class,
UserHydrator::class => InvokableFactory::class,
OrderHydrator::class => InvokableFactory::class,
],
'delegators' => [
......@@ -88,22 +89,23 @@ $config = [
],
],
'controllers' => [
'factories' => [
'factories' => [
RecordController::class => AbstractBaseWithConfigFactory::class,
UserController::class => UserControllerFactory::class,
UserController::class => UserControllerFactory::class,
],
'aliases' => [
'aliases' => [
\VuFind\Controller\RecordController::class => RecordController::class,
],
'delegators' => [
RecordController::class => [
RecordControllerDelegatorFactory::class,
RecordControllerDelegatorFactory::class,
],
],
],
'listeners' => [
ErrorListener::class,
LocaleListener::class,
BaseUrlListener::class,
],
// TODO: issue PR to add alias to vufind core
'controller_plugins' => [
......@@ -129,6 +131,7 @@ $config = [
ErrorListener::class => InvokableFactory:: class,
ILSAuthenticator::class => ILSAuthenticatorFactory::class,
LocaleListener::class => InvokableFactory::class,
BaseUrlListener::class => InvokableFactory::class
],
],
'view_helpers' => [
......@@ -141,12 +144,12 @@ $config = [
],
'vufind' => [
'plugin_managers' => [
'ajaxhandler' => [
'ajaxhandler' => [
'factories' => [
'fid\AjaxHandler\GetResolverLinks' =>
'fid\AjaxHandler\GetResolverLinksFactory'
],
'aliases' => [
'aliases' => [
'getResolverLinks' =>
'fid\AjaxHandler\GetResolverLinks'
]
......@@ -320,7 +323,7 @@ $config = [
],
],
],
'orders' => [
'orders' => [
'type' => 'literal',
'options' => [
'route' => '/orders',
......@@ -339,7 +342,7 @@ $config = [
'route' => '/admin'
],
'child_routes' => [
'list' => [
'list' => [
'type' => 'literal',
'options' => [
'route' => '/list',
......@@ -349,7 +352,7 @@ $config = [
],
],
],
'exportList' => [
'exportList' => [
'type' => 'literal',
'options' => [
'route' => '/exportList',
......@@ -359,7 +362,7 @@ $config = [
],
],
],
'edit' => [
'edit' => [
'type' => 'Zend\Router\Http\Segment',
'options' => [
'route' => '/edit/[:userid]',
......@@ -370,7 +373,7 @@ $config = [
],
],
],
'orders' => [
'orders' => [
'type' => 'literal',
'options' => [
'route' => '/orders',
......@@ -412,7 +415,9 @@ $config = [
];
$nonTabRecordActions = [
'fidPDA', 'fidSubitoArticle', 'fidSubitoPartialCopy'
'fidPDA',
'fidSubitoArticle',
'fidSubitoPartialCopy'
];
// Define record view routes -- route name => controller
......
<?php
/**
* Copyright (C) 2020 Leipzig University Library
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* @author Sebastian Kehr <kehr@ub.uni-leipzig.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2
*/
namespace fid\Listener;
use fid\Service\ClientException;
use fid\Service\ClientFactory;
use Psr\Container\ContainerInterface;
use VuFind\Config\PluginManager;
use VuFind\Cookie\CookieManager;
use Zend\Config\Config;
use Zend\EventManager\AbstractListenerAggregate;
use Zend\EventManager\EventManagerInterface;
use Zend\Mvc\MvcEvent;
use Zend\View\Model\ViewModel;
class BaseUrlListener extends AbstractListenerAggregate
{
protected const PARAM = 'fidis_base_url';
protected const EVENT = MvcEvent::EVENT_ROUTE;
protected const STATUS = '%sFidis: %s';
/**
* @var string
*/
protected $baseUrl;
/**
* @return string
*/
public function getBaseUrl(): string
{
return $this->baseUrl;
}
public function attach(EventManagerInterface $events, $priority = 9000)
{
$events->attach(static::EVENT, [$this, 'onDispatch'], $priority);
}
/**
* @param MvcEvent $event
*
* @throws ClientException
*/
public function onDispatch(MvcEvent $event)
{
/** @var Config $config */
/** @var PluginManager $configManager */
/** @var ContainerInterface $container */
$request = $event->getRequest();
$container = $event->getApplication()->getServiceManager();
$configManager = $container->get(PluginManager::class);
$config = $configManager->get(ClientFactory::CONFIG_KEY)->Client;
if (!$config instanceof Config || !$config->baseUrlOverrideAllowed) {
return;
}
$this->baseUrl = $request->getQuery(self::PARAM)
?? $request->getCookie()[self::PARAM]
?? $config->baseUrl;
$valid = $this->baseUrl === $config->baseUrl
|| preg_match("#$config->baseUrlOverridePattern#", $this->baseUrl);
if (!$valid) {
$this->baseUrl = $config->baseUrl;
}
/** @var ViewModel $viewModel */
/** @var CookieManager $cookieManager */
$cookieManager = $container->get(CookieManager::class);
$viewModel = $container->get('ViewManager')->getViewModel();
$cookieManager->set(self::PARAM, $this->baseUrl);
$fidisStatus = sprintf(self::STATUS, $valid ? '' : '!', $this->baseUrl);
$viewModel->setVariable('fidisStatus', $fidisStatus);
}
}
\ No newline at end of file
<?php
/**
* Copyright (C) 2019 Leipzig University Library
* Copyright (C) 2020 Leipzig University Library
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
......@@ -21,6 +21,7 @@
namespace fid\Service;
use fid\Listener\BaseUrlListener;
use Psr\Container\ContainerInterface;
use Psr\Http\Client\ClientInterface as HttpClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
......@@ -35,7 +36,7 @@ use Zend\Session\SessionManager;
class ClientFactory
{
protected const CONFIG_KEY = 'fid';
public const CONFIG_KEY = 'fid';
protected const ERROR_CONFIG_FILE = 'Invalid configuration file "%s.ini".';
......@@ -55,6 +56,9 @@ class ClientFactory
throw new ClientException($message);
}
$baseUrl = $container->get(BaseUrlListener::class)->getBaseUrl();
$configArray = compact('baseUrl') + $config->toArray();
/** @var SessionManager $sessionManager */
$sessionManager = $container->get(SessionManager::class);
$session = new Session(Client::class, $sessionManager);
......@@ -71,7 +75,9 @@ class ClientFactory
/** @var RequestFactoryInterface $requestFactory */
$requestFactory = $container->get(RequestFactoryInterface::class);
return new Client($config->toArray(), $session, $cookies, $serializer,
$httpClient, $uriFactory, $streamFactory, $requestFactory);
return new Client(
$configArray, $session, $cookies, $serializer, $httpClient,
$uriFactory, $streamFactory, $requestFactory
);
}
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment