Passed
Pull Request — master (#7302)
by Angel Fernando Quiroz
18:19 queued 07:15
created

SchemaController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 311
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 230
c 1
b 0
f 0
dl 0
loc 311
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A listSchemas() 0 17 1
B getUserCoreSchema() 0 271 1
A geSchema() 0 13 2
1
<?php
2
3
/* For licensing terms,
4
see /license.txt */
5
6
declare(strict_types=1);
7
8
namespace Chamilo\CoreBundle\Controller\Scim;
9
10
use Symfony\Component\HttpFoundation\JsonResponse;
11
use Symfony\Component\HttpFoundation\Response;
12
use Symfony\Component\Routing\Attribute\Route;
13
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
14
15
#[Route('/scim/v2/Schemas')]
16
class SchemaController extends AbstractScimController
17
{
18
    #[Route('', name: 'scim_schemas', methods: ['GET'])]
19
    public function listSchemas(): JsonResponse
20
    {
21
        $schemas = [
22
            'schemas' => ['urn:ietf:params:scim:api:messages:2.0:ListResponse'],
23
            'itemsPerPage' => 1,
24
            'startIndex' => 1,
25
            'totalResults' => 1,
26
            'Resources' => [
27
                $this->getUserCoreSchema(),
28
            ],
29
        ];
30
31
        return new JsonResponse(
32
            $schemas,
33
            Response::HTTP_OK,
34
            ['Content-Type' => self::SCIM_CONTENT_TYPE]
35
        );
36
    }
37
38
    private function getUserCoreSchema(): array
39
    {
40
        $location = $this->generateUrl(
41
            'scim_schema',
42
            ['schemaId' => 'urn:ietf:params:scim:schemas:core:2.0:User'],
43
            UrlGeneratorInterface::ABSOLUTE_URL
44
        );
45
46
        return [
47
            'id' => 'urn:ietf:params:scim:schemas:core:2.0:User',
48
            'name' => 'User',
49
            'description' => 'User Schema',
50
            'attributes' => [
51
                [
52
                    'name' => 'id',
53
                    'type' => 'string',
54
                    'multiValued' => false,
55
                    'description' => 'Unique identifier for the resource as defined by Chamilo.',
56
                    'required' => true,
57
                    'caseExact' => true,
58
                    'mutability' => 'readOnly',
59
                    'returned' => 'default',
60
                    'uniqueness' => 'server',
61
                ],
62
                [
63
                    'name' => 'externalId',
64
                    'type' => 'string',
65
                    'multiValued' => false,
66
                    'description' => 'Unique identifier for the resource as defined by the provisioning client.',
67
                    'required' => false,
68
                    'caseExact' => false,
69
                    'mutability' => 'readWrite',
70
                    'returned' => 'default',
71
                    'uniqueness' => 'none',
72
                ],
73
                [
74
                    'name' => 'userName',
75
                    'type' => 'string',
76
                    'multiValued' => false,
77
                    'description' => 'Unique identifier for the User, typically used by the user to directly authenticate to Chamilo.',
78
                    'required' => true,
79
                    'caseExact' => false,
80
                    'mutability' => 'readWrite',
81
                    'returned' => 'default',
82
                    'uniqueness' => 'server',
83
                ],
84
                [
85
                    'name' => 'displayName',
86
                    'type' => 'string',
87
                    'multiValued' => false,
88
                    'description' => 'The name of the User, suitable for display to end-users.',
89
                    'required' => false,
90
                    'caseExact' => false,
91
                    'mutability' => 'readOnly',
92
                    'returned' => 'default',
93
                    'uniqueness' => 'none',
94
                ],
95
                [
96
                    'name' => 'name',
97
                    'type' => 'complex',
98
                    'multiValued' => false,
99
                    'description' => "The components of the user's real name.",
100
                    'required' => false,
101
                    'mutability' => 'readWrite',
102
                    'returned' => 'default',
103
                    'subAttributes' => [
104
                        [
105
                            'name' => 'familyName',
106
                            'type' => 'string',
107
                            'description' => "The family name of the User, or last name in most Western languages (e.g., 'Jensen' given the full name 'Ms. Barbara J Jensen, III').",
108
                            'multiValued' => false,
109
                            'required' => true,
110
                            'mutability' => 'readWrite',
111
                            'returned' => 'default',
112
                        ],
113
                        [
114
                            'name' => 'givenName',
115
                            'type' => 'string',
116
                            'multiValued' => false,
117
                            'description' => "The given name of the User, or first name in most Western languages (e.g., 'Barbara' given the full name 'Ms. Barbara J Jensen, III').",
118
                            'required' => true,
119
                            'mutability' => 'readWrite',
120
                            'returned' => 'default',
121
                        ],
122
                    ],
123
                ],
124
                [
125
                    'name' => 'emails',
126
                    'type' => 'complex',
127
                    'multiValued' => true,
128
                    'description' => 'Email addresses for the user.',
129
                    'required' => true,
130
                    'mutability' => 'readWrite',
131
                    'returned' => 'default',
132
                    'subAttributes' => [
133
                        [
134
                            'name' => 'value',
135
                            'type' => 'string',
136
                            'multiValued' => false,
137
                            'description' => 'Email addresses for the user.',
138
                            'required' => false,
139
                            'mutability' => 'readWrite',
140
                            'returned' => 'default',
141
                        ],
142
                        [
143
                            'name' => 'type',
144
                            'type' => 'string',
145
                            'multiValued' => false,
146
                            'description' => "A label indicating the attribute's function.",
147
                            'required' => false,
148
                            'mutability' => 'readWrite',
149
                            'returned' => 'default',
150
                            'canonicalValues' => [
151
                                'work',
152
                            ],
153
                        ],
154
                        [
155
                            'name' => 'primary',
156
                            'type' => 'boolean',
157
                            'multiValued' => false,
158
                            'description' => "A Boolean value indicating the 'primary' or preferred attribute value for this attribute",
159
                            'required' => false,
160
                            'mutability' => 'readWrite',
161
                            'returned' => 'default',
162
                        ],
163
                    ],
164
                ],
165
                [
166
                    'name' => 'phoneNumbers',
167
                    'type' => 'complex',
168
                    'multiValued' => true,
169
                    'description' => 'Phone numbers for the User.',
170
                    'required' => false,
171
                    'subAttributes' => [
172
                        [
173
                            'name' => 'value',
174
                            'type' => 'string',
175
                            'multiValued' => false,
176
                            'description' => 'Phone number of the User.',
177
                            'required' => false,
178
                            'caseExact' => false,
179
                            'mutability' => 'readWrite',
180
                            'returned' => 'default',
181
                            'uniqueness' => 'none',
182
                        ],
183
                        [
184
                            'name' => 'type',
185
                            'type' => 'string',
186
                            'multiValued' => false,
187
                            'description' => "A label indicating the attribute's function.",
188
                            'required' => false,
189
                            'caseExact' => false,
190
                            'canonicalValues' => [
191
                                'work',
192
                            ],
193
                            'mutability' => 'readWrite',
194
                            'returned' => 'default',
195
                            'uniqueness' => 'none',
196
                        ],
197
                        [
198
                            'name' => 'primary',
199
                            'type' => 'boolean',
200
                            'multiValued' => false,
201
                            'description' => "A Boolean value indicating the 'primary' or preferred attribute value for this attribute.",
202
                            'required' => false,
203
                            'mutability' => 'readWrite',
204
                            'returned' => 'default',
205
                        ],
206
                    ],
207
                    'mutability' => 'readWrite',
208
                    'returned' => 'default',
209
                ],
210
                [
211
                    'name' => 'addresses',
212
                    'type' => 'complex',
213
                    'multiValued' => true,
214
                    'description' => 'A physical mailing address for this User.',
215
                    'required' => false,
216
                    'subAttributes' => [
217
                        [
218
                            'name' => 'formatted',
219
                            'type' => 'string',
220
                            'multiValued' => false,
221
                            'description' => 'The full mailing address, formatted for display or use with a mailing label.',
222
                            'required' => false,
223
                            'caseExact' => false,
224
                            'mutability' => 'readWrite',
225
                            'returned' => 'default',
226
                            'uniqueness' => 'none',
227
                        ],
228
                        [
229
                            'name' => 'type',
230
                            'type' => 'string',
231
                            'multiValued' => false,
232
                            'description' => "A label indicating the attribute's function.",
233
                            'required' => false,
234
                            'caseExact' => false,
235
                            'canonicalValues' => [
236
                                'work',
237
                            ],
238
                            'mutability' => 'readWrite',
239
                            'returned' => 'default',
240
                            'uniqueness' => 'none',
241
                        ],
242
                    ],
243
                    'mutability' => 'readWrite',
244
                    'returned' => 'default',
245
                    'uniqueness' => 'none',
246
                ],
247
                [
248
                    'name' => 'timezone',
249
                    'type' => 'string',
250
                    'multiValued' => false,
251
                    'description' => "The User's time zone in the 'Olson' time zone database format, e.g., 'America/Los_Angeles'.",
252
                    'required' => false,
253
                    'caseExact' => false,
254
                    'mutability' => 'readWrite',
255
                    'returned' => 'default',
256
                    'uniqueness' => 'none',
257
                ],
258
                [
259
                    'name' => 'active',
260
                    'type' => 'boolean',
261
                    'multiValued' => false,
262
                    'description' => "A Boolean value indicating the User's administrative status.",
263
                    'required' => false,
264
                    'mutability' => 'readWrite',
265
                    'returned' => 'default',
266
                ],
267
                [
268
                    'name' => 'meta',
269
                    'type' => 'complex',
270
                    'multiValued' => false,
271
                    'required' => false,
272
                    'mutability' => 'readOnly',
273
                    'returned' => 'default',
274
                    'subAttributes' => [
275
                        [
276
                            'name' => 'resourceType',
277
                            'type' => 'string',
278
                            'multiValued' => false,
279
                            'mutability' => 'readOnly',
280
                            'returned' => 'default',
281
                        ],
282
                        [
283
                            'name' => 'created',
284
                            'type' => 'dateTime',
285
                            'multiValued' => false,
286
                            'mutability' => 'readOnly',
287
                            'returned' => 'default',
288
                        ],
289
                        [
290
                            'name' => 'lastModified',
291
                            'type' => 'dateTime',
292
                            'multiValued' => false,
293
                            'mutability' => 'readOnly',
294
                            'returned' => 'default',
295
                        ],
296
                        [
297
                            'name' => 'location',
298
                            'type' => 'string',
299
                            'multiValued' => false,
300
                            'mutability' => 'readOnly',
301
                            'returned' => 'default',
302
                        ],
303
                    ],
304
                ],
305
            ],
306
            'meta' => [
307
                'resourceType' => 'Schema',
308
                'location' => $location,
309
            ],
310
        ];
311
    }
312
313
    #[Route('/{schemaId}', name: 'scim_schema', methods: ['GET'])]
314
    public function geSchema(string $schemaId): JsonResponse
315
    {
316
        if ('urn:ietf:params:scim:schemas:core:2.0:User' !== $schemaId) {
317
            throw $this->createNotFoundException('Schema not supported');
318
        }
319
320
        $userSchema = $this->getUserCoreSchema();
321
322
        return new JsonResponse(
323
            $userSchema,
324
            Response::HTTP_OK,
325
            ['Content-Type' => self::SCIM_CONTENT_TYPE]
326
        );
327
    }
328
}
329