Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
76.47% |
13 / 17 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
MultiIdPConfigurationLoader | |
76.47% |
13 / 17 |
|
50.00% |
1 / 2 |
5.33 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getConfiguration | |
73.33% |
11 / 15 |
|
0.00% |
0 / 1 |
4.30 |
1 | <?php |
2 | |
3 | /** |
4 | * Configuration loader for Multiple IdPs |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * @category VuFind |
9 | * @package Authentication |
10 | * @author Vaclav Rosecky <vaclav.rosecky@mzk.cz> |
11 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
12 | * @link https://vufind.org Main Page |
13 | */ |
14 | |
15 | namespace VuFind\Auth\Shibboleth; |
16 | |
17 | use VuFind\Exception\Auth as AuthException; |
18 | |
19 | /** |
20 | * Configuration loader for Multiple IdPs |
21 | * |
22 | * @category VuFind |
23 | * @package Authentication |
24 | * @author Vaclav Rosecky <vaclav.rosecky@mzk.cz> |
25 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
26 | * @link https://vufind.org Main Page |
27 | */ |
28 | class MultiIdPConfigurationLoader implements |
29 | ConfigurationLoaderInterface, |
30 | \Laminas\Log\LoggerAwareInterface |
31 | { |
32 | use \VuFind\Log\LoggerAwareTrait; |
33 | |
34 | /** |
35 | * Configured IdPs with entityId and overridden attribute mapping |
36 | * |
37 | * @var \Laminas\Config\Config |
38 | */ |
39 | protected $config; |
40 | |
41 | /** |
42 | * Configured IdPs with entityId and overridden attribute mapping |
43 | * |
44 | * @var \Laminas\Config\Config |
45 | */ |
46 | protected $shibConfig; |
47 | |
48 | /** |
49 | * Constructor |
50 | * |
51 | * @param \Laminas\Config\Config $config Configuration |
52 | * @param \Laminas\Config\Config $shibConfig Shibboleth configuration for IdPs |
53 | */ |
54 | public function __construct( |
55 | \Laminas\Config\Config $config, |
56 | \Laminas\Config\Config $shibConfig |
57 | ) { |
58 | $this->config = $config; |
59 | $this->shibConfig = $shibConfig; |
60 | } |
61 | |
62 | /** |
63 | * Return shibboleth configuration. |
64 | * |
65 | * @param string $entityId entity Id |
66 | * |
67 | * @throws \VuFind\Exception\Auth |
68 | * @return array shibboleth configuration |
69 | */ |
70 | public function getConfiguration($entityId) |
71 | { |
72 | $config = $this->config->Shibboleth->toArray(); |
73 | $idpConfig = null; |
74 | $prefix = null; |
75 | foreach ($this->shibConfig as $name => $configuration) { |
76 | if ($entityId == trim($configuration['entityId'])) { |
77 | $idpConfig = $configuration->toArray(); |
78 | $prefix = $name; |
79 | break; |
80 | } |
81 | } |
82 | if ($idpConfig == null) { |
83 | $this->debug( |
84 | "Missing configuration for Idp with entityId: {$entityId})" |
85 | ); |
86 | throw new AuthException('Missing configuration for IdP.'); |
87 | } |
88 | $config = array_merge($config, $idpConfig); |
89 | $config['prefix'] = $prefix; |
90 | return $config; |
91 | } |
92 | } |