|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\Module\discopower\Controller; |
|
6
|
|
|
|
|
7
|
|
|
use Exception; |
|
8
|
|
|
use SimpleSAML\Configuration; |
|
9
|
|
|
use SimpleSAML\Error; |
|
10
|
|
|
use SimpleSAML\HTTP\RunnableResponse; |
|
11
|
|
|
use SimpleSAML\Module\discopower\PowerIdPDisco; |
|
12
|
|
|
use SimpleSAML\Session; |
|
13
|
|
|
use SimpleSAML\XHTML\Template; |
|
14
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
15
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
16
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
17
|
|
|
|
|
18
|
|
|
class DiscoPower |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request The current request. |
|
22
|
|
|
* @return \SimpleSAML\HTTP\RunnableResponse |
|
23
|
|
|
*/ |
|
24
|
|
|
public function main(Request $request): RunnableResponse |
|
|
|
|
|
|
25
|
|
|
{ |
|
26
|
|
|
try { |
|
27
|
|
|
$discoHandler = new PowerIdPDisco( |
|
28
|
|
|
['saml20-idp-remote'], |
|
29
|
|
|
'poweridpdisco' |
|
30
|
|
|
); |
|
31
|
|
|
} catch (Exception $exception) { |
|
32
|
|
|
// An error here should be caused by invalid query parameters |
|
33
|
|
|
throw new Error\Error('DISCOPARAMS', $exception); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
try { |
|
37
|
|
|
return new RunnableResponse([$discoHandler, 'handleRequest'], []); |
|
38
|
|
|
} catch (Exception $exception) { |
|
39
|
|
|
// An error here should be caused by metadata |
|
40
|
|
|
throw new Error\Error('METADATA', $exception); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* An AJAX handler to retrieve a list of disco tabs from the session. |
|
46
|
|
|
* This allows us to dynamically update the tab list without inline javascript. |
|
47
|
|
|
* |
|
48
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request The current request. |
|
49
|
|
|
*/ |
|
50
|
|
|
public function tablist(Request $request): Response |
|
51
|
|
|
{ |
|
52
|
|
|
$session = Session::getSessionFromRequest(); |
|
53
|
|
|
$tabs = $session->getData('discopower:tabList', 'tabs'); |
|
54
|
|
|
$faventry = $session->getData('discopower:tabList', 'faventry'); |
|
55
|
|
|
$defaulttab = $session->getData('discopower:tabList', 'defaulttab'); |
|
56
|
|
|
|
|
57
|
|
|
if (!is_array($tabs)) { |
|
58
|
|
|
throw new Error\Exception('Could not get tab list from session'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$response = new JsonResponse(); |
|
62
|
|
|
|
|
63
|
|
|
// handle JSONP requests |
|
64
|
|
|
if ($request->query->has('callback')) { |
|
65
|
|
|
$callback = $request->query->get('callback'); |
|
66
|
|
|
if (!preg_match('/^[a-z0-9_]+$/i', $callback, $matches)) { |
|
67
|
|
|
throw new Error\Exception('Unsafe JSONP callback function name "' . $matches[0] . '"'); |
|
68
|
|
|
} |
|
69
|
|
|
$response->setCallback($callback); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$response->setData( |
|
73
|
|
|
[ |
|
74
|
|
|
'faventry' => $faventry, |
|
75
|
|
|
'default' => $defaulttab, |
|
76
|
|
|
'tabs' => $tabs, |
|
77
|
|
|
] |
|
78
|
|
|
); |
|
79
|
|
|
return $response; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.