This repository has been archived by the owner on Dec 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 240
/
Contact.php
710 lines (623 loc) · 16.3 KB
/
Contact.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
<?php
/*
* Copyright 2005 - 2020 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Centreon\Domain\Contact;
use Centreon\Domain\Menu\Model\Page;
use Symfony\Component\Security\Core\User\UserInterface;
use Centreon\Domain\Contact\Interfaces\ContactInterface;
class Contact implements UserInterface, ContactInterface
{
// global api roles
public const ROLE_API_CONFIGURATION = 'ROLE_API_CONFIGURATION';
public const ROLE_API_REALTIME = 'ROLE_API_REALTIME';
// user action roles
public const ROLE_HOST_CHECK = 'ROLE_HOST_CHECK';
public const ROLE_SERVICE_CHECK = 'ROLE_SERVICE_CHECK';
public const ROLE_HOST_ACKNOWLEDGEMENT = 'ROLE_HOST_ACKNOWLEDGEMENT';
public const ROLE_HOST_DISACKNOWLEDGEMENT = 'ROLE_HOST_DISACKNOWLEDGEMENT';
public const ROLE_SERVICE_ACKNOWLEDGEMENT = 'ROLE_SERVICE_ACKNOWLEDGEMENT';
public const ROLE_SERVICE_DISACKNOWLEDGEMENT = 'ROLE_SERVICE_DISACKNOWLEDGEMENT';
public const ROLE_CANCEL_HOST_DOWNTIME = 'ROLE_CANCEL_HOST_DOWNTIME';
public const ROLE_CANCEL_SERVICE_DOWNTIME = 'ROLE_CANCEL_SERVICE_DOWNTIME';
public const ROLE_ADD_HOST_DOWNTIME = 'ROLE_ADD_HOST_DOWNTIME';
public const ROLE_ADD_SERVICE_DOWNTIME = 'ROLE_ADD_SERVICE_DOWNTIME';
public const ROLE_SERVICE_SUBMIT_RESULT = 'ROLE_SERVICE_SUBMIT_RESULT';
public const ROLE_HOST_SUBMIT_RESULT = 'ROLE_HOST_SUBMIT_RESULT';
public const ROLE_HOST_ADD_COMMENT = 'ROLE_HOST_ADD_COMMENT';
public const ROLE_SERVICE_ADD_COMMENT = 'ROLE_SERVICE_ADD_COMMENT';
public const ROLE_DISPLAY_COMMAND = 'ROLE_DISPLAY_COMMAND';
public const ROLE_GENERATE_CONFIGURATION = 'ROLE_GENERATE_CONFIGURATION';
// user pages access
public const ROLE_CONFIGURATION_HOSTS_WRITE = 'ROLE_CONFIGURATION_HOSTS_HOSTS_RW';
public const ROLE_CONFIGURATION_HOSTS_READ = 'ROLE_CONFIGURATION_HOSTS_HOSTS_R';
public const ROLE_CONFIGURATION_SERVICES_WRITE = 'ROLE_CONFIGURATION_SERVICES_SERVICES_BY_HOST_RW';
public const ROLE_CONFIGURATION_SERVICES_READ = 'ROLE_CONFIGURATION_SERVICES_SERVICES_BY_HOST_R';
public const ROLE_CONFIGURATION_META_SERVICES_WRITE = 'ROLE_CONFIGURATION_SERVICES_META_SERVICES_RW';
public const ROLE_CONFIGURATION_META_SERVICES_READ = 'ROLE_CONFIGURATION_SERVICES_META_SERVICES_R';
public const ROLE_MONITORING_EVENT_LOGS = 'ROLE_MONITORING_EVENT_LOGS_EVENT_LOGS_RW';
public const ROLE_REPORTING_DASHBOARD_HOSTS = 'ROLE_REPORTING_DASHBOARD_HOSTS_RW';
public const ROLE_REPORTING_DASHBOARD_SERVICES = 'ROLE_REPORTING_DASHBOARD_SERVICES_RW';
public const ROLE_CONFIGURATION_MONITORING_SERVER_READ_WRITE = 'ROLE_CONFIGURATION_POLLERS_POLLERS_RW';
public const ROLE_CONFIGURATION_MONITORING_SERVER_READ = 'ROLE_CONFIGURATION_POLLERS_POLLERS_R';
public const ROLE_CONFIGURATION_HOSTS_HOST_GROUPS_READ_WRITE = 'ROLE_CONFIGURATION_HOSTS_HOST_GROUPS_RW';
public const ROLE_CONFIGURATION_HOSTS_HOST_GROUPS_READ = 'ROLE_CONFIGURATION_HOSTS_HOST_GROUPS_R';
public const ROLE_CONFIGURATION_SERVICES_SERVICE_GROUPS_READ_WRITE =
'ROLE_CONFIGURATION_SERVICES_SERVICE_GROUPS_RW';
public const ROLE_CONFIGURATION_SERVICES_SERVICE_GROUPS_READ = 'ROLE_CONFIGURATION_SERVICES_SERVICE_GROUPS_R';
public const ROLE_CONFIGURATION_CONTACTS_READ_WRITE = 'ROLE_CONFIGURATION_USERS_CONTACTS__USERS_RW';
public const ROLE_CONFIGURATION_CONTACTS_READ = 'ROLE_CONFIGURATION_USERS_CONTACTS__USERS_R';
public const ROLE_CONFIGURATION_USERS_CONTACT_GROUPS_READ_WRITE = 'ROLE_CONFIGURATION_USERS_CONTACT_GROUPS_RW';
public const ROLE_CONFIGURATION_USERS_CONTACT_GROUPS_READ = 'ROLE_CONFIGURATION_USERS_CONTACT_GROUPS_R';
/**
* @var string
*/
public const DEFAULT_LOCALE = 'en_US';
/**
* @var string
*/
public const DEFAULT_CHARSET = 'UTF-8';
/**
* @var int Id of contact
*/
private $id;
/**
* @var string Name of contact
*/
private $name;
/**
* @var string Alias of contact
*/
private $alias;
/**
* @var string Language of contact
*/
private $lang;
/**
* @var string Email of contact
*/
private $email;
/**
* @var bool Is an admin contact ?
*/
private $isAdmin;
/**
* @var int|null Id of the contact template
*/
private $templateId;
/**
* @var bool Indicates whether this contact is enabled or disabled
*/
private $isActive;
/**
* @var bool Indicates whether this contact is allowed to reach centreon application
*/
private $isAllowedToReachWeb;
/**
* @var string|null Authentication Token
*/
private $token;
/**
* @var string|null Encoded password
*/
private $encodedPassword;
/**
* @var bool Indicates if this user has access to the configuration section of API
*/
private $hasAccessToApiConfiguration;
/**
* @var bool Indicates if this user has access to the real time section of API
*/
private $hasAccessToApiRealTime;
/**
* @var string[]
*/
private $roles = [];
/**
* @var string[] List of names of topology rules to which the contact can access
*/
private $topologyRulesNames = [];
/**
* @var \DateTimeZone $timezone timezone of the user
*/
private $timezone;
/**
* @var int
*/
private int $timezoneId;
/**
* @var string|null $locale locale of the user
*/
private $locale;
/**
* @var Page|null
*/
private $defaultPage;
/**
* Indicates if user uses deprecated pages
*
* @var bool
*/
private $useDeprecatedPages;
/**
* @var bool
*/
private $isOneClickExportEnabled = false;
/**
* @var string|null
*/
private $theme;
/**
* @param int $timezoneId
* @return self
*/
public function setTimezoneId(int $timezoneId): self
{
$this->timezoneId = $timezoneId;
return $this;
}
/**
* @return int
*/
public function getTimezoneId(): int
{
return $this->timezoneId;
}
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @param int $id
* @return self
*/
public function setId(int $id): self
{
$this->id = $id;
return $this;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
* @return self
*/
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return string
*/
public function getAlias(): string
{
return $this->alias;
}
/**
* @param string $alias
* @return self
*/
public function setAlias(string $alias): self
{
$this->alias = $alias;
return $this;
}
/**
* @return string
*/
public function getLang(): string
{
return $this->lang;
}
/**
* @param string $lang
* @return self
*/
public function setLang(string $lang): self
{
$this->lang = $lang;
return $this;
}
/**
* @return string
*/
public function getEmail(): string
{
return $this->email;
}
/**
* @param string $email
* @return self
*/
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* @inheritDoc
*/
public function isAdmin(): bool
{
return $this->isAdmin;
}
/**
* Set if the user is admin or not.
*
* @param bool $isAdmin
* @return self
*/
public function setAdmin(bool $isAdmin): self
{
$this->isAdmin = $isAdmin;
if ($this->isAdmin) {
$this->addRole(self::ROLE_API_REALTIME);
$this->addRole(self::ROLE_API_CONFIGURATION);
}
return $this;
}
/**
* @return int|null
*/
public function getTemplateId(): ?int
{
return $this->templateId;
}
/**
* @param int|null $templateId
* @return self
*/
public function setTemplateId(?int $templateId): self
{
$this->templateId = $templateId;
return $this;
}
/**
* @return bool
*/
public function isActive(): bool
{
return $this->isActive;
}
/**
* @param bool $isActive
* @return self
*/
public function setIsActive(bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
/**
* @inheritDoc
*/
public function isAllowedToReachWeb(): bool
{
return $this->isAllowedToReachWeb;
}
/**
* @inheritDoc
*/
public function setAllowedToReachWeb(bool $isAllowed): static
{
$this->isAllowedToReachWeb = $isAllowed;
return $this;
}
/**
* @return string|null
*/
public function getToken(): ?string
{
return $this->token;
}
/**
* @param string|null $token
* @return self
*/
public function setToken(?string $token): self
{
$this->token = $token;
return $this;
}
/**
* @return string|null
*/
public function getEncodedPassword(): ?string
{
return $this->encodedPassword;
}
/**
* @param string|null $encodedPassword
* @return self
*/
public function setEncodedPassword(?string $encodedPassword): self
{
$this->encodedPassword = $encodedPassword;
return $this;
}
/**
* Returns the roles granted to the user.
*
* public function getRoles()
* {
* return array('ROLE_USER');
* }
*
* Alternatively, the roles might be stored on a ``roles`` property,
* and populated in any number of different ways when the user object
* is created.
*
* @return string[] The user roles
*/
public function getRoles(): array
{
return array_merge($this->roles, $this->topologyRulesNames);
}
/**
* Returns the password used to authenticate the user.
*
* This should be the encoded password. On authentication, a plain-text
* password will be salted, encoded, and then compared to this value.
*
* @return string|null The password
*/
public function getPassword(): ?string
{
return $this->token;
}
/**
* Returns the salt that was originally used to encode the password.
*
* This can return null if the password was not encoded using a salt.
*
* @return string|null The salt
*/
public function getSalt()
{
return null;
}
/**
* Returns the username used to authenticate the user.
*
* @return string The username
*/
public function getUsername()
{
return $this->name;
}
/**
* Removes sensitive data from the user.
*
* This is important if, at any given point, sensitive information like
* the plain-text password is stored on this object.
*/
public function eraseCredentials(): void
{
// Nothing to do. But we must to define this method
}
/**
* @inheritDoc
*/
public function hasAccessToApiConfiguration(): bool
{
return $this->hasAccessToApiConfiguration;
}
/**
* @inheritDoc
*/
public function setAccessToApiConfiguration(bool $hasAccessToApiConfiguration): static
{
$this->hasAccessToApiConfiguration = $hasAccessToApiConfiguration;
if ($this->hasAccessToApiConfiguration) {
$this->addRole(self::ROLE_API_CONFIGURATION);
} else {
$this->removeRole(self::ROLE_API_CONFIGURATION);
}
return $this;
}
/**
* @inheritDoc
*/
public function hasAccessToApiRealTime(): bool
{
return $this->hasAccessToApiRealTime;
}
/**
* @inheritDoc
*/
public function setAccessToApiRealTime(bool $hasAccessToApiRealTime): static
{
$this->hasAccessToApiRealTime = $hasAccessToApiRealTime;
if ($this->hasAccessToApiRealTime) {
$this->addRole(self::ROLE_API_REALTIME);
} else {
$this->removeRole(self::ROLE_API_REALTIME);
}
return $this;
}
/**
* @inheritDoc
*/
public function hasRole(string $role): bool
{
return in_array($role, $this->roles);
}
/**
* @inheritDoc
*/
public function hasTopologyRole(string $role): bool
{
return in_array($role, $this->topologyRulesNames);
}
/**
* Add a specific role to this user.
*
* @param string $roleName Role name to add
*/
public function addRole(string $roleName): void
{
if (!in_array($roleName, $this->roles)) {
$this->roles[] = $roleName;
}
}
/**
* Removes an existing roles.
*
* @param string $roleName Role name to remove
*/
private function removeRole(string $roleName): void
{
unset($this->roles[$roleName]);
}
/**
* Added a topology rule.
*
* @param string $topologyRuleName Topology rule name
*/
public function addTopologyRule(string $topologyRuleName): void
{
if (!in_array($topologyRuleName, $this->topologyRulesNames)) {
$this->topologyRulesNames[] = $topologyRuleName;
}
}
/**
* timezone setter
*
* @param \DateTimeZone $timezone
* @return self
*/
public function setTimezone(\DateTimeZone $timezone): self
{
$this->timezone = $timezone;
return $this;
}
/**
* timezone getter
*
* @return \DateTimeZone
*/
public function getTimezone(): \DateTimeZone
{
return $this->timezone;
}
/**
* locale setter
*
* @param string|null $locale
* @return self
*/
public function setLocale(?string $locale): self
{
$this->locale = $locale;
return $this;
}
/**
* locale getter
*
* @return string|null
*/
public function getLocale(): ?string
{
return $this->locale;
}
/**
* @inheritDoc
*/
public function setDefaultPage(?Page $defaultPage): static
{
$this->defaultPage = $defaultPage;
return $this;
}
/**
* get user default page
*
* @return Page|null
*/
public function getDefaultPage(): ?Page
{
return $this->defaultPage;
}
/**
* @inheritDoc
*/
public function isUsingDeprecatedPages(): bool
{
return $this->useDeprecatedPages;
}
/**
* @inheritDoc
*/
public function setUseDeprecatedPages(bool $useDeprecatedPages): static
{
$this->useDeprecatedPages = $useDeprecatedPages;
return $this;
}
/**
* @return bool
*/
public function isOneClickExportEnabled(): bool
{
return $this->isOneClickExportEnabled;
}
/**
* @param bool $isOneClickExportEnabled
* @return self
*/
public function setOneClickExportEnabled(bool $isOneClickExportEnabled): self
{
$this->isOneClickExportEnabled = $isOneClickExportEnabled;
return $this;
}
/**
* @inheritDoc
*/
public function getUserIdentifier(): string
{
return $this->alias;
}
/**
* Set user current theme.
*
* @param string $theme user's new theme.
* @return self
*/
public function setTheme(string $theme): self
{
$this->theme = $theme;
return $this;
}
/**
* Get user current theme.
*
* @return string|null
*/
public function getTheme(): ?string
{
return $this->theme;
}
}