1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* MFA factor interface.
|
|
|
19 |
*
|
|
|
20 |
* @package tool_mfa
|
|
|
21 |
* @author Mikhail Golenkov <golenkovm@gmail.com>
|
|
|
22 |
* @copyright Catalyst IT
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
namespace tool_mfa\local\factor;
|
|
|
27 |
|
|
|
28 |
use stdClass;
|
|
|
29 |
|
|
|
30 |
interface object_factor {
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* Returns true if factor is enabled, otherwise false.
|
|
|
34 |
*
|
|
|
35 |
* @return bool
|
|
|
36 |
* @throws \dml_exception
|
|
|
37 |
*/
|
|
|
38 |
public function is_enabled(): bool;
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
* Returns configured factor weight.
|
|
|
42 |
*
|
|
|
43 |
* @return int
|
|
|
44 |
* @throws \dml_exception
|
|
|
45 |
*/
|
|
|
46 |
public function get_weight(): int;
|
|
|
47 |
|
|
|
48 |
/**
|
|
|
49 |
* Returns factor name from language string.
|
|
|
50 |
*
|
|
|
51 |
* @return string
|
|
|
52 |
* @throws \coding_exception
|
|
|
53 |
*/
|
|
|
54 |
public function get_display_name(): string;
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
* Returns factor info from language string.
|
|
|
58 |
*
|
|
|
59 |
* @return string
|
|
|
60 |
* @throws \coding_exception
|
|
|
61 |
*/
|
|
|
62 |
public function get_info(): string;
|
|
|
63 |
|
|
|
64 |
/**
|
|
|
65 |
* Defines setup_factor form definition page for particular factor.
|
|
|
66 |
*
|
|
|
67 |
* @param \MoodleQuickForm $mform
|
|
|
68 |
* @return \MoodleQuickForm $mform
|
|
|
69 |
* @throws \coding_exception
|
|
|
70 |
*/
|
|
|
71 |
public function setup_factor_form_definition(\MoodleQuickForm $mform): \MoodleQuickForm;
|
|
|
72 |
|
|
|
73 |
/**
|
|
|
74 |
* Defines setup_factor form definition page after form data has been set.
|
|
|
75 |
*
|
|
|
76 |
* @param \MoodleQuickForm $mform
|
|
|
77 |
* @return \MoodleQuickForm $mform
|
|
|
78 |
* @throws \coding_exception
|
|
|
79 |
*/
|
|
|
80 |
public function setup_factor_form_definition_after_data(\MoodleQuickForm $mform): \MoodleQuickForm;
|
|
|
81 |
|
|
|
82 |
/**
|
|
|
83 |
* Implements setup_factor form validation for particular factor.
|
|
|
84 |
* Returns an array of errors, where array key = field id and array value = error text.
|
|
|
85 |
*
|
|
|
86 |
* @param array $data
|
|
|
87 |
* @return array
|
|
|
88 |
*/
|
|
|
89 |
public function setup_factor_form_validation(array $data): array;
|
|
|
90 |
|
|
|
91 |
/**
|
|
|
92 |
* Defines login form definition page for particular factor.
|
|
|
93 |
*
|
|
|
94 |
* @param \MoodleQuickForm $mform
|
|
|
95 |
* @return \MoodleQuickForm $mform
|
|
|
96 |
* @throws \coding_exception
|
|
|
97 |
*/
|
|
|
98 |
public function login_form_definition(\MoodleQuickForm $mform): \MoodleQuickForm;
|
|
|
99 |
|
|
|
100 |
/**
|
|
|
101 |
* Defines login form definition page after form data has been set.
|
|
|
102 |
*
|
|
|
103 |
* @param \MoodleQuickForm $mform
|
|
|
104 |
* @return \MoodleQuickForm $mform
|
|
|
105 |
* @throws \coding_exception
|
|
|
106 |
*/
|
|
|
107 |
public function login_form_definition_after_data(\MoodleQuickForm $mform): \MoodleQuickForm;
|
|
|
108 |
|
|
|
109 |
/**
|
|
|
110 |
* Implements login form validation for particular factor.
|
|
|
111 |
* Returns an array of errors, where array key = field id and array value = error text.
|
|
|
112 |
*
|
|
|
113 |
* @param array $data
|
|
|
114 |
* @return array
|
|
|
115 |
*/
|
|
|
116 |
public function login_form_validation(array $data): array;
|
|
|
117 |
|
|
|
118 |
/**
|
|
|
119 |
* Setups in given factor when the form is cancelled
|
|
|
120 |
*
|
|
|
121 |
* @param int $factorid
|
|
|
122 |
* @return void
|
|
|
123 |
*/
|
|
|
124 |
public function setup_factor_form_is_cancelled(int $factorid): void;
|
|
|
125 |
|
|
|
126 |
/**
|
|
|
127 |
* Setup submit button string in given factor
|
|
|
128 |
*
|
|
|
129 |
* @return string|null
|
|
|
130 |
*/
|
|
|
131 |
public function setup_factor_form_submit_button_string(): ?string;
|
|
|
132 |
|
|
|
133 |
/**
|
|
|
134 |
* Setups given factor and adds it to user's active factors list.
|
|
|
135 |
* Returns true if factor has been successfully added, otherwise false.
|
|
|
136 |
*
|
|
|
137 |
* @param stdClass $data
|
|
|
138 |
* @return stdClass|null the factor record, or null.
|
|
|
139 |
*/
|
|
|
140 |
public function setup_user_factor(stdClass $data): stdClass|null;
|
|
|
141 |
|
|
|
142 |
/**
|
|
|
143 |
* Returns an array of all user factors of given type (both active and revoked).
|
|
|
144 |
*
|
|
|
145 |
* @param stdClass $user the user to check against.
|
|
|
146 |
* @return array
|
|
|
147 |
*/
|
|
|
148 |
public function get_all_user_factors(stdClass $user): array;
|
|
|
149 |
|
|
|
150 |
/**
|
|
|
151 |
* Returns an array of active user factor records.
|
|
|
152 |
* Filters get_all_user_factors() output.
|
|
|
153 |
*
|
|
|
154 |
* @param stdClass $user the user to check against.
|
|
|
155 |
* @return array
|
|
|
156 |
*/
|
|
|
157 |
public function get_active_user_factors(stdClass $user): array;
|
|
|
158 |
|
|
|
159 |
/**
|
|
|
160 |
* Returns true if factor class has factor records that might be revoked.
|
|
|
161 |
* It means that user can revoke factor record from their profile.
|
|
|
162 |
*
|
|
|
163 |
* @return bool
|
|
|
164 |
*/
|
|
|
165 |
public function has_revoke(): bool;
|
|
|
166 |
|
|
|
167 |
/**
|
|
|
168 |
* Marks factor record as revoked.
|
|
|
169 |
* If factorid is not provided, revoke all instances of factor.
|
|
|
170 |
*
|
|
|
171 |
* @param int|null $factorid
|
|
|
172 |
* @return bool
|
|
|
173 |
*/
|
|
|
174 |
public function revoke_user_factor(?int $factorid = null): bool;
|
|
|
175 |
|
|
|
176 |
/**
|
|
|
177 |
* When validation code is correct - update lastverified field for given factor.
|
|
|
178 |
* If factor id is not provided, update all factor entries for user.
|
|
|
179 |
*
|
|
|
180 |
* @param int|null $factorid
|
|
|
181 |
* @return bool|\dml_exception
|
|
|
182 |
*/
|
|
|
183 |
public function update_lastverified(?int $factorid = null): bool|\dml_exception;
|
|
|
184 |
|
|
|
185 |
/**
|
|
|
186 |
* Gets lastverified timestamp.
|
|
|
187 |
*
|
|
|
188 |
* @param int $factorid
|
|
|
189 |
* @return int|bool
|
|
|
190 |
*/
|
|
|
191 |
public function get_lastverified(int $factorid): int|bool;
|
|
|
192 |
|
|
|
193 |
/**
|
|
|
194 |
* Returns true if factor needs to be setup by user and has setup_form.
|
|
|
195 |
*
|
|
|
196 |
* @return bool
|
|
|
197 |
*/
|
|
|
198 |
public function has_setup(): bool;
|
|
|
199 |
|
|
|
200 |
/**
|
|
|
201 |
* If has_setup returns true, decides if the setup buttons should be shown on the preferences page.
|
|
|
202 |
*
|
|
|
203 |
* @return bool
|
|
|
204 |
*/
|
|
|
205 |
public function show_setup_buttons(): bool;
|
|
|
206 |
|
|
|
207 |
/**
|
|
|
208 |
* Returns true if factor requires user input for success or failure during login.
|
|
|
209 |
*
|
|
|
210 |
* @return bool
|
|
|
211 |
*/
|
|
|
212 |
public function has_input(): bool;
|
|
|
213 |
|
|
|
214 |
/**
|
|
|
215 |
* Returns the state of the factor check
|
|
|
216 |
*
|
|
|
217 |
* @return string
|
|
|
218 |
*/
|
|
|
219 |
public function get_state(): string;
|
|
|
220 |
|
|
|
221 |
/**
|
|
|
222 |
* Sets the state of the factor check into the session.
|
|
|
223 |
* Returns whether storing the var was successful.
|
|
|
224 |
*
|
|
|
225 |
* @param string $state
|
|
|
226 |
* @return bool
|
|
|
227 |
*/
|
|
|
228 |
public function set_state(string $state): bool;
|
|
|
229 |
|
|
|
230 |
/**
|
|
|
231 |
* Fires any additional actions required by the factor once the user reaches the pass state.
|
|
|
232 |
*
|
|
|
233 |
* @return void
|
|
|
234 |
*/
|
|
|
235 |
public function post_pass_state(): void;
|
|
|
236 |
|
|
|
237 |
/**
|
|
|
238 |
* Retrieves label for a factorid.
|
|
|
239 |
*
|
|
|
240 |
* @param int $factorid
|
|
|
241 |
* @return string|\dml_exception
|
|
|
242 |
*/
|
|
|
243 |
public function get_label(int $factorid): string|\dml_exception;
|
|
|
244 |
|
|
|
245 |
/**
|
|
|
246 |
* Returns a list of urls to not redirect from.
|
|
|
247 |
*
|
|
|
248 |
* @return array
|
|
|
249 |
*/
|
|
|
250 |
public function get_no_redirect_urls(): array;
|
|
|
251 |
|
|
|
252 |
/**
|
|
|
253 |
* Returns all possible states for a user.
|
|
|
254 |
*
|
|
|
255 |
* @param stdClass $user
|
|
|
256 |
* @return array
|
|
|
257 |
*/
|
|
|
258 |
public function possible_states(stdClass $user): array;
|
|
|
259 |
|
|
|
260 |
/**
|
|
|
261 |
* Return summary condition for passing factor.
|
|
|
262 |
*
|
|
|
263 |
* @return string
|
|
|
264 |
*/
|
|
|
265 |
public function get_summary_condition(): string;
|
|
|
266 |
|
|
|
267 |
/**
|
|
|
268 |
* Checks whether the factor combination is valid based on factor behaviour.
|
|
|
269 |
* E.g. a combination with nosetup and another factor is not valid,
|
|
|
270 |
* as you cannot pass nosetup with another factor.
|
|
|
271 |
*
|
|
|
272 |
* @param array $combination array of factors that make up the combination
|
|
|
273 |
* @return bool
|
|
|
274 |
*/
|
|
|
275 |
public function check_combination(array $combination): bool;
|
|
|
276 |
|
|
|
277 |
/**
|
|
|
278 |
* Gets the string for setup button on preferences page.
|
|
|
279 |
*
|
|
|
280 |
* @return string the string to display on the button.
|
|
|
281 |
*/
|
|
|
282 |
public function get_setup_string(): string;
|
|
|
283 |
|
|
|
284 |
/**
|
|
|
285 |
* Deletes all instances of a factor for user.
|
|
|
286 |
*
|
|
|
287 |
* @param stdClass $user the user to delete for.
|
|
|
288 |
* @return void
|
|
|
289 |
*/
|
|
|
290 |
public function delete_factor_for_user(stdClass $user): void;
|
|
|
291 |
|
|
|
292 |
/**
|
|
|
293 |
* Process a cancel action from a user.
|
|
|
294 |
*
|
|
|
295 |
* @return void
|
|
|
296 |
*/
|
|
|
297 |
public function process_cancel_action(): void;
|
|
|
298 |
|
|
|
299 |
/**
|
|
|
300 |
* Hook point for global auth form action hooks.
|
|
|
301 |
*
|
|
|
302 |
* @param \MoodleQuickForm $mform Form to inject global elements into.
|
|
|
303 |
* @return void
|
|
|
304 |
*/
|
|
|
305 |
public function global_definition(\MoodleQuickForm $mform): void;
|
|
|
306 |
|
|
|
307 |
/**
|
|
|
308 |
* Hook point for global auth form action hooks.
|
|
|
309 |
*
|
|
|
310 |
* @param \MoodleQuickForm $mform Form to inject global elements into.
|
|
|
311 |
* @return void
|
|
|
312 |
*/
|
|
|
313 |
public function global_definition_after_data(\MoodleQuickForm $mform): void;
|
|
|
314 |
|
|
|
315 |
/**
|
|
|
316 |
* Hook point for global auth form action hooks.
|
|
|
317 |
*
|
|
|
318 |
* @param array $data Data from the form.
|
|
|
319 |
* @param array $files Files form the form.
|
|
|
320 |
* @return array of errors from validation.
|
|
|
321 |
*/
|
|
|
322 |
public function global_validation(array $data, array $files): array;
|
|
|
323 |
|
|
|
324 |
/**
|
|
|
325 |
* Hook point for global auth form action hooks.
|
|
|
326 |
*
|
|
|
327 |
* @param object $data Data from the form.
|
|
|
328 |
* @return void
|
|
|
329 |
*/
|
|
|
330 |
public function global_submit(object $data): void;
|
|
|
331 |
}
|