1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace SimpleSAML\Module\consent; |
||
6 | |||
7 | use Exception; |
||
8 | use SimpleSAML\Module; |
||
9 | |||
10 | /** |
||
11 | * Base class for consent storage handlers. |
||
12 | * |
||
13 | * @package SimpleSAMLphp |
||
14 | */ |
||
15 | |||
16 | abstract class Store |
||
17 | { |
||
18 | /** |
||
19 | * Constructor for the base class. |
||
20 | * |
||
21 | * This constructor should always be called first in any class which implements this class. |
||
22 | * |
||
23 | * @param array &$config The configuration for this storage handler. |
||
24 | */ |
||
25 | protected function __construct(array &$config) |
||
26 | { |
||
27 | } |
||
28 | |||
29 | |||
30 | /** |
||
31 | * Check for consent. |
||
32 | * |
||
33 | * This function checks whether a given user has authorized the release of the attributes identified by |
||
34 | * $attributeSet from $source to $destination. |
||
35 | * |
||
36 | * @param string $userId The hash identifying the user at an IdP. |
||
37 | * @param string $destinationId A string which identifyes the destination. |
||
38 | * @param string $attributeSet A hash which identifies the attributes. |
||
39 | * |
||
40 | * @return bool True if the user has given consent earlier, false if not |
||
41 | * (or on error). |
||
42 | */ |
||
43 | abstract public function hasConsent(string $userId, string $destinationId, string $attributeSet): bool; |
||
44 | |||
45 | |||
46 | /** |
||
47 | * Save consent. |
||
48 | * |
||
49 | * Called when the user asks for the consent to be saved. If consent information for the given user and destination |
||
50 | * already exists, it should be overwritten. |
||
51 | * |
||
52 | * @param string $userId The hash identifying the user at an IdP. |
||
53 | * @param string $destinationId A string which identifyes the destination. |
||
54 | * @param string $attributeSet A hash which identifies the attributes. |
||
55 | * |
||
56 | * @return bool True if consent is succesfully saved otherwise false. |
||
57 | */ |
||
58 | abstract public function saveConsent(string $userId, string $destinationId, string $attributeSet): bool; |
||
59 | |||
60 | |||
61 | /** |
||
62 | * Delete consent. |
||
63 | * |
||
64 | * Called when a user revokes consent for a given destination. |
||
65 | * |
||
66 | * @param string $userId The hash identifying the user at an IdP. |
||
67 | * @param string $destinationId A string which identifyes the destination. |
||
68 | * |
||
69 | * @return mixed Should be the number of consent deleted. |
||
70 | */ |
||
71 | abstract public function deleteConsent(string $userId, string $destinationId); |
||
72 | |||
73 | |||
74 | /** |
||
75 | * Delete all consents. |
||
76 | * |
||
77 | * Called when a user revokes all consents |
||
78 | * |
||
79 | * @param string $userId The hash identifying the user at an IdP. |
||
80 | * |
||
81 | * @return mixed Should be the number of consent removed |
||
82 | * |
||
83 | * @throws \Exception |
||
84 | */ |
||
85 | public function deleteAllConsents(string $userId) |
||
0 ignored issues
–
show
|
|||
86 | { |
||
87 | throw new Exception('Not implemented: deleteAllConsents()'); |
||
88 | } |
||
89 | |||
90 | |||
91 | /** |
||
92 | * Get statistics for all consent given in the consent store |
||
93 | * |
||
94 | * @return mixed Statistics from the consent store |
||
95 | * |
||
96 | * @throws \Exception |
||
97 | */ |
||
98 | public function getStatistics() |
||
99 | { |
||
100 | throw new Exception('Not implemented: getStatistics()'); |
||
101 | } |
||
102 | |||
103 | |||
104 | /** |
||
105 | * Retrieve consents. |
||
106 | * |
||
107 | * This function should return a list of consents the user has saved. |
||
108 | * |
||
109 | * @param string $userId The hash identifying the user at an IdP. |
||
110 | * |
||
111 | * @return array Array of all destination ids the user has given consent for. |
||
112 | */ |
||
113 | abstract public function getConsents(string $userId): array; |
||
114 | |||
115 | |||
116 | /** |
||
117 | * Parse consent storage configuration. |
||
118 | * |
||
119 | * This function parses the configuration for a consent storage method. An exception will be thrown if |
||
120 | * configuration parsing fails. |
||
121 | * |
||
122 | * @param mixed $config The configuration. |
||
123 | * |
||
124 | * @return \SimpleSAML\Module\consent\Store An object which implements the \SimpleSAML\Module\consent\Store class. |
||
125 | * |
||
126 | * @throws \Exception if the configuration is invalid. |
||
127 | */ |
||
128 | public static function parseStoreConfig($config): Store |
||
129 | { |
||
130 | if (is_string($config)) { |
||
131 | $config = [$config]; |
||
132 | } |
||
133 | |||
134 | if (!is_array($config)) { |
||
135 | throw new Exception('Invalid configuration for consent store option: ' . var_export($config, true)); |
||
136 | } |
||
137 | |||
138 | if (!array_key_exists(0, $config)) { |
||
139 | throw new Exception('Consent store without name given.'); |
||
140 | } |
||
141 | |||
142 | $className = Module::resolveClass( |
||
143 | $config[0], |
||
144 | 'Consent\Store', |
||
145 | '\SimpleSAML\Module\consent\Store', |
||
146 | ); |
||
147 | |||
148 | unset($config[0]); |
||
149 | /** |
||
150 | * @psalm-suppress InvalidStringClass |
||
151 | * @var \SimpleSAML\Module\consent\Store $retval |
||
152 | */ |
||
153 | $retval = new $className($config); |
||
154 | return $retval; |
||
155 | } |
||
156 | } |
||
157 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.