1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Validator\Constraints\Role\Permissions; |
4
|
|
|
|
5
|
|
|
use Ds\Component\Api\Collection\ServiceCollection; |
|
|
|
|
6
|
|
|
use Ds\Component\Acl\Model\Permission; |
|
|
|
|
7
|
|
|
use JsonSchema\Validator; |
|
|
|
|
8
|
|
|
use Symfony\Component\Validator\Constraint; |
|
|
|
|
9
|
|
|
use Symfony\Component\Validator\ConstraintValidator; |
|
|
|
|
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class ValidValidator |
13
|
|
|
* |
14
|
|
|
* @example |
15
|
|
|
* <code> |
16
|
|
|
* { |
17
|
|
|
* "identities": [ |
18
|
|
|
* { |
19
|
|
|
* "scope": { |
20
|
|
|
* "type": "owned_by", |
21
|
|
|
* "entity": "BusinessUnit", |
22
|
|
|
* "entityUuid": "aff1370c-9cb7-432d-a608-57021637f278" |
23
|
|
|
* }, |
24
|
|
|
* "permissions": [ |
25
|
|
|
* { |
26
|
|
|
* "key": "individual", |
27
|
|
|
* "attributes": ["BROWSE", "READ"] |
28
|
|
|
* }, |
29
|
|
|
* { |
30
|
|
|
* "key": "individual_uuid", |
31
|
|
|
* "attributes": ["BROWSE", "READ"] |
32
|
|
|
* } |
33
|
|
|
* ] |
34
|
|
|
* } |
35
|
|
|
* ] |
36
|
|
|
* } |
37
|
|
|
* </code> |
38
|
|
|
*/ |
39
|
|
|
final class ValidValidator extends ConstraintValidator |
40
|
|
|
{ |
41
|
|
|
/** |
42
|
|
|
* @var \Ds\Component\Api\Collection\ServiceCollection |
43
|
|
|
*/ |
44
|
|
|
protected $serviceCollection; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Constructor |
48
|
|
|
* |
49
|
|
|
* @param \Ds\Component\Api\Collection\ServiceCollection $serviceCollection |
50
|
|
|
*/ |
51
|
|
|
public function __construct(ServiceCollection $serviceCollection) |
52
|
|
|
{ |
53
|
|
|
$this->serviceCollection = $serviceCollection; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
*/ |
59
|
|
|
public function validate($role, Constraint $constraint) |
60
|
|
|
{ |
61
|
|
|
$validator = new Validator; |
62
|
|
|
$property = ' |
63
|
|
|
{ |
64
|
|
|
"type": "array", |
65
|
|
|
"items": { |
66
|
|
|
"type": "array", |
67
|
|
|
"additionalProperties": false, |
68
|
|
|
"required": ["scope", "permissions"], |
69
|
|
|
"properties": { |
70
|
|
|
"scope": { |
71
|
|
|
"type": "array", |
72
|
|
|
"additionalProperties": false, |
73
|
|
|
"properties": { |
74
|
|
|
"operator": { |
75
|
|
|
"type": "string", |
76
|
|
|
"enum": ["and", "or"] |
77
|
|
|
}, |
78
|
|
|
"conditions": { |
79
|
|
|
"type": "array" |
80
|
|
|
}, |
81
|
|
|
"type": { |
82
|
|
|
"type": "string", |
83
|
|
|
"enum": ["generic", "object", "identity", "owner", "session", "property"] |
84
|
|
|
}, |
85
|
|
|
"entity": { |
86
|
|
|
"type": "string" |
87
|
|
|
}, |
88
|
|
|
"entityUuid": { |
89
|
|
|
"type": ["string", "null"] |
90
|
|
|
}, |
91
|
|
|
"property": { |
92
|
|
|
"type": "string" |
93
|
|
|
}, |
94
|
|
|
"comparison": { |
95
|
|
|
"type": "string", |
96
|
|
|
"enum": ["eq", "neq"] |
97
|
|
|
}, |
98
|
|
|
"value": {} |
99
|
|
|
} |
100
|
|
|
}, |
101
|
|
|
"permissions": { |
102
|
|
|
"type": "array", |
103
|
|
|
"items": { |
104
|
|
|
"type": "array", |
105
|
|
|
"additionalProperties": false, |
106
|
|
|
"required": ["key", "attributes"], |
107
|
|
|
"properties": { |
108
|
|
|
"key": { |
109
|
|
|
"type": "string" |
110
|
|
|
}, |
111
|
|
|
"attributes": { |
112
|
|
|
"type": "array", |
113
|
|
|
"items": { |
114
|
|
|
"type": "string", |
115
|
|
|
"enum": ["BROWSE", "READ", "EDIT", "ADD", "DELETE", "EXECUTE"] |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
'; |
125
|
|
|
$schema = json_decode(' |
126
|
|
|
{ |
127
|
|
|
"type": "array", |
128
|
|
|
"additionalProperties": false, |
129
|
|
|
"properties": { |
130
|
|
|
"assets": ' . $property . ', |
131
|
|
|
"authentication": ' . $property . ', |
132
|
|
|
"cases": ' . $property . ', |
133
|
|
|
"cms": ' . $property . ', |
134
|
|
|
"forms": ' . $property . ', |
135
|
|
|
"identities": ' . $property . ', |
136
|
|
|
"microservice": ' . $property . ', |
137
|
|
|
"records": ' . $property . ', |
138
|
|
|
"services": ' . $property . ', |
139
|
|
|
"tasks": ' . $property . ', |
140
|
|
|
"tenants": ' . $property . ' |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
'); |
144
|
|
|
$permissions = $role->getPermissions(); |
145
|
|
|
$validator->validate($permissions, $schema); |
146
|
|
|
|
147
|
|
|
if (!$validator->isValid()) { |
148
|
|
|
foreach ($validator->getErrors() as $error) { |
149
|
|
|
$this->context |
150
|
|
|
->buildViolation($error['message']) |
151
|
|
|
->atPath('permissions.' . $error['property']) |
152
|
|
|
->addViolation(); |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths