Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
84.62% |
11 / 13 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
| ToolKeyChainRepository | |
84.62% |
11 / 13 |
|
33.33% |
1 / 3 |
5.09 | |
0.00% |
0 / 1 |
| find | |
90.91% |
10 / 11 |
|
0.00% |
0 / 1 |
3.01 | |||
| findByKeySetName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getLtiProviderService | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 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\models\classes\Security\DataAccess\Repository; |
| 24 | |
| 25 | use common_exception_NoImplementation; |
| 26 | use OAT\Library\Lti1p3Core\Security\Key\Key; |
| 27 | use OAT\Library\Lti1p3Core\Security\Key\KeyChain; |
| 28 | use OAT\Library\Lti1p3Core\Security\Key\KeyChainInterface; |
| 29 | use OAT\Library\Lti1p3Core\Security\Key\KeyChainRepositoryInterface; |
| 30 | use oat\oatbox\service\ConfigurableService; |
| 31 | use oat\taoLti\models\classes\LtiProvider\InvalidLtiProviderException; |
| 32 | use oat\taoLti\models\classes\LtiProvider\LtiProviderService; |
| 33 | |
| 34 | class ToolKeyChainRepository extends ConfigurableService implements KeyChainRepositoryInterface |
| 35 | { |
| 36 | /** |
| 37 | * @throws InvalidLtiProviderException |
| 38 | */ |
| 39 | public function find(string $identifier): ?KeyChainInterface |
| 40 | { |
| 41 | $ltiProvider = $this->getLtiProviderService()->searchById($identifier); |
| 42 | |
| 43 | if (!$ltiProvider) { |
| 44 | throw new InvalidLtiProviderException('Lti Provider is not found'); |
| 45 | } |
| 46 | |
| 47 | if (empty($ltiProvider->getToolPublicKey())) { |
| 48 | return null; |
| 49 | } |
| 50 | |
| 51 | return new KeyChain( |
| 52 | $ltiProvider->getId(), |
| 53 | $ltiProvider->getId(), |
| 54 | new Key($ltiProvider->getToolPublicKey()), |
| 55 | new Key('') |
| 56 | ); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * @throws common_exception_NoImplementation |
| 61 | */ |
| 62 | public function findByKeySetName(string $keySetName): array |
| 63 | { |
| 64 | throw new common_exception_NoImplementation(); |
| 65 | } |
| 66 | |
| 67 | private function getLtiProviderService(): LtiProviderService |
| 68 | { |
| 69 | return $this->getServiceLocator()->get(LtiProviderService::SERVICE_ID); |
| 70 | } |
| 71 | } |