ExpiryWarning   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

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

3 Methods

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