Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
authtype.php
1
<?php
2
3
namespace
Bitrix\Rest\Engine\ActionFilter
;
4
5
use
Bitrix\Main\Error
;
6
use
Bitrix\Main\Event
;
7
use
Bitrix\Main\EventResult
;
8
use
Bitrix\Rest
;
9
14
class
AuthType
extends
Base
15
{
16
public
const
PASSWORD
= 0b00000001;
17
public
const
APPLICATION
= 0b00000010;
18
public
const
SESSION
= 0b00000100;
19
20
public
const
ALL
= self::APPLICATION | self::PASSWORD |
self::SESSION
;
21
22
public
const
ERROR_INSUFFICIENT_AUTH_TYPE
=
'insufficient_auth_type'
;
23
24
private
$types;
25
26
public
function
__construct
($types)
27
{
28
$this->types = $types;
29
parent::__construct();
30
}
31
32
public
function
onBeforeAction
(
Event
$event)
33
{
34
$scope = $this->
getCurrentAuthType
();
35
if
(($this->types & $scope) === $scope)
36
{
37
return
null
;
38
}
39
40
$this->addError(
new
Error
(
'The request requires higher privileges than provided.'
, self::ERROR_INSUFFICIENT_AUTH_TYPE));
41
42
return
new
EventResult
(EventResult::ERROR,
null
,
null
, $this);
43
}
44
45
protected
function
getCurrentAuthType
() : ?int
46
{
47
$server = $this->
getRestServer
();
48
if
($server)
49
{
50
switch
($server->getAuthType())
51
{
52
case
Rest\APAuth\Auth::AUTH_TYPE:
53
return
static::PASSWORD;
54
case
Rest\OAuth\Auth::AUTH_TYPE:
55
return
static::APPLICATION;
56
case
Rest\SessionAuth\Auth::AUTH_TYPE:
57
return
static::SESSION;
58
}
59
}
60
61
return
null
;
62
}
63
}
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\Event
Definition
event.php:5
Bitrix\Main\EventResult
Definition
eventresult.php:5
Bitrix\Rest\Engine\ActionFilter\AuthType
Definition
authtype.php:15
Bitrix\Rest\Engine\ActionFilter\AuthType\PASSWORD
const PASSWORD
Definition
authtype.php:16
Bitrix\Rest\Engine\ActionFilter\AuthType\onBeforeAction
onBeforeAction(Event $event)
Definition
authtype.php:32
Bitrix\Rest\Engine\ActionFilter\AuthType\getCurrentAuthType
getCurrentAuthType()
Definition
authtype.php:45
Bitrix\Rest\Engine\ActionFilter\AuthType\__construct
__construct($types)
Definition
authtype.php:26
Bitrix\Rest\Engine\ActionFilter\AuthType\ALL
const ALL
Definition
authtype.php:20
Bitrix\Rest\Engine\ActionFilter\AuthType\ERROR_INSUFFICIENT_AUTH_TYPE
const ERROR_INSUFFICIENT_AUTH_TYPE
Definition
authtype.php:22
Bitrix\Rest\Engine\ActionFilter\AuthType\APPLICATION
const APPLICATION
Definition
authtype.php:17
Bitrix\Rest\Engine\ActionFilter\AuthType\SESSION
const SESSION
Definition
authtype.php:18
Bitrix\Rest\Engine\ActionFilter\Base
Definition
base.php:13
Bitrix\Rest\Engine\ActionFilter\Base\getRestServer
getRestServer()
Definition
base.php:28
Bitrix\Rest\Engine\ActionFilter
Definition
authtype.php:3
Bitrix\Rest
Definition
accessexception.php:2
modules
rest
lib
engine
actionfilter
authtype.php
Создано системой
1.10.0