Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
57.14% |
8 / 14 |
|
40.00% |
2 / 5 |
CRAP | |
0.00% |
0 / 1 |
| Lti1p3OidcLoginAuthenticator | |
57.14% |
8 / 14 |
|
40.00% |
2 / 5 |
8.83 | |
0.00% |
0 / 1 |
| withLoginAuthenticator | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| authenticate | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| getExternalOidcLoginAuthenticator | |
33.33% |
2 / 6 |
|
0.00% |
0 / 1 |
3.19 | |||
| getRegistrationRepository | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getUserAuthenticator | |
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\models\classes\Platform\Service\Oidc; |
| 24 | |
| 25 | use OAT\Library\Lti1p3Core\Security\Oidc\OidcAuthenticator; |
| 26 | use oat\oatbox\service\ConfigurableService; |
| 27 | use oat\taoLti\models\classes\Platform\Repository\Lti1p3RegistrationRepository; |
| 28 | use Psr\Http\Message\ResponseInterface; |
| 29 | use Psr\Http\Message\ServerRequestInterface; |
| 30 | |
| 31 | class Lti1p3OidcLoginAuthenticator extends ConfigurableService implements OidcLoginAuthenticatorInterface |
| 32 | { |
| 33 | /** @var OidcAuthenticator */ |
| 34 | private $loginAuthenticator; |
| 35 | |
| 36 | public function withLoginAuthenticator(OidcAuthenticator $loginAuthenticator): void |
| 37 | { |
| 38 | $this->loginAuthenticator = $loginAuthenticator; |
| 39 | } |
| 40 | |
| 41 | public function authenticate(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface |
| 42 | { |
| 43 | $launchRequest = $this->getExternalOidcLoginAuthenticator() |
| 44 | ->authenticate($request); |
| 45 | |
| 46 | $response->getBody() |
| 47 | ->write($launchRequest->toHtmlRedirectForm()); |
| 48 | |
| 49 | return $response; |
| 50 | } |
| 51 | |
| 52 | private function getExternalOidcLoginAuthenticator(): OidcAuthenticator |
| 53 | { |
| 54 | if (!$this->loginAuthenticator) { |
| 55 | $this->loginAuthenticator = new OidcAuthenticator( |
| 56 | $this->getRegistrationRepository(), |
| 57 | $this->getUserAuthenticator() |
| 58 | ); |
| 59 | } |
| 60 | |
| 61 | return $this->loginAuthenticator; |
| 62 | } |
| 63 | |
| 64 | private function getRegistrationRepository(): Lti1p3RegistrationRepository |
| 65 | { |
| 66 | return $this->getServiceLocator()->get(Lti1p3RegistrationRepository::SERVICE_ID); |
| 67 | } |
| 68 | |
| 69 | private function getUserAuthenticator(): Lti1p3UserAuthenticator |
| 70 | { |
| 71 | return $this->getServiceLocator()->get(Lti1p3UserAuthenticator::class); |
| 72 | } |
| 73 | } |