Skip to content

Commit

Permalink
Merge branch 'dev' into doctrine
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz committed Nov 13, 2023
2 parents e32a6e1 + 18b4cee commit 98f700e
Show file tree
Hide file tree
Showing 10 changed files with 176 additions and 22 deletions.
15 changes: 15 additions & 0 deletions config/vufind/SimulatedSSO.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; This file controls the behavior of the SimulatedSSO authentication module,
; which is intended for testing/development use only. This can be used to
; log in a specific user account as if single sign-on was triggered, which is
; useful for evaluating VuFind's SSO behavior when a real environment is not
; available.
[General]
; What username should be returned? (Set to false to throw an exception instead).
username = fakeuser1

; Map of user attributes to set (corresponding to columns in the user table).
; Comment this out to use defaults, and set "attributes = false" to disable all
; attributes.
attributes[firstname] = Test
attributes[lastname] = User
attributes[email] = "[email protected]"
14 changes: 13 additions & 1 deletion config/vufind/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ method = Database
;method = Facebook
;method = PasswordAccess
;method = Email
;method = SimulatedSSO ; INTENDED FOR TEST/DEVELOPMENT PURPOSES ONLY
;method = SimulatedSSO ; FOR TESTING ONLY -- see SimulatedSSO.ini

; This setting only applies when method is set to ILS. It determines which
; field of the ILS driver's patronLogin() return array is used as the username
Expand Down Expand Up @@ -1449,6 +1449,18 @@ replace_other_urls = true
; to false.
;prefixLinks = true

; Use a web service to determine whether to prefix each link, ignoring prefixLinks
; above unless the web service call fails. Query the configured URL via HTTP GET
; and a single query parameter, 'url', set to the link domain. The web service
; should return a body with a single number, '1' to prefix and '0' if not. The
; web service should be hosted closely such that query time is minimal. See
; https://github.com/lehigh-university-libraries/ezproxy-url-checker for an OSS
; implementation of this protocol that extracts the answers from EZproxy config.
;prefixLinksWebServiceUrl = http://localhost:8888/proxyUrl

; Duration (seconds) to cache web service response data. Default is 600.
;prefixLinksWebServiceCacheLifetime = 600

; Uncomment the following line and change the password to something secret to enable
; EZproxy ticket authentication.
;secret = "verysecretpassword"
Expand Down
7 changes: 6 additions & 1 deletion module/VuFind/src/VuFind/AjaxHandler/SystemStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development Wiki
*/
class SystemStatus extends AbstractBase
class SystemStatus extends AbstractBase implements \Laminas\Log\LoggerAwareInterface
{
use \VuFind\Log\LoggerAwareTrait;

/**
* Session Manager
*
Expand Down Expand Up @@ -119,6 +121,9 @@ public function handleRequest(Params $params)
);
}

// Test logging (note that the message doesn't need to get written for the log writers to initialize):
$this->log('info', 'SystemStatus log check', [], true);

// Test search index
try {
$results = $this->resultsManager->get('Solr');
Expand Down
60 changes: 54 additions & 6 deletions module/VuFind/src/VuFind/Auth/SimulatedSSO.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
use Laminas\Http\PhpEnvironment\Request;
use VuFind\Exception\Auth as AuthException;

use function is_array;

/**
* Simulated single sign-on authentication module (for testing purposes only).
*
Expand All @@ -50,14 +52,34 @@ class SimulatedSSO extends AbstractBase
*/
protected $getSessionInitiatorCallback;

/**
* Configuration settings
*
* @var array
*/
protected $simulatedSSOConfig;

/**
* Default user attributes, if not overridden by configuration.
*
* @var array
*/
protected $defaultAttributes = [
'firstname' => 'Test',
'lastname' => 'User',
'email' => '[email protected]',
];

/**
* Constructor
*
* @param callable $url Session initiator URL callback
* @param callable $url Session initiator URL callback
* @param array $config Configuration settings
*/
public function __construct($url)
public function __construct($url, array $config = [])
{
$this->getSessionInitiatorCallback = $url;
$this->simulatedSSOConfig = $config;
}

/**
Expand All @@ -71,10 +93,36 @@ public function __construct($url)
public function authenticate($request)
{
// If we made it this far, we should log in the user!
$user = $this->getUserTable()->getByUsername('fakeuser1');
$user->firstname = 'Test';
$user->lastname = 'User';
$user->email = '[email protected]';
$username = $this->simulatedSSOConfig['General']['username'] ?? 'fakeuser1';
if (!$username) {
throw new AuthException('Simulated failure');
}
$user = $this->getUserTable()->getByUsername($username);

// Get attribute configuration -- use defaults if no value is set, and use an
// empty array if something invalid was provided.
$attribs = $this->simulatedSSOConfig['General']['attributes']
?? $this->defaultAttributes;
if (!is_array($attribs)) {
$attribs = [];
}

$catPassword = null;
foreach ($attribs as $attribute => $value) {
if ($attribute == 'email') {
$user->updateEmail($value);
} elseif ($attribute != 'cat_password') {
$user->$attribute = $value ?? '';
} else {
$catPassword = $value;
}
}
if (!empty($user->cat_username)) {
$user->saveCredentials(
$user->cat_username,
empty($catPassword) ? $user->getCatPassword() : $catPassword
);
}

// Save and return the user object:
$user->save();
Expand Down
4 changes: 3 additions & 1 deletion module/VuFind/src/VuFind/Auth/SimulatedSSOFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public function __invoke(
$url('simulatedsso-login', [], ['query' => ['return' => $target]])
);
};
return new $requestedName($getUrl);
$config = $container->get(\VuFind\Config\PluginManager::class)
->get('SimulatedSSO')->toArray();
return new $requestedName($getUrl, $config);
}
}
2 changes: 1 addition & 1 deletion module/VuFind/src/VuFind/Cover/Layer/AbstractLayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ abstract class AbstractLayer implements LayerInterface
* @param resource $im Image resource being updated
* @param string $color Legal color name from HTML4
*
* @return allocated color
* @return int|false allocated color
*/
protected function getColor($im, $color)
{
Expand Down
6 changes: 3 additions & 3 deletions module/VuFind/src/VuFind/Cover/Layer/AbstractTextLayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected function drawText(

// If the wrap width is smaller than the image width, we want to account
// for this when right or left aligning to maintain padding on the image.
$wrapGap = ($settings->width - $settings->wrapWidth) / 2;
$wrapGap = (int)(($settings->width - $settings->wrapWidth) / 2);

$textWidth = $this->textWidth($text, $font, $fontSize);
if ($textWidth > $settings->width) {
Expand All @@ -118,7 +118,7 @@ protected function drawText(
break;
case 'center':
default:
$x = ($settings->width - $textWidth) / 2;
$x = (int)(($settings->width - $textWidth) / 2);
}

// Generate 5 lines of text, 4 offset in a border color
Expand All @@ -129,6 +129,6 @@ protected function drawText(
imagettftext($im, $fontSize, 0, $x - 1, $y, $scolor, $font, $text);
}
// 1 centered in main color
imagettftext($im, $fontSize, 0, $x, $y, $mcolor, $font, $text);
imagettftext($im, $fontSize, 0, $x, (int)$y, $mcolor, $font, $text);
}
}
8 changes: 4 additions & 4 deletions module/VuFind/src/VuFind/Cover/Layer/GridBackground.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ protected function renderGrid($im, $pattern, $color, $settings)
$settings->height,
$this->getColor($im, $settings->baseColor)
);
$halfWidth = $settings->width / 2;
$halfHeight = $settings->height / 2;
$boxWidth = $settings->width / 8;
$boxHeight = $settings->height / 8;
$halfWidth = (int)($settings->width / 2);
$halfHeight = (int)($settings->height / 2);
$boxWidth = (int)($settings->width / 8);
$boxHeight = (int)($settings->height / 8);

$bc = str_split($pattern);
for ($k = 0; $k < 4; $k++) {
Expand Down
78 changes: 74 additions & 4 deletions module/VuFind/src/VuFind/View/Helper/Root/ProxyUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@

namespace VuFind\View\Helper\Root;

use Exception;
use Laminas\Cache\Storage\Adapter\AbstractAdapter as CacheAdapter;

use function intval;

/**
* Proxy URL view helper
*
Expand All @@ -38,8 +43,14 @@
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development Wiki
*/
class ProxyUrl extends \Laminas\View\Helper\AbstractHelper
class ProxyUrl extends \Laminas\View\Helper\AbstractHelper implements
\Laminas\Log\LoggerAwareInterface,
\VuFindHttp\HttpServiceAwareInterface
{
use \VuFind\Cache\CacheTrait;
use \VuFind\Log\LoggerAwareTrait;
use \VuFindHttp\HttpServiceAwareTrait;

/**
* VuFind configuration
*
Expand All @@ -51,10 +62,13 @@ class ProxyUrl extends \Laminas\View\Helper\AbstractHelper
* Constructor
*
* @param \Laminas\Config\Config $config VuFind configuration
* @param CacheAdapter $cache Cache for web service responses
*/
public function __construct($config = null)
public function __construct($config = null, CacheAdapter $cache = null)
{
$this->config = $config;
$this->setCacheStorage($cache);
$this->cacheLifetime = intval($config->EZproxy->prefixLinksWebServiceCacheLifetime ?? 600);
}

/**
Expand All @@ -66,10 +80,66 @@ public function __construct($config = null)
*/
public function __invoke($url)
{
$usePrefix = !isset($this->config->EZproxy->prefixLinks)
|| $this->config->EZproxy->prefixLinks;
$useWebService = $this->config->EZproxy->prefixLinksWebServiceUrl ?? false;
if ($useWebService) {
$usePrefix = $this->checkUrl($url) ?? $this->checkConfig();
} else {
$usePrefix = $this->checkConfig();
}

return ($usePrefix && isset($this->config->EZproxy->host))
? $this->config->EZproxy->host . '/login?qurl=' . urlencode($url)
: $url;
}

/**
* Return the configured prefixLinks setting.
*
* @return bool The configured setting, or the default
*/
protected function checkConfig()
{
return $this->config->EZproxy->prefixLinks ?? true;
}

/**
* Check whether the given URL requires the proxy prefix. Cache the response.
*
* @param string $url The raw URL to check
*
* @return mixed Whether the URL should be prefixed, or null if it can't be determined
*/
protected function checkUrl($url)
{
$domain = parse_url($url, PHP_URL_SCHEME)
. '://'
. parse_url($url, PHP_URL_HOST);
$cacheKey = "proxyUrl-domainToUsePrefix-$domain";
$usePrefix = $this->getCachedData($cacheKey);
if (null === $usePrefix) {
$usePrefix = $this->queryWebService($domain);
$this->putCachedData($cacheKey, $usePrefix);
}
return $usePrefix;
}

/**
* Query the web service on whether to prefix URLs to a given domain.
*
* @param $domain The domain
*
* @return mixed Whether the URL should be prefixed, or null if it can't be determined
*/
protected function queryWebService($domain)
{
$prefixLinksWebServiceUrl = $this->config->EZproxy->prefixLinksWebServiceUrl;
try {
$response = $this->httpService->get($prefixLinksWebServiceUrl, ['url' => $domain]);
$responseData = trim($response->getContent());
} catch (Exception $ex) {
$this->logError('Exception during EZproxy web service request: ' . $ex->getMessage());
return null;
}
return '1' === $responseData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public function __invoke(
}
$config = $container->get(\VuFind\Config\PluginManager::class)
->get('config');
return new $requestedName($config);
$cache = $container->get(\VuFind\Cache\Manager::class)
->getCache('object');
return new $requestedName($config, $cache);
}
}

0 comments on commit 98f700e

Please sign in to comment.