1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\ActiveDirectory\Authenticators; |
4
|
|
|
|
5
|
|
|
use SilverStripe\ActiveDirectory\Helpers\SAMLHelper; |
6
|
|
|
use SilverStripe\Control\Controller; |
7
|
|
|
use Silverstripe\Control\Director; |
8
|
|
|
use SilverStripe\Control\HTTPRequest; |
9
|
|
|
use SilverStripe\Control\Session; |
10
|
|
|
use SilverStripe\Core\Config\Config; |
11
|
|
|
use SilverStripe\Core\Injector\Injector; |
12
|
|
|
use SilverStripe\Forms\Form; |
13
|
|
|
use SilverStripe\ORM\ValidationResult; |
14
|
|
|
use SilverStripe\Security\Authenticator; |
15
|
|
|
use SilverStripe\Security\Member; |
16
|
|
|
use SilverStripe\Security\MemberAuthenticator\LoginHandler; |
17
|
|
|
use SilverStripe\Security\MemberAuthenticator\LogoutHandler; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class SAMLAuthenticator |
21
|
|
|
* |
22
|
|
|
* Authenticates the user against a SAML IdP via a single sign-on process. |
23
|
|
|
* It will create a {@link Member} stub record with rudimentary fields (see {@link SAMLController::acs()}) |
24
|
|
|
* if the Member record was not found. |
25
|
|
|
* |
26
|
|
|
* You can either use: |
27
|
|
|
* - just SAMLAuthenticator (which will trigger LDAP sync anyway, via LDAPMemberExtension::memberLoggedIn) |
28
|
|
|
* - just LDAPAuthenticator (syncs explicitly, but no single sign-on via IdP done) |
29
|
|
|
* - both, so people have multiple tabbed options in the login form. |
30
|
|
|
* |
31
|
|
|
* Both authenticators understand and collaborate through the GUID field on the Member. |
32
|
|
|
* |
33
|
|
|
* @package activedirectory |
34
|
|
|
*/ |
35
|
|
|
class SAMLAuthenticator implements Authenticator |
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
private $name = 'SAML'; |
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return string |
44
|
|
|
*/ |
45
|
|
|
public static function get_name() |
46
|
|
|
{ |
47
|
|
|
return Config::inst()->get(self::class, 'name'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param Controller $controller |
52
|
|
|
* @return SAMLLoginForm |
53
|
|
|
*/ |
54
|
|
|
public static function get_login_form(Controller $controller) |
55
|
|
|
{ |
56
|
|
|
return new SAMLLoginForm($controller, 'LoginForm'); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Sends the authentication process down the SAML rabbit hole. It will trigger |
61
|
|
|
* the IdP redirection via the 3rd party implementation, and if successful, the user |
62
|
|
|
* will be delivered to the SAMLController::acs. |
63
|
|
|
* |
64
|
|
|
* @param array $data |
65
|
|
|
* @param HTTPRequest $request |
66
|
|
|
* @param ValidationResult|null $result |
67
|
|
|
* @return bool|Member|void |
68
|
|
|
* @internal param Form $form |
69
|
|
|
*/ |
70
|
|
|
public function authenticate(array $data, HTTPRequest $request, ValidationResult &$result = null) |
71
|
|
|
{ |
72
|
|
|
// $data is not used - the form is just one button, with no fields. |
73
|
|
|
$auth = Injector::inst()->get(SAMLHelper::class)->getSAMLAuth(); |
74
|
|
|
$request->getSession()->set('BackURL', isset($data['BackURL']) ? $data['BackURL'] : null); |
75
|
|
|
$request->getSession()->save($request); |
76
|
|
|
$auth->login(Director::absoluteBaseURL().'saml/'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Returns the services supported by this authenticator |
81
|
|
|
* |
82
|
|
|
* The number should be a bitwise-OR of 1 or more of the following constants: |
83
|
|
|
* Authenticator::LOGIN, Authenticator::LOGOUT, Authenticator::CHANGE_PASSWORD, |
84
|
|
|
* Authenticator::RESET_PASSWORD, or Authenticator::CMS_LOGIN |
85
|
|
|
* |
86
|
|
|
* @return int |
87
|
|
|
*/ |
88
|
|
|
public function supportedServices() |
89
|
|
|
{ |
90
|
|
|
// TODO: Implement supportedServices() method. |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Return RequestHandler to manage the log-in process. |
95
|
|
|
* |
96
|
|
|
* The default URL of the RequestHandler should return the initial log-in form, any other |
97
|
|
|
* URL may be added for other steps & processing. |
98
|
|
|
* |
99
|
|
|
* URL-handling methods may return an array [ "Form" => (form-object) ] which can then |
100
|
|
|
* be merged into a default controller. |
101
|
|
|
* |
102
|
|
|
* @param string $link The base link to use for this RequestHandler |
103
|
|
|
* @return LoginHandler |
104
|
|
|
*/ |
105
|
|
|
public function getLoginHandler($link) |
106
|
|
|
{ |
107
|
|
|
// TODO: Implement getLoginHandler() method. |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Return the RequestHandler to manage the log-out process. |
112
|
|
|
* |
113
|
|
|
* The default URL of the RequestHandler should log the user out immediately and destroy the session. |
114
|
|
|
* |
115
|
|
|
* @param string $link The base link to use for this RequestHandler |
116
|
|
|
* @return LogoutHandler |
117
|
|
|
*/ |
118
|
|
|
public function getLogOutHandler($link) |
119
|
|
|
{ |
120
|
|
|
// TODO: Implement getLogOutHandler() method. |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Return RequestHandler to manage the change-password process. |
125
|
|
|
* |
126
|
|
|
* The default URL of the RequetHandler should return the initial change-password form, |
127
|
|
|
* any other URL may be added for other steps & processing. |
128
|
|
|
* |
129
|
|
|
* URL-handling methods may return an array [ "Form" => (form-object) ] which can then |
130
|
|
|
* be merged into a default controller. |
131
|
|
|
* |
132
|
|
|
* @param string $link The base link to use for this RequestHnadler |
133
|
|
|
*/ |
134
|
|
|
public function getChangePasswordHandler($link) |
135
|
|
|
{ |
136
|
|
|
// TODO: Implement getChangePasswordHandler() method. |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @param string $link |
141
|
|
|
* @return mixed |
142
|
|
|
*/ |
143
|
|
|
public function getLostPasswordHandler($link) |
144
|
|
|
{ |
145
|
|
|
// TODO: Implement getLostPasswordHandler() method. |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Check if the passed password matches the stored one (if the member is not locked out). |
150
|
|
|
* |
151
|
|
|
* Note, we don't return early, to prevent differences in timings to give away if a member |
152
|
|
|
* password is invalid. |
153
|
|
|
* |
154
|
|
|
* @param Member $member |
155
|
|
|
* @param string $password |
156
|
|
|
* @param ValidationResult $result |
157
|
|
|
* @return ValidationResult |
158
|
|
|
*/ |
159
|
|
|
public function checkPassword(Member $member, $password, ValidationResult &$result = null) |
160
|
|
|
{ |
161
|
|
|
// TODO: Implement checkPassword() method. |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.