1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\Module\cdc\Controller; |
6
|
|
|
|
7
|
|
|
use SimpleSAML\Auth; |
8
|
|
|
use SimpleSAML\Configuration; |
9
|
|
|
use SimpleSAML\Error; |
10
|
|
|
use SimpleSAML\HTTP\RunnableResponse; |
11
|
|
|
use SimpleSAML\Module\cdc\Client; |
12
|
|
|
use SimpleSAML\Module\cdc\Server; |
13
|
|
|
use SimpleSAML\Session; |
14
|
|
|
use Symfony\Component\HttpFoundation\Request; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Controller class for the cdc module. |
18
|
|
|
* |
19
|
|
|
* This class serves the different views available in the module. |
20
|
|
|
* |
21
|
|
|
* @package simplesamlphp/simplesamlphp-module-cdc |
22
|
|
|
*/ |
23
|
|
|
class CDC |
24
|
|
|
{ |
25
|
|
|
/** @var \SimpleSAML\Configuration */ |
26
|
|
|
protected Configuration $config; |
27
|
|
|
|
28
|
|
|
/** @var \SimpleSAML\Session */ |
29
|
|
|
protected Session $session; |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Controller constructor. |
34
|
|
|
* |
35
|
|
|
* It initializes the global configuration and session for the controllers implemented here. |
36
|
|
|
* |
37
|
|
|
* @param \SimpleSAML\Configuration $config The configuration to use by the controllers. |
38
|
|
|
* @param \SimpleSAML\Session $session The session to use by the controllers. |
39
|
|
|
* |
40
|
|
|
* @throws \Exception |
41
|
|
|
*/ |
42
|
|
|
public function __construct( |
43
|
|
|
Configuration $config, |
44
|
|
|
Session $session |
45
|
|
|
) { |
46
|
|
|
$this->config = $config; |
47
|
|
|
$this->session = $session; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Server |
53
|
|
|
* |
54
|
|
|
* @return \SimpleSAML\HTTP\RunnableResponse |
55
|
|
|
*/ |
56
|
|
|
public function server(): RunnableResponse |
57
|
|
|
{ |
58
|
|
|
return new RunnableResponse([Server::class, 'processRequest'], []); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Resume |
64
|
|
|
* |
65
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request The current request. |
66
|
|
|
* |
67
|
|
|
* @return \SimpleSAML\HTTP\RunnableResponse |
68
|
|
|
*/ |
69
|
|
|
public function resume(Request $request): RunnableResponse |
70
|
|
|
{ |
71
|
|
|
$domain = $request->get('domain'); |
72
|
|
|
if ($domain === null) { |
73
|
|
|
throw new Error\BadRequest('Missing domain to CDC resume handler.'); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$client = new Client($domain); |
77
|
|
|
|
78
|
|
|
$response = $client->getResponse(); |
79
|
|
|
if ($response === null) { |
80
|
|
|
throw new Error\BadRequest('Missing CDC response to CDC resume handler.'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
if (!isset($response['id'])) { |
84
|
|
|
throw new Error\BadRequest('CDCResponse without id.'); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$state = Auth\State::loadState($response['id'], 'cdc:resume'); |
88
|
|
|
if (is_null($state)) { |
89
|
|
|
throw new Error\NoState(); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return new RunnableResponse([Auth\ProcessingChain::class, 'resumeProcessing'], [$state]); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|