Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| KeyChainView | |
0.00% |
0 / 18 |
|
0.00% |
0 / 5 |
30 | |
0.00% |
0 / 1 |
| view | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| getSafeKeyChains | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| getJwksRepository | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getKeyChainRepository | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getUrlGenerator | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2020 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\taoLti\controller; |
| 24 | |
| 25 | use OAT\Library\Lti1p3Core\Security\Key\KeyChainRepositoryInterface; |
| 26 | use oat\tao\helpers\UrlHelper; |
| 27 | use oat\tao\model\security\Business\Contract\JwksRepositoryInterface; |
| 28 | use oat\tao\model\security\Business\Domain\Key\KeyChain; |
| 29 | use oat\tao\model\security\Business\Domain\Key\KeyChainQuery; |
| 30 | use oat\taoLti\models\classes\Security\DataAccess\Repository\CachedPlatformJwksRepository; |
| 31 | use oat\taoLti\models\classes\Security\DataAccess\Repository\CachedPlatformKeyChainRepository; |
| 32 | use tao_actions_CommonModule as CommonModule; |
| 33 | |
| 34 | class KeyChainView extends CommonModule |
| 35 | { |
| 36 | public function view(): void |
| 37 | { |
| 38 | $this->setData('lti-jwks', json_encode($this->getJwksRepository()->find())); |
| 39 | |
| 40 | $this->setData('lti-key-chains', json_encode($this->getSafeKeyChains())); |
| 41 | |
| 42 | $this->setData( |
| 43 | 'lti-key-chain-generate-url', |
| 44 | $this->getUrlGenerator()->buildUrl('generate', 'KeyChainGenerator') |
| 45 | ); |
| 46 | |
| 47 | $this->setView('ltiKeyChain/ltiKeyChainGenerate.tpl'); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * @todo Remove or move this method once UX is validated |
| 52 | */ |
| 53 | private function getSafeKeyChains(): array |
| 54 | { |
| 55 | $keyChains = $this->getKeyChainRepository()->findAll(new KeyChainQuery())->getKeyChains(); |
| 56 | |
| 57 | return array_map(function (KeyChain $keyChain) { |
| 58 | return [ |
| 59 | 'identifier' => $keyChain->getIdentifier(), |
| 60 | 'name' => $keyChain->getName(), |
| 61 | 'public' => $keyChain->getPublicKey()->getValue(), |
| 62 | ]; |
| 63 | }, $keyChains); |
| 64 | } |
| 65 | |
| 66 | private function getJwksRepository(): JwksRepositoryInterface |
| 67 | { |
| 68 | return $this->getServiceLocator()->get(CachedPlatformJwksRepository::class); |
| 69 | } |
| 70 | |
| 71 | private function getKeyChainRepository(): CachedPlatformKeyChainRepository |
| 72 | { |
| 73 | return $this->getServiceLocator()->get(CachedPlatformKeyChainRepository::class); |
| 74 | } |
| 75 | |
| 76 | private function getUrlGenerator(): UrlHelper |
| 77 | { |
| 78 | return $this->getServiceLocator()->get(UrlHelper::class); |
| 79 | } |
| 80 | } |