1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Created by PhpStorm. |
5
|
|
|
* Project: json-rpc-server |
6
|
|
|
* User: sv |
7
|
|
|
* Date: 06.02.2021 |
8
|
|
|
* Time: 11:39 |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
declare(strict_types=1); |
12
|
|
|
|
13
|
|
|
namespace Onnov\JsonRpcServer\Definition; |
14
|
|
|
|
15
|
|
|
use Psr\Log\LogLevel; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class RpcAuthDefinition |
19
|
|
|
* |
20
|
|
|
* @package Onnov\JsonRpcServer\Definition |
21
|
|
|
*/ |
22
|
|
|
class RpcAuthDefinition |
23
|
|
|
{ |
24
|
|
|
use CastableToArray; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Authorisation Error. |
28
|
|
|
* |
29
|
|
|
* @var RpcErrorDefinition |
30
|
|
|
*/ |
31
|
|
|
private $authError; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Procedures not requiring authorization. |
35
|
|
|
* |
36
|
|
|
* @var string[] |
37
|
|
|
*/ |
38
|
|
|
private $procWithoutAuth; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* External authorization result. |
42
|
|
|
* |
43
|
|
|
* @var bool |
44
|
|
|
*/ |
45
|
|
|
private $resultAuth; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* RpcAuthDefinition constructor. |
49
|
|
|
* |
50
|
|
|
* @param mixed[] $data |
51
|
|
|
*/ |
52
|
9 |
|
public function __construct(array $data = []) |
53
|
|
|
{ |
54
|
9 |
|
$this->authError = $data['authError'] ?? new RpcErrorDefinition( |
55
|
9 |
|
[ |
56
|
9 |
|
'code' => -32001, |
57
|
9 |
|
'message' => 'Access denied, you are not authorized', |
58
|
9 |
|
'description' => 'The error occurs if the procedure requires authorization, ' |
59
|
9 |
|
. 'but the user is not authorized.', |
60
|
9 |
|
'logLevel' => LogLevel::INFO, |
61
|
9 |
|
] |
62
|
9 |
|
); |
63
|
9 |
|
$this->procWithoutAuth = $data['procWithoutAuth'] ?? []; |
64
|
9 |
|
$this->resultAuth = $data['resultAuth'] ?? true; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return RpcErrorDefinition |
69
|
|
|
*/ |
70
|
9 |
|
public function getAuthError(): RpcErrorDefinition |
71
|
|
|
{ |
72
|
9 |
|
return $this->authError; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param RpcErrorDefinition $authError |
77
|
|
|
* @return RpcAuthDefinition |
78
|
|
|
*/ |
79
|
|
|
public function setAuthError(RpcErrorDefinition $authError): self |
80
|
|
|
{ |
81
|
|
|
$this->authError = $authError; |
82
|
|
|
|
83
|
|
|
return $this; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return string[] |
88
|
|
|
*/ |
89
|
2 |
|
public function getProcWithoutAuth(): array |
90
|
|
|
{ |
91
|
2 |
|
return $this->procWithoutAuth; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param string[] $procWithoutAuth |
96
|
|
|
* @return RpcAuthDefinition |
97
|
|
|
*/ |
98
|
|
|
public function setProcWithoutAuth(array $procWithoutAuth): self |
99
|
|
|
{ |
100
|
|
|
$this->procWithoutAuth = $procWithoutAuth; |
101
|
|
|
|
102
|
|
|
return $this; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return bool |
107
|
|
|
*/ |
108
|
7 |
|
public function isResultAuth(): bool |
109
|
|
|
{ |
110
|
7 |
|
return $this->resultAuth; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param bool $resultAuth |
115
|
|
|
* @return RpcAuthDefinition |
116
|
|
|
*/ |
117
|
|
|
public function setResultAuth(bool $resultAuth): self |
118
|
|
|
{ |
119
|
|
|
$this->resultAuth = $resultAuth; |
120
|
|
|
|
121
|
|
|
return $this; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|