1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Class SAMLAuthenticator |
4
|
|
|
* |
5
|
|
|
* Authenticates the user against a SAML IdP via a single sign-on process. |
6
|
|
|
* It will create a {@link Member} stub record with rudimentary fields (see {@link SAMLController::acs()}) |
7
|
|
|
* if the Member record was not found. |
8
|
|
|
* |
9
|
|
|
* You can either use: |
10
|
|
|
* - just SAMLAuthenticator (which will trigger LDAP sync anyway, via LDAPMemberExtension::memberLoggedIn) |
11
|
|
|
* - just LDAPAuthenticator (syncs explicitly, but no single sign-on via IdP done) |
12
|
|
|
* - both, so people have multiple tabbed options in the login form. |
13
|
|
|
* |
14
|
|
|
* Both authenticators understand and collaborate through the GUID field on the Member. |
15
|
|
|
*/ |
16
|
|
|
class SAMLAuthenticator extends Authenticator |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
private $name = 'SAML'; |
|
|
|
|
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @return string |
25
|
|
|
*/ |
26
|
|
|
public static function get_name() |
27
|
|
|
{ |
28
|
|
|
return Config::inst()->get('SAMLAuthenticator', 'name'); |
|
|
|
|
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param Controller $controller |
33
|
|
|
* @return SAMLLoginForm |
34
|
|
|
*/ |
35
|
|
|
public static function get_login_form(Controller $controller) |
36
|
|
|
{ |
37
|
|
|
return new SAMLLoginForm($controller, 'LoginForm'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Sends the authentication process down the SAML rabbit hole. It will trigger |
42
|
|
|
* the IdP redirection via the 3rd party implementation, and if successful, the user |
43
|
|
|
* will be delivered to the SAMLController::acs. |
44
|
|
|
* |
45
|
|
|
* @param array $data |
46
|
|
|
* @param Form $form |
47
|
|
|
* @return bool|Member|void |
48
|
|
|
* @throws SS_HTTPResponse_Exception |
49
|
|
|
*/ |
50
|
|
|
public static function authenticate($data, Form $form = null) |
51
|
|
|
{ |
52
|
|
|
// $data is not used - the form is just one button, with no fields. |
53
|
|
|
$auth = Injector::inst()->get('SAMLHelper')->getSAMLAuth(); |
54
|
|
|
Session::set('BackURL', isset($data['BackURL']) ? $data['BackURL'] : null); |
55
|
|
|
Session::save(); |
56
|
|
|
$auth->login(Director::absoluteBaseURL().'saml/'); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.