Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 11 |
CRAP | |
0.00% |
0 / 1 |
| common_session_RestrictedSession | |
0.00% |
0 / 17 |
|
0.00% |
0 / 11 |
182 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getUser | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getUserUri | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getUserLabel | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getUserRoles | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| getDataLanguage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getInterfaceLanguage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getUserPropertyValues | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getTimeZone | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| refresh | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| restoreOriginal | |
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) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | /** |
| 23 | * |
| 24 | * RestrictedSession allows a user to reduce his own access roles |
| 25 | * This can be used to test the interface |
| 26 | * |
| 27 | * @access private |
| 28 | * @author Joel Bout, <joel@taotesting.com> |
| 29 | * @package generis |
| 30 | |
| 31 | */ |
| 32 | class common_session_RestrictedSession implements common_session_StatefulSession |
| 33 | { |
| 34 | /** |
| 35 | * real user session that will be restricted |
| 36 | * |
| 37 | * @var common_session_Session |
| 38 | */ |
| 39 | private $internalSession; |
| 40 | |
| 41 | /** |
| 42 | * filter on the users roles |
| 43 | * |
| 44 | * @var array |
| 45 | */ |
| 46 | private $filter; |
| 47 | |
| 48 | /** |
| 49 | * |
| 50 | * @param common_session_Session $session |
| 51 | * @param array $filter |
| 52 | */ |
| 53 | public function __construct(common_session_Session $session, $filter) |
| 54 | { |
| 55 | $this->internalSession = $session; |
| 56 | $this->filter = $filter; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * (non-PHPdoc) |
| 61 | * @see common_session_Session::getUser() |
| 62 | */ |
| 63 | public function getUser() |
| 64 | { |
| 65 | return $this->internalSession->getUser(); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * (non-PHPdoc) |
| 70 | * @see common_session_AbstractSession::getUserUri() |
| 71 | */ |
| 72 | public function getUserUri() |
| 73 | { |
| 74 | return $this->internalSession->getUserUri(); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * (non-PHPdoc) |
| 79 | * @see common_session_Session::getUserLabel() |
| 80 | */ |
| 81 | public function getUserLabel() |
| 82 | { |
| 83 | return $this->internalSession->getUserLabel(); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * (non-PHPdoc) |
| 88 | * @see common_session_AbstractSession::getUserRoles() |
| 89 | */ |
| 90 | public function getUserRoles() |
| 91 | { |
| 92 | $returnValue = $this->internalSession->getUserRoles(); |
| 93 | foreach (array_keys($returnValue) as $key) { |
| 94 | $role = $returnValue[$key]; |
| 95 | if (!in_array($role, $this->filter)) { |
| 96 | unset($returnValue[$key]); |
| 97 | } |
| 98 | } |
| 99 | return $returnValue; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * (non-PHPdoc) |
| 104 | * @see common_session_Session::getDataLanguage() |
| 105 | */ |
| 106 | public function getDataLanguage() |
| 107 | { |
| 108 | return $this->internalSession->getDataLanguage(); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * (non-PHPdoc) |
| 113 | * @see common_session_Session::getInterfaceLanguage() |
| 114 | */ |
| 115 | public function getInterfaceLanguage() |
| 116 | { |
| 117 | return $this->internalSession->getInterfaceLanguage(); |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * (non-PHPdoc) |
| 122 | * @see common_session_Session::getUserPropertyValues() |
| 123 | */ |
| 124 | public function getUserPropertyValues($property) |
| 125 | { |
| 126 | return $this->internalSession->getUserPropertyValues($property); |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * (non-PHPdoc) |
| 131 | * @see common_session_Session::getTimeZone() |
| 132 | */ |
| 133 | public function getTimeZone() |
| 134 | { |
| 135 | return $this->internalSession->getTimeZone(); |
| 136 | } |
| 137 | |
| 138 | |
| 139 | /** |
| 140 | * (non-PHPdoc) |
| 141 | * @see common_session_Session::refresh() |
| 142 | */ |
| 143 | public function refresh() |
| 144 | { |
| 145 | $this->internalSession->refresh(); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Revert back to the original Session |
| 150 | */ |
| 151 | public function restoreOriginal() |
| 152 | { |
| 153 | common_session_SessionManager::startSession($this->internalSession); |
| 154 | } |
| 155 | } |