AuthorizeByDest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 19
c 1
b 0
f 0
dl 0
loc 58
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A forbidden() 0 23 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\Module\authorizebydest\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 AuthorizeByDest
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
     * @throws Error\BadRequest
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, 'authorizebydest:AuthorizeByDest');
67
68
        $t = new Template($this->config, 'authorizebydest: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['authprocAuthorizeByDest_reject_msg'])) {
76
            $t->data['reject_msg'] = $state['authprocAuthorizeByDest_reject_msg'];
77
        }
78
79
        $t->setStatusCode(403);
80
        return $t;
81
    }
82
}
83