Code Coverage  | 
      ||||||||||
Lines  | 
       Functions and Methods  | 
       Classes and Traits  | 
      ||||||||
| Total |         | 
       100.00%  | 
       11 / 11  | 
               | 
       100.00%  | 
       3 / 3  | 
       CRAP |         | 
       100.00%  | 
       1 / 1  | 
      
| LisAuthAdapter |         | 
       100.00%  | 
       11 / 11  | 
               | 
       100.00%  | 
       3 / 3  | 
       4 |         | 
       100.00%  | 
       1 / 1  | 
      
| __construct |         | 
       100.00%  | 
       1 / 1  | 
               | 
       100.00%  | 
       1 / 1  | 
       1 | |||
| authenticate |         | 
       100.00%  | 
       9 / 9  | 
               | 
       100.00%  | 
       1 / 1  | 
       2 | |||
| getLisOauthService |         | 
       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) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); | 
| 19 | */ | 
| 20 | |
| 21 | namespace oat\taoLti\models\classes\Lis; | 
| 22 | |
| 23 | use common_http_InvalidSignatureException; | 
| 24 | use common_user_auth_Adapter; | 
| 25 | use common_user_User; | 
| 26 | use oat\tao\model\oauth\lockout\LockOutException; | 
| 27 | use Psr\Http\Message\ServerRequestInterface; | 
| 28 | use Zend\ServiceManager\ServiceLocatorAwareInterface; | 
| 29 | use Zend\ServiceManager\ServiceLocatorAwareTrait; | 
| 30 | |
| 31 | class LisAuthAdapter implements common_user_auth_Adapter, ServiceLocatorAwareInterface | 
| 32 | { | 
| 33 | use ServiceLocatorAwareTrait; | 
| 34 | |
| 35 | /** @var ServerRequestInterface */ | 
| 36 | protected $request; | 
| 37 | |
| 38 | public function __construct(ServerRequestInterface $request) | 
| 39 | { | 
| 40 | $this->request = $request; | 
| 41 | } | 
| 42 | |
| 43 | /** | 
| 44 | * @return common_user_User|LtiProviderUser | 
| 45 | * @throws LisAuthAdapterException | 
| 46 | */ | 
| 47 | public function authenticate() | 
| 48 | { | 
| 49 | $oauthService = $this->getLisOauthService(); | 
| 50 | try { | 
| 51 | /** @var LisOAuthConsumer $oauthConsumer */ | 
| 52 | [$oauthConsumer, $token] = $oauthService->validatePsrRequest($this->request); | 
| 53 | } catch (common_http_InvalidSignatureException | LockOutException $exception) { | 
| 54 | // to meet interface requirement | 
| 55 | throw new LisAuthAdapterException( | 
| 56 | $exception->getMessage(), | 
| 57 | $exception->getCode(), | 
| 58 | $exception | 
| 59 | ); | 
| 60 | } | 
| 61 | |
| 62 | return new LtiProviderUser($oauthConsumer->getLtiProvider()); | 
| 63 | } | 
| 64 | |
| 65 | /** | 
| 66 | * @return LisOauthService | 
| 67 | */ | 
| 68 | private function getLisOauthService() | 
| 69 | { | 
| 70 | /** @noinspection PhpIncompatibleReturnTypeInspection */ | 
| 71 | return $this->getServiceLocator()->get(LisOauthService::SERVICE_ID); | 
| 72 | } | 
| 73 | } |