|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Service; |
|
4
|
|
|
|
|
5
|
|
|
use App\Entity\ServiceProvider; |
|
6
|
|
|
use App\Entity\ServiceProviderConfirmation; |
|
7
|
|
|
use App\Entity\User; |
|
8
|
|
|
use App\Repository\ServiceProviderConfirmationRepositoryInterface; |
|
9
|
|
|
use App\Saml\AttributeValueProvider; |
|
10
|
|
|
|
|
11
|
|
|
class ServiceProviderConfirmationService { |
|
12
|
|
|
|
|
13
|
|
|
private $attributeValueProvider; |
|
14
|
|
|
private $confirmationRepository; |
|
15
|
|
|
|
|
16
|
1 |
|
public function __construct(AttributeValueProvider $attributeValueProvider, ServiceProviderConfirmationRepositoryInterface $confirmationRepository) { |
|
17
|
1 |
|
$this->attributeValueProvider = $attributeValueProvider; |
|
18
|
1 |
|
$this->confirmationRepository = $confirmationRepository; |
|
19
|
1 |
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function needsConfirmation(User $user, ServiceProvider $serviceProvider) { |
|
22
|
|
|
$confirmation = $this->confirmationRepository->findOneByUserAndServiceProvider($user, $serviceProvider); |
|
23
|
|
|
|
|
24
|
|
|
if($confirmation === null) { |
|
25
|
|
|
return true; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
$confirmedAttributes = $confirmation->getAttributes(); |
|
29
|
|
|
$currentAttributes = array_keys($this->attributeValueProvider->getValuesForUser($user, $serviceProvider->getEntityId())); |
|
30
|
|
|
|
|
31
|
|
|
sort($confirmedAttributes); |
|
32
|
|
|
sort($currentAttributes); |
|
33
|
|
|
|
|
34
|
|
|
return $confirmedAttributes !== $currentAttributes; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function saveConfirmation(User $user, ServiceProvider $serviceProvider) { |
|
38
|
|
|
$confirmation = $this->confirmationRepository->findOneByUserAndServiceProvider($user, $serviceProvider); |
|
39
|
|
|
|
|
40
|
|
|
if($confirmation === null) { |
|
41
|
|
|
$confirmation = (new ServiceProviderConfirmation()) |
|
42
|
|
|
->setUser($user) |
|
43
|
|
|
->setServiceProvider($serviceProvider); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$currentAttributes = array_keys($this->attributeValueProvider->getValuesForUser($user, $serviceProvider->getEntityId())); |
|
47
|
|
|
$confirmation->setAttributes($currentAttributes); |
|
48
|
|
|
|
|
49
|
|
|
$this->confirmationRepository->persist($confirmation); |
|
50
|
|
|
} |
|
51
|
|
|
} |