1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\Module\authorize\Controller; |
6
|
|
|
|
7
|
|
|
use SimpleSAML\Auth; |
8
|
|
|
use SimpleSAML\Configuration; |
9
|
|
|
use SimpleSAML\Error; |
10
|
|
|
use SimpleSAML\Module; |
11
|
|
|
use SimpleSAML\Session; |
12
|
|
|
use SimpleSAML\XHTML\Template; |
13
|
|
|
use Symfony\Component\HttpFoundation\Request; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Controller class for the authorize module. |
17
|
|
|
* |
18
|
|
|
* This class serves the different views available in the module. |
19
|
|
|
* |
20
|
|
|
* @package SimpleSAML\Module\authorize |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
class Authorize |
24
|
|
|
{ |
25
|
|
|
/** @var \SimpleSAML\Configuration */ |
26
|
|
|
protected $config; |
27
|
|
|
|
28
|
|
|
/** @var \SimpleSAML\Session */ |
29
|
|
|
protected $session; |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Controller constructor. |
34
|
|
|
* |
35
|
|
|
* It initializes the global configuration and auth source configuration 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
|
|
|
* Show a 403 Forbidden page about not authorized to access an application. |
53
|
|
|
* |
54
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
55
|
|
|
* @return \SimpleSAML\XHTML\Template |
56
|
|
|
*/ |
57
|
|
|
public function forbidden(Request $request): Template |
58
|
|
|
{ |
59
|
|
|
$stateId = $request->get('StateId', false); |
60
|
|
|
if ($stateId === false) { |
61
|
|
|
throw new Error\BadRequest('Missing required StateId query parameter.'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** @var array $state */ |
65
|
|
|
$state = Auth\State::loadState($stateId, 'authorize:Authorize'); |
66
|
|
|
|
67
|
|
|
$t = new Template($this->config, 'authorize:authorize_403.twig'); |
68
|
|
|
if (isset($state['Source']['auth'])) { |
69
|
|
|
$t->data['logoutURL'] = Module::getModuleURL( |
70
|
|
|
'core/authenticate.php', |
71
|
|
|
['as' => $state['Source']['auth']] |
72
|
|
|
) . "&logout"; |
73
|
|
|
} |
74
|
|
|
if (isset($state['authprocAuthorize_reject_msg'])) { |
75
|
|
|
$t->data['reject_msg'] = $state['authprocAuthorize_reject_msg']; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$t->setStatusCode(403); |
79
|
|
|
return $t; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|