1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\Module\authX509\Controller; |
6
|
|
|
|
7
|
|
|
use SimpleSAML\Auth; |
8
|
|
|
use SimpleSAML\Configuration; |
9
|
|
|
use SimpleSAML\Error; |
10
|
|
|
use SimpleSAML\HTTP\RunnableResponse; |
11
|
|
|
use SimpleSAML\Logger; |
12
|
|
|
use SimpleSAML\Module; |
13
|
|
|
use SimpleSAML\Module\authX509\Auth\Source\X509userCert; |
14
|
|
|
use SimpleSAML\Session; |
15
|
|
|
use SimpleSAML\XHTML\Template; |
16
|
|
|
use Symfony\Component\HttpFoundation\Request; |
17
|
|
|
use Symfony\Component\HttpFoundation\Response; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Controller class for the authx509 module. |
21
|
|
|
* |
22
|
|
|
* This class serves the different views available in the module. |
23
|
|
|
* |
24
|
|
|
* @package simplesamlphp/simplesamlphp-module-authx509 |
25
|
|
|
*/ |
26
|
|
|
class ExpiryWarning |
27
|
|
|
{ |
28
|
|
|
/** @var \SimpleSAML\Configuration */ |
29
|
|
|
protected Configuration $config; |
30
|
|
|
|
31
|
|
|
/** @var \SimpleSAML\Session */ |
32
|
|
|
protected Session $session; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var \SimpleSAML\Auth\State|string |
36
|
|
|
* @psalm-var \SimpleSAML\Auth\State|class-string |
37
|
|
|
*/ |
38
|
|
|
protected $authState = Auth\State::class; |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Controller constructor. |
43
|
|
|
* |
44
|
|
|
* It initializes the global configuration and session for the controllers implemented here. |
45
|
|
|
* |
46
|
|
|
* @param \SimpleSAML\Configuration $config The configuration to use by the controllers. |
47
|
|
|
* @param \SimpleSAML\Session $session The session to use by the controllers. |
48
|
|
|
* |
49
|
|
|
* @throws \Exception |
50
|
|
|
*/ |
51
|
|
|
public function __construct( |
52
|
|
|
Configuration $config, |
53
|
|
|
Session $session |
54
|
|
|
) { |
55
|
|
|
$this->config = $config; |
56
|
|
|
$this->session = $session; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Inject the \SimpleSAML\Auth\State dependency. |
62
|
|
|
* |
63
|
|
|
* @param \SimpleSAML\Auth\State $authState |
64
|
|
|
*/ |
65
|
|
|
public function setAuthState(Auth\State $authState): void |
66
|
|
|
{ |
67
|
|
|
$this->authState = $authState; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Show expiry warning. |
73
|
|
|
* |
74
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
75
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
76
|
|
|
* @throws \Exception |
77
|
|
|
*/ |
78
|
|
|
public function main(Request $request): Response |
79
|
|
|
{ |
80
|
|
|
Logger::info('AuthX509 - Showing expiry warning to user'); |
81
|
|
|
|
82
|
|
|
$id = $request->query->get('StateId', null); |
83
|
|
|
if ($id === null) { |
84
|
|
|
throw new Error\BadRequest('Missing required StateId query parameter.'); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$state = $this->authState::loadState($id, 'warning:expire'); |
88
|
|
|
|
89
|
|
|
if (is_null($state)) { |
90
|
|
|
throw new Error\NoState(); |
91
|
|
|
} elseif ($request->query->get('proceed', null) !== null) { |
92
|
|
|
// The user has pressed the proceed-button |
93
|
|
|
return new RunnableResponse([Auth\ProcessingChain::class, 'resumeProcessing'], [$state]); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$t = new Template($this->config, 'authX509:X509warning.twig'); |
97
|
|
|
$t->data['target'] = Module::getModuleURL('authX509/expirywarning.php'); |
98
|
|
|
$t->data['data'] = ['StateId' => $id]; |
99
|
|
|
$t->data['daysleft'] = $state['daysleft']; |
100
|
|
|
$t->data['renewurl'] = $state['renewurl']; |
101
|
|
|
$t->data['errorcodes'] = Error\ErrorCodes::getAllErrorCodeMessages(); |
102
|
|
|
return $t; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|