SAMLLoginHandler   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 28
c 1
b 0
f 0
dl 0
loc 113
rs 10
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A login() 0 4 1
A doLogin() 0 4 2
A loginForm() 0 6 1
A Link() 0 5 1
A getHelper() 0 3 1
A setHelper() 0 4 1
1
<?php
2
3
namespace SilverStripe\SAML\Authenticators;
4
5
use SilverStripe\Control\Controller;
6
use SilverStripe\Control\HTTPRequest;
7
use SilverStripe\Control\HTTPResponse;
8
use SilverStripe\Control\HTTPResponse_Exception;
9
use SilverStripe\Control\RequestHandler;
10
use SilverStripe\SAML\Helpers\SAMLHelper;
11
12
class SAMLLoginHandler extends RequestHandler
13
{
14
    private static $url_handlers = [
0 ignored issues
show
introduced by
The private property $url_handlers is not used, and could be removed.
Loading history...
15
        '' => 'login',
16
    ];
17
18
    private static $allowed_actions = [
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
19
        'login',
20
        'LoginForm'
21
    ];
22
23
    private static $dependencies = [
0 ignored issues
show
introduced by
The private property $dependencies is not used, and could be removed.
Loading history...
24
        'helper' => '%$' . SAMLHelper::class
25
    ];
26
27
    /**
28
     * @var SAMLAuthenticator
29
     */
30
    protected $authenticator;
31
32
    /**
33
     * @var SAMLHelper
34
     */
35
    protected $helper;
36
37
    /**
38
     * Link to this handler
39
     *
40
     * @var string
41
     */
42
    protected $link = null;
43
44
    /**
45
     * @param string $link The URL to recreate this request handler
46
     * @param SAMLAuthenticator $authenticator The authenticator to use
47
     */
48
    public function __construct($link, SAMLAuthenticator $authenticator)
49
    {
50
        $this->link = $link;
51
        $this->authenticator = $authenticator;
52
        parent::__construct();
53
    }
54
55
    /**
56
     * URL handler for the log-in screen
57
     *
58
     * @return array
59
     */
60
    public function login()
61
    {
62
        return [
63
            'Form' => $this->loginForm(),
64
        ];
65
    }
66
67
    public function loginForm()
68
    {
69
        return SAMLLoginForm::create(
70
            $this,
71
            get_class($this->authenticator),
72
            'LoginForm'
73
        );
74
    }
75
76
    /**
77
     * Return a link to this request handler.
78
     * The link returned is supplied in the constructor
79
     *
80
     * @param null|string $action
81
     * @return string
82
     */
83
    public function Link($action = null)
84
    {
85
        $link = Controller::join_links($this->link, $action);
86
        $this->extend('updateLink', $link, $action);
87
        return $link;
88
    }
89
90
    /**
91
     * Login form handler method
92
     *
93
     * This method is called when the user finishes the login flow
94
     *
95
     * @param array $data Submitted data
96
     * @param SAMLLoginForm $form
97
     * @param HTTPRequest $request
98
     * @return void This method never returns anything - it just redirects the user to the IdP
99
     * @throws HTTPResponse_Exception
100
     */
101
    public function doLogin($data, SAMLLoginForm $form, HTTPRequest $request)
0 ignored issues
show
Unused Code introduced by
The parameter $form is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

101
    public function doLogin($data, /** @scrutinizer ignore-unused */ SAMLLoginForm $form, HTTPRequest $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
102
    {
103
        $backURL = (isset($data['BackURL']) ? $data['BackURL'] : null);
104
        $this->helper->redirect($this, $request, $backURL);
105
    }
106
107
    /**
108
     * @return SAMLHelper
109
     */
110
    public function getHelper()
111
    {
112
        return $this->helper;
113
    }
114
115
    /**
116
     * Sets the SAMLHelper that this login handler should use to redirect users to the IdP
117
     *
118
     * @param SAMLHelper $helper
119
     * @return $this
120
     */
121
    public function setHelper(SAMLHelper $helper)
122
    {
123
        $this->helper = $helper;
124
        return $this;
125
    }
126
}
127