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