Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
token.php
1
<?php
2
3
namespace
Bitrix\Main\Engine\ActionFilter
;
4
5
use
Bitrix\Main\Context
;
6
use
Bitrix\Main\Error
;
7
use
Bitrix\Main\Event
;
8
use
Bitrix\Main\EventResult
;
9
use
Bitrix\Main\Engine\ActionFilter\Service
;
10
11
class
Token
extends
Base
12
{
13
protected
const
ERROR_RESTRICTED_BY_SIGN_CHECK
=
'restricted_by_sign'
;
14
16
protected
$entityHeaderName
;
17
19
protected
$tokenHeaderName
;
20
22
protected
$getEntityClosure
;
23
24
final
public
function
__construct
(\Closure $getEntityClosure)
25
{
26
$this->entityHeaderName = Service\Token::getEntityHeader();
27
$this->tokenHeaderName = Service\Token::getTokenHeader();
28
$this->getEntityClosure = $getEntityClosure;
29
30
parent::__construct();
31
}
32
33
final
public
function
onBeforeAction
(
Event
$event)
34
{
35
$entityValue = (string)
Context::getCurrent
()->getRequest()->getHeader($this->entityHeaderName);
36
$tokenValue = (string)
Context::getCurrent
()->getRequest()->getHeader($this->tokenHeaderName);
37
38
if
(!$this->
check
($entityValue, $tokenValue))
39
{
40
Context::getCurrent
()->getResponse()->setStatus(403);
41
$this->
addError
(
new
Error
(
42
'Access restricted by sign check'
,
43
self::ERROR_RESTRICTED_BY_SIGN_CHECK
44
));
45
46
return
new
EventResult
(EventResult::ERROR,
null
,
null
, $this);
47
}
48
49
return
null
;
50
}
51
52
protected
function
check
(
string
$entityValue =
''
,
string
$tokenValue =
''
): bool
53
{
54
global $USER;
55
56
$result =
false
;
57
try
58
{
59
$result = ($entityValue === (
new
Service\Token
($USER->getId()))->
unsign
($tokenValue, ($this->getEntityClosure)()));
60
}
61
catch
(\Exception $e)
62
{
63
}
64
65
return
$result;
66
}
67
}
Bitrix\Main\Context\getCurrent
static getCurrent()
Definition
context.php:241
Bitrix\Main\Engine\ActionFilter\Base
Definition
base.php:15
Bitrix\Main\Engine\ActionFilter\Base\addError
addError(Error $error)
Definition
base.php:80
Bitrix\Main\Engine\ActionFilter\Service\Token
Definition
token.php:14
Bitrix\Main\Engine\ActionFilter\Service\Token\unsign
unsign(string $signedValue='', string $payloadEntityValue='')
Definition
token.php:68
Bitrix\Main\Engine\ActionFilter\Token\$entityHeaderName
$entityHeaderName
Definition
token.php:16
Bitrix\Main\Engine\ActionFilter\Token\$tokenHeaderName
$tokenHeaderName
Definition
token.php:19
Bitrix\Main\Engine\ActionFilter\Token\__construct
__construct(\Closure $getEntityClosure)
Definition
token.php:24
Bitrix\Main\Engine\ActionFilter\Token\ERROR_RESTRICTED_BY_SIGN_CHECK
const ERROR_RESTRICTED_BY_SIGN_CHECK
Definition
token.php:13
Bitrix\Main\Engine\ActionFilter\Token\$getEntityClosure
$getEntityClosure
Definition
token.php:22
Bitrix\Main\Engine\ActionFilter\Token\onBeforeAction
onBeforeAction(Event $event)
Definition
token.php:33
Bitrix\Main\Engine\ActionFilter\Token\check
check(string $entityValue='', string $tokenValue='')
Definition
token.php:52
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\Event
Definition
event.php:5
Bitrix\Main\EventResult
Definition
eventresult.php:5
Bitrix\Main\Context
Definition
culture.php:9
Bitrix\Main\Engine\ActionFilter\Service
Definition
token.php:3
Bitrix\Main\Engine\ActionFilter
Definition
authentication.php:4
modules
main
lib
engine
actionfilter
token.php
Создано системой
1.10.0