Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ShibbolethFactory
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 1
 __invoke
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
6
 getConfigurationLoader
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3/**
4 * Factory for Shibboleth authentication module.
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2019.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2,
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 *
23 * @category VuFind
24 * @package  Authentication
25 * @author   Demian Katz <demian.katz@villanova.edu>
26 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
27 * @link     https://vufind.org/wiki/development Wiki
28 */
29
30namespace VuFind\Auth;
31
32use Laminas\ServiceManager\Exception\ServiceNotCreatedException;
33use Laminas\ServiceManager\Exception\ServiceNotFoundException;
34use Psr\Container\ContainerExceptionInterface as ContainerException;
35use Psr\Container\ContainerInterface;
36use VuFind\Auth\Shibboleth\MultiIdPConfigurationLoader;
37use VuFind\Auth\Shibboleth\SingleIdPConfigurationLoader;
38
39/**
40 * Factory for Shibboleth authentication module.
41 *
42 * @category VuFind
43 * @package  Authentication
44 * @author   Demian Katz <demian.katz@villanova.edu>
45 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
46 * @link     https://vufind.org/wiki/development Wiki
47 */
48class ShibbolethFactory implements \Laminas\ServiceManager\Factory\FactoryInterface
49{
50    public const SHIBBOLETH_CONFIG_FILE_NAME = 'Shibboleth';
51
52    /**
53     * Create an object
54     *
55     * @param ContainerInterface $container     Service manager
56     * @param string             $requestedName Service being created
57     * @param null|array         $options       Extra options (optional)
58     *
59     * @return object
60     *
61     * @throws ServiceNotFoundException if unable to resolve the service.
62     * @throws ServiceNotCreatedException if an exception is raised when
63     * creating a service.
64     * @throws ContainerException&\Throwable if any other error occurs
65     */
66    public function __invoke(
67        ContainerInterface $container,
68        $requestedName,
69        array $options = null
70    ) {
71        if (!empty($options)) {
72            throw new \Exception('Unexpected options sent to factory.');
73        }
74        $loader = $this->getConfigurationLoader($container);
75        $request = $container->get('Request');
76        return new $requestedName(
77            $container->get(\Laminas\Session\SessionManager::class),
78            $loader,
79            $request,
80            $container->get(\VuFind\Auth\ILSAuthenticator::class)
81        );
82    }
83
84    /**
85     * Return configuration loader for shibboleth
86     *
87     * @param ContainerInterface $container Service manager
88     *
89     * @return configuration loader
90     */
91    public function getConfigurationLoader(ContainerInterface $container)
92    {
93        $configManager = $container->get(\VuFind\Config\PluginManager::class);
94        $config = $configManager->get('config');
95        $override = $config->Shibboleth->allow_configuration_override ?? false;
96        if ($override) {
97            $shibConfig = $configManager->get(self::SHIBBOLETH_CONFIG_FILE_NAME);
98            return new MultiIdPConfigurationLoader($config, $shibConfig);
99        }
100        return new SingleIdPConfigurationLoader($config);
101    }
102}