|
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\OAuthBundle\Service; |
|
12
|
|
|
|
|
13
|
|
|
use LoginCidadao\OAuthBundle\Entity\Organization; |
|
14
|
|
|
use LoginCidadao\OpenIDBundle\Entity\ClientMetadata; |
|
15
|
|
|
use LoginCidadao\OpenIDBundle\Validator\SectorIdentifierUriChecker; |
|
16
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException; |
|
17
|
|
|
|
|
18
|
|
|
class OrganizationService |
|
19
|
|
|
{ |
|
20
|
|
|
/** @var SectorIdentifierUriChecker */ |
|
21
|
|
|
private $sectorIdentifierChecker; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* OrganizationService constructor. |
|
25
|
|
|
* @param SectorIdentifierUriChecker $sectorIdentifierChecker |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct(SectorIdentifierUriChecker $sectorIdentifierChecker) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->sectorIdentifierChecker = $sectorIdentifierChecker; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function getOrganization(ClientMetadata $metadata = null) |
|
33
|
|
|
{ |
|
34
|
|
|
if ($metadata === null) { |
|
35
|
|
|
return null; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
if ($metadata->getOrganization() === null && $metadata->getSectorIdentifierUri()) { |
|
39
|
|
|
$sectorIdentifierUri = $metadata->getSectorIdentifierUri(); |
|
40
|
|
|
try { |
|
41
|
|
|
$verified = $this->sectorIdentifierChecker->check($metadata, $sectorIdentifierUri); |
|
42
|
|
|
} catch (HttpException $e) { |
|
43
|
|
|
$verified = false; |
|
44
|
|
|
} |
|
45
|
|
|
$uri = parse_url($sectorIdentifierUri); |
|
46
|
|
|
$domain = $uri['host']; |
|
47
|
|
|
|
|
48
|
|
|
$organization = new Organization(); |
|
49
|
|
|
$organization->setDomain($domain) |
|
50
|
|
|
->setName($domain) |
|
51
|
|
|
->setTrusted(false) |
|
52
|
|
|
->setVerifiedAt($verified ? new \DateTime() : null); |
|
53
|
|
|
|
|
54
|
|
|
return $organization; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return $metadata->getOrganization(); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|