|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\SAML\Authenticators; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Control\RequestHandler; |
|
6
|
|
|
use SilverStripe\Forms\FieldList; |
|
7
|
|
|
use SilverStripe\Forms\HiddenField; |
|
8
|
|
|
use SilverStripe\Forms\FormAction; |
|
9
|
|
|
use SilverStripe\Security\LoginForm; |
|
10
|
|
|
use SilverStripe\Security\Security; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class SAMLLoginForm |
|
14
|
|
|
* |
|
15
|
|
|
* This not very interesting in itself. It's pretty much boiler-plate code to access the authenticator. |
|
16
|
|
|
*/ |
|
17
|
|
|
class SAMLLoginForm extends LoginForm |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* This field is used in the "You are logged in as %s" message |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
public $loggedInAsField = 'FirstName'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $authenticator_class = SAMLAuthenticator::class; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* The name of this login form, to display in the frontend |
|
32
|
|
|
* Replaces Authenticator::get_name() |
|
33
|
|
|
* |
|
34
|
|
|
* @return string |
|
35
|
|
|
*/ |
|
36
|
|
|
public function getAuthenticatorName() |
|
37
|
|
|
{ |
|
38
|
|
|
return _t(__CLASS__ . '.AUTHENTICATORNAME', 'SAML'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Constructor |
|
43
|
|
|
* |
|
44
|
|
|
* @param RequestHandler $controller |
|
45
|
|
|
* @param string $authenticatorClass @deprecated this argument is not used, can be removed in next major release |
|
46
|
|
|
* @param string $name method on the $controller |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct(RequestHandler $controller, $authenticatorClass, $name) |
|
49
|
|
|
{ |
|
50
|
|
|
$backURL = $this->getSession()->get('BackURL'); |
|
51
|
|
|
|
|
52
|
|
|
if (!empty($this->getRequest()->requestVar('BackURL'))) { |
|
53
|
|
|
$backURL = $this->getRequest()->requestVar('BackURL'); |
|
54
|
|
|
} |
|
55
|
|
|
if ($this->shouldShowLogoutFields()) { |
|
56
|
|
|
$fields = FieldList::create([ |
|
57
|
|
|
HiddenField::create('AuthenticationMethod', null, $this->authenticator_class, $this) |
|
58
|
|
|
]); |
|
59
|
|
|
$actions = FieldList::create([ |
|
60
|
|
|
FormAction::create( |
|
61
|
|
|
'logout', |
|
62
|
|
|
_t('SilverStripe\\Security\\Member.BUTTONLOGINOTHER', 'Log in as someone else') |
|
63
|
|
|
) |
|
64
|
|
|
]); |
|
65
|
|
|
} else { |
|
66
|
|
|
$fields = $this->getFormFields(); |
|
67
|
|
|
$actions = $this->getFormActions(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
if ($backURL) { |
|
71
|
|
|
$fields->push(HiddenField::create('BackURL', 'BackURL', $backURL)); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$this->setFormMethod('POST', true); |
|
75
|
|
|
|
|
76
|
|
|
parent::__construct($controller, $name, $fields, $actions); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
protected function getFormFields() |
|
80
|
|
|
{ |
|
81
|
|
|
return FieldList::create([ |
|
82
|
|
|
HiddenField::create('AuthenticationMethod', null, $this->authenticator_class, $this) |
|
83
|
|
|
]); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
protected function getFormActions() |
|
87
|
|
|
{ |
|
88
|
|
|
return FieldList::create([ |
|
89
|
|
|
FormAction::create('dologin', _t('SilverStripe\\Security\\Member.BUTTONLOGIN', 'Log in')) |
|
90
|
|
|
]); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @return bool |
|
95
|
|
|
*/ |
|
96
|
|
|
protected function shouldShowLogoutFields() |
|
97
|
|
|
{ |
|
98
|
|
|
if (!Security::getCurrentUser()) { |
|
99
|
|
|
return false; |
|
100
|
|
|
} |
|
101
|
|
|
return true; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|