Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
50.00% |
3 / 6 |
|
40.00% |
2 / 5 |
CRAP | |
0.00% |
0 / 1 |
| AbstractAuthType | |
50.00% |
3 / 6 |
|
40.00% |
2 / 5 |
8.12 | |
0.00% |
0 / 1 |
| call | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| getAuthClass | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| getAuthProperties | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| getTemplate | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| __toPhpCode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setInstance | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setCredentials | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getInstance | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getCredentials | |
100.00% |
2 / 2 |
|
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) 2018 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | * @author Alexander Zagovorichev <olexander.zagovorychev@1pt.com> |
| 21 | */ |
| 22 | |
| 23 | namespace oat\tao\model\auth; |
| 24 | |
| 25 | use oat\generis\model\OntologyAwareTrait; |
| 26 | use oat\oatbox\PhpSerializable; |
| 27 | use Psr\Http\Message\RequestInterface; |
| 28 | use Psr\Http\Message\ResponseInterface; |
| 29 | |
| 30 | /** |
| 31 | * Class AbstractAuthType |
| 32 | * @package oat\tao\model\auth |
| 33 | */ |
| 34 | abstract class AbstractAuthType implements PhpSerializable |
| 35 | { |
| 36 | use OntologyAwareTrait; |
| 37 | |
| 38 | /** @var \core_kernel_classes_Resource The resource which has authorizations */ |
| 39 | private $instance = null; |
| 40 | |
| 41 | /** @var array */ |
| 42 | protected $credentials = []; |
| 43 | |
| 44 | /** |
| 45 | * Call a request through current authenticator |
| 46 | * |
| 47 | * @param RequestInterface $request |
| 48 | * @param array $clientOptions Http client options |
| 49 | * @return ResponseInterface |
| 50 | * @throws \common_exception_InvalidArgumentType |
| 51 | */ |
| 52 | abstract public function call(RequestInterface $request, array $clientOptions = []); |
| 53 | |
| 54 | /** |
| 55 | * RDF class or AbstractCredentials of the AuthType |
| 56 | * @param array $parameters |
| 57 | * @return \core_kernel_classes_Class | AbstractCredentials |
| 58 | */ |
| 59 | abstract public function getAuthClass($parameters = []); |
| 60 | |
| 61 | /** |
| 62 | * All fields to configure current authenticator |
| 63 | * |
| 64 | * @return array |
| 65 | */ |
| 66 | abstract public function getAuthProperties(); |
| 67 | /** |
| 68 | * Returns template for the current instance (or empty template for the default authorization) with credentials |
| 69 | * |
| 70 | * @return string |
| 71 | * @throws \common_exception_InvalidArgumentType |
| 72 | */ |
| 73 | abstract public function getTemplate(); |
| 74 | /** |
| 75 | * (non-PHPdoc) |
| 76 | * @see \oat\oatbox\PhpSerializable::__toPhpCode() |
| 77 | */ |
| 78 | public function __toPhpCode() |
| 79 | { |
| 80 | return 'new ' . get_class($this) . '()'; |
| 81 | } |
| 82 | /** |
| 83 | * @deprecated Please use setCredentials method with array of credentials for current auth type |
| 84 | * Set the instance that contain authentication options |
| 85 | * |
| 86 | * @param \core_kernel_classes_Resource $instance |
| 87 | */ |
| 88 | public function setInstance(\core_kernel_classes_Resource $instance = null) |
| 89 | { |
| 90 | $this->instance = $instance; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @param array $credentials |
| 95 | */ |
| 96 | public function setCredentials($credentials = []) |
| 97 | { |
| 98 | $this->credentials = $credentials; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * @deprecated Please use getCredentials for getting credentials for current auth type |
| 103 | * Get the instance that contain authentication options |
| 104 | * |
| 105 | * @return \core_kernel_classes_Resource |
| 106 | */ |
| 107 | public function getInstance() |
| 108 | { |
| 109 | return $this->instance; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * @return array |
| 114 | */ |
| 115 | protected function getCredentials() |
| 116 | { |
| 117 | $credentialsClass = $this->getAuthClass($this->credentials); |
| 118 | return $credentialsClass->getProperties(); |
| 119 | } |
| 120 | } |