1 | <?php |
||
22 | class ValidateAuthenticationFilter extends ActionFilter |
||
23 | { |
||
24 | /** |
||
25 | * @var Closure |
||
26 | */ |
||
27 | public $denyCallback; |
||
28 | |||
29 | /** |
||
30 | * @var bool |
||
31 | */ |
||
32 | public $invert = false; |
||
33 | |||
34 | public function beforeAction($action) |
||
35 | { |
||
36 | /** @var MfaIdentityInterface $identity */ |
||
37 | $identity = Yii::$app->user->identity; |
||
38 | |||
39 | if (Yii::$app->user->isGuest || $identity === null) { |
||
40 | return true; |
||
41 | } |
||
42 | |||
43 | try { |
||
44 | $this->validateAuthentication($identity); |
||
45 | } catch (AuthenticationException $e) { |
||
46 | return $this->denyAccess($e); |
||
47 | } |
||
48 | |||
49 | return true; |
||
50 | } |
||
51 | |||
52 | public function validateAuthentication(MfaIdentityInterface $identity) |
||
60 | |||
61 | /** |
||
62 | * @param AuthenticationException $exception |
||
63 | * @return mixed |
||
64 | */ |
||
65 | protected function denyAccess($exception) |
||
73 | } |
||
74 |