Passed
Pull Request — master (#4)
by Tim
02:38
created

Authorize::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 2
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
use Symfony\Component\HttpFoundation\Response;
15
16
/**
17
 * Controller class for the authorize module.
18
 *
19
 * This class serves the different views available in the module.
20
 *
21
 * @package SimpleSAML\Module\authorize
22
 */
23
24
class Authorize
25
{
26
    /** @var \SimpleSAML\Configuration */
27
    protected $config;
28
29
    /** @var \SimpleSAML\Session */
30
    protected $session;
31
32
33
    /**
34
     * Controller constructor.
35
     *
36
     * It initializes the global configuration and auth source configuration for the controllers implemented here.
37
     *
38
     * @param \SimpleSAML\Configuration              $config The configuration to use by the controllers.
39
     * @param \SimpleSAML\Session                    $session The session to use by the controllers.
40
     *
41
     * @throws \Exception
42
     */
43
    public function __construct(
44
        Configuration $config,
45
        Session $session
46
    ) {
47
        $this->config = $config;
48
        $this->session = $session;
49
    }
50
51
52
    /**
53
     * Show a 403 Forbidden page about not authorized to access an application.
54
     *
55
     * @param \Symfony\Component\HttpFoundation\Request $request
56
     * @return \SimpleSAML\XHTML\Template
57
     */
58
    public function forbidden(Request $request): Template
59
    {
60
        $stateId = $request->get('StateId', false);
61
        if ($stateId === false) {
62
            throw new Error\BadRequest('Missing required StateId query parameter.');
63
        }
64
65
        /** @var array $state */
66
        $state = Auth\State::loadState($stateId, 'authorize:Authorize');
67
68
        $t = new Template($this->config, 'authorize:authorize_403.twig');
69
        if (isset($state['Source']['auth'])) {
70
            $t->data['logoutURL'] = Module::getModuleURL(
71
                'core/authenticate.php',
72
                ['as' => $state['Source']['auth']]
73
            ) . "&logout";
74
        }
75
        if (isset($state['authprocAuthorize_reject_msg'])) {
76
            $t->data['reject_msg'] = $state['authprocAuthorize_reject_msg'];
77
        }
78
79
        $t->setStatusCode(Response::HTTP_FORBIDDEN);
80
        return $t;
81
    }
82
}
83