ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
CardinalitySingle.php
Go to the documentation of this file.
1 <?php
2 
4 
15 {
17  private $singleValued = array();
18 
20  private $firstValue = array();
21 
23  private $flatten = array();
24 
26  private $flattenWith = ';';
27 
29  private $ignoreEntities = array();
30 
32  private $http;
33 
41  public function __construct($config, $reserved, HTTPAdapter $http = null)
42  {
43  parent::__construct($config, $reserved);
44  assert(is_array($config));
45 
46  $this->http = $http ?: new HTTPAdapter();
47 
48  if (array_key_exists('singleValued', $config)) {
49  $this->singleValued = $config['singleValued'];
50  }
51  if (array_key_exists('firstValue', $config)) {
52  $this->firstValue = $config['firstValue'];
53  }
54  if (array_key_exists('flattenWith', $config)) {
55  $this->flattenWith = is_array($config['flattenWith']) ? array_shift($config['flattenWith']) : $config['flattenWith'];
56  }
57  if (array_key_exists('flatten', $config)) {
58  $this->flatten = $config['flatten'];
59  }
60  if (array_key_exists('ignoreEntities', $config)) {
61  $this->ignoreEntities = $config['ignoreEntities'];
62  }
63  /* for consistency with core:Cardinality */
64  if (array_key_exists('%ignoreEntities', $config)) {
65  $this->ignoreEntities = $config['%ignoreEntities'];
66  }
67  }
68 
74  public function process(&$request)
75  {
76  assert(is_array($request));
77  assert(array_key_exists("Attributes", $request));
78 
79  if (array_key_exists('Source', $request) &&
80  array_key_exists('entityid', $request['Source']) &&
81  in_array($request['Source']['entityid'], $this->ignoreEntities, true)
82  ) {
83  SimpleSAML\Logger::debug('CardinalitySingle: Ignoring assertions from '.$request['Source']['entityid']);
84  return;
85  }
86 
87  foreach ($request['Attributes'] as $k => $v) {
88  if (!is_array($v)) {
89  continue;
90  }
91  if (count($v) <= 1) {
92  continue;
93  }
94 
95  if (in_array($k, $this->singleValued)) {
96  $request['core:cardinality:errorAttributes'][$k] = array(count($v), '0 ≤ n ≤ 1');
97  continue;
98  }
99  if (in_array($k, $this->firstValue)) {
100  $request['Attributes'][$k] = array(array_shift($v));
101  continue;
102  }
103  if (in_array($k, $this->flatten)) {
104  $request['Attributes'][$k] = array(implode($this->flattenWith, $v));
105  continue;
106  }
107  }
108 
109  /* abort if we found a problematic attribute */
110  if (array_key_exists('core:cardinality:errorAttributes', $request)) {
111  $id = SimpleSAML_Auth_State::saveState($request, 'core:cardinality');
112  $url = SimpleSAML\Module::getModuleURL('core/cardinality_error.php');
113  $this->http->redirectTrustedURL($url, array('StateId' => $id));
114  return;
115  }
116  }
117 }
$config
Definition: bootstrap.php:15
foreach($paths as $path) $request
Definition: asyncclient.php:32
__construct($config, $reserved, HTTPAdapter $http=null)
Initialize this filter, parse configuration.
static debug($string)
Definition: Logger.php:211
if(!array_key_exists('StateId', $_REQUEST)) $id
process(&$request)
Process this filter.
static getModuleURL($resource, array $parameters=array())
Get absolute URL to a specified module resource.
Definition: Module.php:220
static http()
Fetches the global http state from ILIAS.
$url
static saveState(&$state, $stage, $rawId=false)
Save the state.
Definition: State.php:194