Skip to content

Commit 1bd9f90

Browse files
committed
hibamegjelenítés
1 parent 9100d5a commit 1bd9f90

2 files changed

Lines changed: 42 additions & 14 deletions

File tree

lib/Auth/Process/AttributeFromRestApi.php

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,30 @@ public function __construct($config, $reserved)
3636

3737
public function process(&$state)
3838
{
39-
assert('is_array($state)');
40-
if (! array_key_exists($this->as_config['nameId_attribute_name'], $state['Attributes'])) {
41-
throw new SimpleSAML_Error_Exception(
42-
"Configuration error: There is no attribute named: "
43-
.$this->as_config['nameId_attribute_name']
44-
." in state['Attributes'] array."
45-
);
39+
try {
40+
assert('is_array($state)');
41+
if (! array_key_exists($this->as_config['nameId_attribute_name'], $state['Attributes'])) {
42+
throw new SimpleSAML_Error_Exception(
43+
"Configuration error: There is no attribute named: '"
44+
.$this->as_config['nameId_attribute_name']
45+
."'' in \$state['Attributes'] array."
46+
);
47+
}
48+
$nameId = $state['Attributes'][$this->as_config['nameId_attribute_name']][0];
49+
$this->config = SimpleSAML_Configuration::getInstance();
50+
$new_attributes = $this->getAttributes($nameId);
51+
$state['Attributes'][key($new_attributes)][0] = $new_attributes[key($new_attributes)];
52+
} catch (\Exception $e) {
53+
$this->showException($e);
4654
}
47-
$nameId = $state['Attributes'][$this->as_config['nameId_attribute_name']][0];
48-
$this->config = SimpleSAML_Configuration::getInstance();
49-
$new_attributes = $this->getAttributes($nameId);
50-
$state['Attributes'][key($new_attributes)][0] = $new_attributes[key($new_attributes)];
55+
5156
}
5257

5358
public function getAttributes($nameId, $attributes = array())
5459
{
5560

5661
// Set up config
5762
$config = $this->config;
58-
$retarray = array();
59-
60-
// Make the call
6163

6264
// Setup cURL
6365
$url = $this->as_config['api_url'].'/'.$nameId;
@@ -92,4 +94,13 @@ public function getAttributes($nameId, $attributes = array())
9294
$attributes = $data['data'];
9395
return $attributes;
9496
}
97+
98+
private function showException($e)
99+
{
100+
$globalConfig = SimpleSAML_Configuration::getInstance();
101+
$t = new SimpleSAML_XHTML_Template($globalConfig, 'attributefromrestapi:exception.tpl.php');
102+
$t->data['e'] = $e->getMessage();
103+
$t->show();
104+
exit();
105+
}
95106
}

templates/exception.tpl.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
$this->data['header'] = 'Error in attribute aggregation';
3+
4+
$this->includeAtTemplateBase('includes/header.php');
5+
?>
6+
<h1>We have a problem.</h1>
7+
8+
We catch an exception during fetching attributes from the external attribute source. The exception is:
9+
<pre>
10+
11+
<?php
12+
echo $this->data['e'];
13+
?>
14+
</pre>
15+
16+
<?php
17+
$this->includeAtTemplateBase('includes/footer.php');

0 commit comments

Comments
 (0)