|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (C) 2016 SURFnet. |
|
4
|
|
|
* |
|
5
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
6
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
7
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
8
|
|
|
* License, or (at your option) any later version. |
|
9
|
|
|
* |
|
10
|
|
|
* This program is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13
|
|
|
* GNU Affero General Public License for more details. |
|
14
|
|
|
* |
|
15
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
16
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17
|
|
|
*/ |
|
18
|
|
|
namespace SURFnet\VPN\Server\GroupProvider; |
|
19
|
|
|
|
|
20
|
|
|
use SURFnet\VPN\Server\GroupProviderInterface; |
|
21
|
|
|
|
|
22
|
|
|
class StaticProvider implements GroupProviderInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** @var array */ |
|
25
|
|
|
private $configData; |
|
26
|
|
|
|
|
27
|
|
|
public function __construct(array $configData) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->configData = $configData; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function getGroups($userId) |
|
33
|
|
|
{ |
|
34
|
|
|
if (!is_array($this->configData)) { |
|
35
|
|
|
return []; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
$memberOf = []; |
|
39
|
|
|
foreach ($this->configData as $groupId => $groupEntry) { |
|
40
|
|
|
if (!is_array($groupEntry)) { |
|
41
|
|
|
continue; |
|
42
|
|
|
} |
|
43
|
|
|
$displayName = $groupId; |
|
44
|
|
|
|
|
45
|
|
|
if (!array_key_exists('members', $groupEntry)) { |
|
46
|
|
|
continue; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
if (!in_array($userId, $groupEntry['members'])) { |
|
50
|
|
|
continue; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
if (array_key_exists('displayName', $groupEntry)) { |
|
54
|
|
|
$displayName = $groupEntry['displayName']; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$memberOf[] = [ |
|
58
|
|
|
'id' => $groupId, |
|
59
|
|
|
'displayName' => $displayName, |
|
60
|
|
|
]; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
return $memberOf; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|