1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\Module\expirycheck\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\Session; |
14
|
|
|
use SimpleSAML\XHTML\Template; |
15
|
|
|
use Symfony\Component\HttpFoundation\Request; |
16
|
|
|
|
17
|
|
|
use function htmlspecialchars; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Controller class for the expirycheck module. |
21
|
|
|
* |
22
|
|
|
* This class serves the different views available in the module. |
23
|
|
|
* |
24
|
|
|
* @package simplesamlphp/simplesamlphp |
25
|
|
|
*/ |
26
|
|
|
class ExpiryCheck |
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
|
|
|
* About to expire. |
73
|
|
|
* |
74
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request The current request. |
75
|
|
|
* |
76
|
|
|
* @return \SimpleSAML\XHTML\Template|\SimpleSAML\HTTP\RunnableResponse |
77
|
|
|
*/ |
78
|
|
|
public function about2expire(Request $request): Template|RunnableResponse |
79
|
|
|
{ |
80
|
|
|
Logger::info('expirycheck - User has been warned that NetID is near to expirational date.'); |
81
|
|
|
|
82
|
|
|
$stateId = $request->query->get('StateId'); |
83
|
|
|
if ($stateId === null) { |
84
|
|
|
throw new Error\BadRequest('Missing required StateId query parameter.'); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$state = $this->authState::loadState($stateId, 'expirywarning:about2expire'); |
88
|
|
|
|
89
|
|
|
if ($request->query->get('yes') !== null) { |
90
|
|
|
// The user has pressed the yes-button |
91
|
|
|
return new RunnableResponse([Auth\ProcessingChain::class, 'resumeProcessing'], [$state]); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$t = new Template($this->config, 'expirycheck:about2expire.twig'); |
95
|
|
|
$t->data['autofocus'] = 'yesbutton'; |
96
|
|
|
$t->data['yesTarget'] = Module::getModuleURL('expirycheck/about2expire'); |
97
|
|
|
$t->data['yesData'] = ['StateId' => $stateId]; |
98
|
|
|
$t->data['daysleft'] = $state['daysleft']; |
99
|
|
|
$t->data['expireOnDate'] = $state['expireOnDate']; |
100
|
|
|
$t->data['netId'] = htmlspecialchars($state['netId']); |
101
|
|
|
|
102
|
|
|
return $t; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Expired. |
108
|
|
|
* |
109
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request The current request. |
110
|
|
|
* |
111
|
|
|
* @return \SimpleSAML\XHTML\Template |
112
|
|
|
*/ |
113
|
|
|
public function expired(Request $request): Template |
114
|
|
|
{ |
115
|
|
|
Logger::info('expirycheck - User has been warned that NetID is near to expirational date.'); |
116
|
|
|
|
117
|
|
|
$stateId = $request->query->get('StateId'); |
118
|
|
|
if ($stateId === null) { |
119
|
|
|
throw new Error\BadRequest('Missing required StateId query parameter.'); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
$state = $this->authState::loadState($stateId, 'expirywarning:expired'); |
123
|
|
|
|
124
|
|
|
$t = new Template($this->config, 'expirycheck:expired.twig'); |
125
|
|
|
$t->data['expireOnDate'] = $state['expireOnDate']; |
126
|
|
|
$t->data['netId'] = $state['netId']; |
127
|
|
|
|
128
|
|
|
return $t; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|