1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
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
10
class
Token
extends
Base
11
{
12
protected
const
ERROR_RESTRICTED_BY_SIGN_CHECK
=
'restricted_by_sign'
;
13
15
protected
$entityHeaderName
;
16
18
protected
$tokenHeaderName
;
19
21
protected
$getEntityClosure
;
22
23
final
public
function
__construct
(\Closure
$getEntityClosure
)
24
{
25
$this->entityHeaderName =
Service\Token::getEntityHeader
();
26
$this->tokenHeaderName =
Service\Token::getTokenHeader
();
27
$this->getEntityClosure =
$getEntityClosure
;
28
29
parent::__construct();
30
}
31
32
final
public
function
onBeforeAction
(
Event
$event
)
33
{
34
$entityValue = (string)Context::getCurrent()->getRequest()->getHeader($this->entityHeaderName);
35
$tokenValue = (string)Context::getCurrent()->getRequest()->getHeader($this->tokenHeaderName);
36
37
if
(!$this->
check
($entityValue, $tokenValue))
38
{
39
Context::getCurrent()->getResponse()->setStatus(403);
40
$this->
addError
(
new
Error
(
41
'Access restricted by sign check'
,
42
self::ERROR_RESTRICTED_BY_SIGN_CHECK
43
));
44
45
return
new
EventResult
(EventResult::ERROR,
null
,
null
, $this);
46
}
47
48
return
null
;
49
}
50
51
protected
function
check
(
string
$entityValue =
''
,
string
$tokenValue =
''
): bool
52
{
53
global
$USER
;
54
55
$result
=
false
;
56
try
57
{
58
$result
= ($entityValue === (
new
Service\Token
(
$USER
->getId()))->unsign($tokenValue, ($this->getEntityClosure)()));
59
}
60
catch
(\
Exception
$e)
61
{
62
}
63
64
return
$result
;
65
}
66
}
Bitrix\Main\Engine\ActionFilter\Base
Определения
base.php:15
Bitrix\Main\Engine\ActionFilter\Base\addError
addError(Error $error)
Определения
base.php:80
Bitrix\Main\Engine\ActionFilter\Service\Token
Определения
token.php:14
Bitrix\Main\Engine\ActionFilter\Service\Token\getEntityHeader
static getEntityHeader()
Определения
token.php:26
Bitrix\Main\Engine\ActionFilter\Service\Token\getTokenHeader
static getTokenHeader()
Определения
token.php:31
Bitrix\Main\Engine\ActionFilter\Token
Определения
token.php:11
Bitrix\Main\Engine\ActionFilter\Token\$entityHeaderName
$entityHeaderName
Определения
token.php:15
Bitrix\Main\Engine\ActionFilter\Token\$tokenHeaderName
$tokenHeaderName
Определения
token.php:18
Bitrix\Main\Engine\ActionFilter\Token\__construct
__construct(\Closure $getEntityClosure)
Определения
token.php:23
Bitrix\Main\Engine\ActionFilter\Token\ERROR_RESTRICTED_BY_SIGN_CHECK
const ERROR_RESTRICTED_BY_SIGN_CHECK
Определения
token.php:12
Bitrix\Main\Engine\ActionFilter\Token\$getEntityClosure
$getEntityClosure
Определения
token.php:21
Bitrix\Main\Engine\ActionFilter\Token\onBeforeAction
onBeforeAction(Event $event)
Определения
token.php:32
Bitrix\Main\Engine\ActionFilter\Token\check
check(string $entityValue='', string $tokenValue='')
Определения
token.php:51
Bitrix\Main\Error
Определения
error.php:15
Bitrix\Main\Event
Определения
event.php:5
Bitrix\Main\EventResult
Определения
eventresult.php:5
$result
$result
Определения
get_property_values.php:14
$USER
global $USER
Определения
csv_new_run.php:40
Bitrix\Main\Engine\Exception
Определения
actionconfigurationexception.php:5
$event
$event
Определения
prolog_after.php:141
bitrix
modules
main
lib
engine
actionfilter
token.php
Создано системой
1.14.0