Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
authtype.php
1<?php
2
4
9
14class 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}