ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
AttributeLimit.php
Go to the documentation of this file.
1<?php
2
10
14 private $allowedAttributes = array();
15
16
22 private $isDefault = FALSE;
23
24
32 public function __construct($config, $reserved) {
33 parent::__construct($config, $reserved);
34
35 assert('is_array($config)');
36
37 foreach ($config as $index => $value) {
38 if ($index === 'default') {
39 $this->isDefault = (bool)$value;
40 } elseif (is_int($index)) {
41 if (!is_string($value)) {
42 throw new SimpleSAML_Error_Exception('AttributeLimit: Invalid attribute name: ' .
43 var_export($value, TRUE));
44 }
45 $this->allowedAttributes[] = $value;
46 } elseif (is_string($index)) {
47 if (!is_array($value)) {
48 throw new SimpleSAML_Error_Exception('AttributeLimit: Values for ' . var_export($index, TRUE) .
49 ' must be specified in an array.');
50 }
51 $this->allowedAttributes[$index] = $value;
52 } else {
53 throw new SimpleSAML_Error_Exception('AttributeLimit: Invalid option: ' . var_export($index, TRUE));
54 }
55 }
56 }
57
58
65 private static function getSPIdPAllowed(array &$request) {
66
67 if (array_key_exists('attributes', $request['Destination'])) {
68 // SP Config
69 return $request['Destination']['attributes'];
70 }
71 if (array_key_exists('attributes', $request['Source'])) {
72 // IdP Config
73 return $request['Source']['attributes'];
74 }
75 return NULL;
76 }
77
78
87 public function process(&$request) {
88 assert('is_array($request)');
89 assert('array_key_exists("Attributes", $request)');
90
91 if ($this->isDefault) {
93 if ($allowedAttributes === NULL) {
95 }
96 } elseif (!empty($this->allowedAttributes)) {
98 } else {
100 if ($allowedAttributes === NULL) {
101 return; /* No limit on attributes. */
102 }
103 }
104
105 $attributes =& $request['Attributes'];
106
107 foreach ($attributes as $name => $values) {
108 if (!in_array($name, $allowedAttributes, TRUE)) {
109 // the attribute name is not in the array of allowed attributes
110 if (array_key_exists($name, $allowedAttributes)) {
111 // but it is an index of the array
112 if (!is_array($allowedAttributes[$name])) {
113 throw new SimpleSAML_Error_Exception('AttributeLimit: Values for ' . var_export($name, TRUE) .
114 ' must be specified in an array.');
115 }
117 if (!empty($attributes[$name])) {
118 continue;
119 }
120 }
121 unset($attributes[$name]);
122 }
123 }
124
125 }
126
127}
An exception for terminatinating execution or to throw for unit testing.
static getSPIdPAllowed(array &$request)
Get list of allowed from the SP/IdP config.
$allowedAttributes
List of attributes which this filter will allow through.
if($format !==null) $name
Definition: metadata.php:146
$index
Definition: metadata.php:60
$attributes