|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the login-cidadao project or it's bundles. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Guilherme Donato <guilhermednt on github> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace LoginCidadao\OpenIDBundle\EventListener; |
|
12
|
|
|
|
|
13
|
|
|
use Doctrine\ORM\EntityManager; |
|
14
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
15
|
|
|
use LoginCidadao\CoreBundle\Entity\Authorization; |
|
16
|
|
|
use LoginCidadao\CoreBundle\Event\GetClientEvent; |
|
17
|
|
|
use LoginCidadao\CoreBundle\Event\LoginCidadaoCoreEvents; |
|
18
|
|
|
use LoginCidadao\OpenIDBundle\Entity\ClientMetadata; |
|
19
|
|
|
use LoginCidadao\OpenIDBundle\Event\AuthorizationEvent; |
|
20
|
|
|
use LoginCidadao\OpenIDBundle\LoginCidadaoOpenIDEvents; |
|
21
|
|
|
use LoginCidadao\OpenIDBundle\Validator\SectorIdentifierUriChecker; |
|
22
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
23
|
|
|
|
|
24
|
|
|
class OAuthEventSubscriber implements EventSubscriberInterface |
|
25
|
|
|
{ |
|
26
|
1 |
|
public static function getSubscribedEvents() |
|
27
|
|
|
{ |
|
28
|
|
|
return [ |
|
29
|
1 |
|
LoginCidadaoOpenIDEvents::NEW_AUTHORIZATION => ['onNewAuthorization', 10], |
|
30
|
|
|
LoginCidadaoOpenIDEvents::UPDATE_AUTHORIZATION => ['onUpdateAuthorization', 10], |
|
31
|
|
|
]; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
1 |
|
public function onNewAuthorization(AuthorizationEvent $event) |
|
35
|
|
|
{ |
|
36
|
1 |
|
$authorization = new Authorization(); |
|
37
|
1 |
|
$authorization->setPerson($event->getPerson()); |
|
38
|
1 |
|
$authorization->setClient($event->getClient()); |
|
39
|
1 |
|
$authorization->setScope($event->getScope()); |
|
40
|
|
|
|
|
41
|
1 |
|
$event->setAuthorization($authorization); |
|
42
|
1 |
|
} |
|
43
|
|
|
|
|
44
|
2 |
|
public function onUpdateAuthorization(AuthorizationEvent $event) |
|
45
|
|
|
{ |
|
46
|
2 |
|
$authorization = $event->getAuthorization(); |
|
47
|
2 |
|
if (!$authorization instanceof Authorization) { |
|
|
|
|
|
|
48
|
|
|
// A pre-existing Authorization is expected. There is nothing we can do here. |
|
49
|
1 |
|
return; |
|
50
|
|
|
} |
|
51
|
1 |
|
$merged = array_merge($authorization->getScope(), $event->getScope()); |
|
52
|
1 |
|
$authorization->setScope($merged); |
|
53
|
1 |
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|