Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| KvNonceStore | |
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| isValid | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
20 | |||
| getPersistence | |
0.00% |
0 / 2 |
|
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) 2013 (original work) (update and modification) Open Assessment Technologies SA |
| 19 | * (under the project TAO-PRODUCT); |
| 20 | */ |
| 21 | |
| 22 | namespace oat\tao\model\oauth\nonce; |
| 23 | |
| 24 | use oat\oatbox\service\ConfigurableService; |
| 25 | |
| 26 | /** |
| 27 | * @author Joel Bout, <joel@taotesting.com> |
| 28 | */ |
| 29 | class KvNonceStore extends ConfigurableService implements NonceStore |
| 30 | { |
| 31 | public const OPTION_PERSISTENCE = 'persistence'; |
| 32 | public const OPTION_TTL = 'ttl'; |
| 33 | |
| 34 | public const DEFAULT_TTL = 1800; |
| 35 | |
| 36 | public const PREFIX = 'nonce_'; |
| 37 | |
| 38 | public function isValid($id) |
| 39 | { |
| 40 | $ttl = $this->hasOption(self::OPTION_TTL) ? $this->getOption(self::OPTION_TTL) : self::DEFAULT_TTL; |
| 41 | if ($this->getPersistence()->supportsFeature(\common_persistence_KeyValuePersistence::FEATURE_NX)) { |
| 42 | return $this->getPersistence()->set(self::PREFIX . $id, 't', $ttl, true); |
| 43 | } else { |
| 44 | if ($this->getPersistence()->exists(self::PREFIX . $id)) { |
| 45 | return false; |
| 46 | } |
| 47 | return $this->getPersistence()->set(self::PREFIX . $id, 't', $ttl); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @return \common_persistence_KeyValuePersistence |
| 53 | */ |
| 54 | protected function getPersistence() |
| 55 | { |
| 56 | $pm = $this->getServiceLocator()->get(\common_persistence_Manager::SERVICE_ID); |
| 57 | return $pm->getPersistenceById($this->getOption(self::OPTION_PERSISTENCE)); |
| 58 | } |
| 59 | } |