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