|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright 2010 SURFnet B.V. |
|
4
|
|
|
* |
|
5
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
6
|
|
|
* you may not use this file except in compliance with the License. |
|
7
|
|
|
* You may obtain a copy of the License at |
|
8
|
|
|
* |
|
9
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
10
|
|
|
* |
|
11
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
12
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
13
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14
|
|
|
* See the License for the specific language governing permissions and |
|
15
|
|
|
* limitations under the License. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace Surfnet\StepupSelfService\SelfServiceBundle\Service\RemoteVetting; |
|
19
|
|
|
|
|
20
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Exception\InvalidRemoteVettingMappingException; |
|
21
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Service\RemoteVetting\Dto\AttributeListDto; |
|
22
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Service\RemoteVetting\Value\AttributeMatch; |
|
23
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Service\RemoteVetting\Value\AttributeMatchCollection; |
|
24
|
|
|
|
|
25
|
|
|
class AttributeMapper |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @var IdentityProviderFactory |
|
29
|
|
|
*/ |
|
30
|
|
|
private $identityProviderFactory; |
|
31
|
|
|
|
|
32
|
|
|
public function __construct(IdentityProviderFactory $identityProviderFactory) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->identityProviderFactory = $identityProviderFactory; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param string $identityProviderName |
|
39
|
|
|
* @param AttributeListDto $localAttributes |
|
40
|
|
|
* @param AttributeListDto $externalAttributes |
|
|
|
|
|
|
41
|
|
|
* @return AttributeMatchCollection |
|
42
|
|
|
* @throws InvalidRemoteVettingMappingException |
|
43
|
|
|
*/ |
|
44
|
|
|
public function map($identityProviderName, AttributeListDto $localAttributes, AttributeListDto $remoteAttributes) |
|
45
|
|
|
{ |
|
46
|
|
|
$attributeMapping = $this->identityProviderFactory->getAttributeMapping($identityProviderName); |
|
47
|
|
|
|
|
48
|
|
|
$localMap = $this->attributeListToMap($localAttributes); |
|
49
|
|
|
$remoteMap = $this->attributeListToMap($remoteAttributes); |
|
50
|
|
|
|
|
51
|
|
|
$matchCollection = new AttributeMatchCollection(); |
|
52
|
|
|
foreach ($attributeMapping as $localName => $remoteName) { |
|
53
|
|
|
if (!array_key_exists($localName, $localMap)) { |
|
54
|
|
|
throw new InvalidRemoteVettingMappingException(sprintf( |
|
55
|
|
|
'Invalid remote vetting attribute mapping, local attribute with name "%s" not found', |
|
56
|
|
|
$localName |
|
57
|
|
|
)); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
if (!array_key_exists($remoteName, $remoteMap)) { |
|
61
|
|
|
throw new InvalidRemoteVettingMappingException(sprintf( |
|
62
|
|
|
'Invalid remote vetting attribute mapping, remote attribute with name "%s" not found', |
|
63
|
|
|
$remoteName |
|
64
|
|
|
)); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$attributeMatch = new AttributeMatch($localMap[$localName], $remoteMap[$remoteName], false, ''); |
|
68
|
|
|
$matchCollection->add($localName, $attributeMatch); |
|
69
|
|
|
}; |
|
70
|
|
|
|
|
71
|
|
|
return $matchCollection; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @param AttributeListDto $attributeList |
|
76
|
|
|
* @return array |
|
77
|
|
|
*/ |
|
78
|
|
|
private function attributeListToMap(AttributeListDto $attributeList) |
|
79
|
|
|
{ |
|
80
|
|
|
$result = []; |
|
81
|
|
|
foreach ($attributeList->getAttributeCollection() as $attribute) { |
|
82
|
|
|
$result[$attribute->getName()] = $attribute; |
|
83
|
|
|
} |
|
84
|
|
|
return $result; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.