-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathScope.php
More file actions
87 lines (77 loc) · 2.87 KB
/
Scope.php
File metadata and controls
87 lines (77 loc) · 2.87 KB
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
<?php
/**
* Copyright 2024 SURF B.V.
*
* 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.
*/
use OpenConext\EngineBlock\Metadata\ShibMdScope;
use OpenConext\Value\Saml\Metadata\ShibbolethMetadataScope;
use OpenConext\Value\Saml\Metadata\ShibbolethMetadataScopeList;
class EngineBlock_Attributes_Validator_Scope extends EngineBlock_Attributes_Validator_Abstract
{
const ERROR_ATTRIBUTE_VALIDATOR_SCOPE = 'error_attribute_validator_scope';
public function validate(array $attributes)
{
if (empty($attributes[$this->_attributeName])) {
return true;
}
$logger = EngineBlock_ApplicationSingleton::getLog();
$scopes = $this->_identityProvider->shibMdScopes;
if (empty($scopes)) {
$logger->notice('No shibmd:scope found in the IdP metadata, not verifying ' . $this->_attributeName);
return true;
}
$scopeList = $this->buildScopeList($scopes);
foreach ($attributes[$this->_attributeName] as $attributeValue) {
if($scopeList->inScope($attributeValue)) {
continue;
}
// consider moving this to inScope()
list(,$suffix) = explode('@', $attributeValue, 2);
if(empty($suffix) || $scopeList->inScope($suffix)) {
continue;
}
$logger->warning(sprintf(
'%s attribute value "%s" is not allowed by configured ShibMdScopes for IdP "%s"',
$this->_attributeName,
$attributeValue,
$this->_identityProvider->entityId
));
$this->_messages[] = [
self::ERROR_ATTRIBUTE_VALIDATOR_SCOPE,
$this->_attributeName,
$this->_options,
$attributeValue
];
return false;
}
return true;
}
/**
* @param ShibMdScope[] $scopes
* @return ShibbolethMetadataScopeList
*/
private function buildScopeList(array $scopes)
{
$scopes = array_map(
function (ShibMdScope $scope) {
if (!$scope->regexp) {
return ShibbolethMetadataScope::literal($scope->allowed);
}
return ShibbolethMetadataScope::regexp($scope->allowed);
},
$scopes
);
return new ShibbolethMetadataScopeList($scopes);
}
}