1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Class SAMLSecurityExtension |
4
|
|
|
* |
5
|
|
|
* Extensions to the {@link Security} controller to support {@link SAMLAuthenticator} |
6
|
|
|
*/ |
7
|
|
|
class SAMLSecurityExtension extends Extension |
|
|
|
|
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Will redirect the user directly to the IdP login endpoint if: |
11
|
|
|
* |
12
|
|
|
* 1) the 'SAMLAuthenticator' is the default authenticator |
13
|
|
|
* 2) there isn't a GET param showloginform set to 1 |
14
|
|
|
* 3) the member is not currently logged in |
15
|
|
|
* 4) there are no form messages (errors or notices) |
16
|
|
|
* |
17
|
|
|
* @return void |
18
|
|
|
*/ |
19
|
|
|
public function onBeforeSecurityLogin() |
20
|
|
|
{ |
21
|
|
|
if (Authenticator::get_default_authenticator() != 'SAMLAuthenticator') { |
22
|
|
|
return; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
// by going to the URL Security/login?showloginform=1 we bypass the auto sign on |
26
|
|
|
if ($this->owner->request->getVar('showloginform') == 1) { |
|
|
|
|
27
|
|
|
return; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
// if member is already logged in, don't auto-sign-on, this is most likely because |
31
|
|
|
// of unsufficient permissions. |
32
|
|
|
$member = Member::currentUser(); |
33
|
|
|
if ($member && $member->exists()) { |
34
|
|
|
return; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
// if there are form messages, don't auto-sign-on, this is most likely because of |
38
|
|
|
// login errors / failures or other notices. |
39
|
|
|
if (Session::get('FormInfo')) { |
40
|
|
|
// since FormInfo can be a "nulled" array, we have to check |
41
|
|
|
foreach (Session::get('FormInfo') as $form => $info) { |
42
|
|
|
foreach ($info as $name => $value) { |
43
|
|
|
if ($value !== null) { |
44
|
|
|
return; |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$backURL = Session::get('BackURL'); |
51
|
|
|
if ($this->owner->request->getVar('BackURL')) { |
52
|
|
|
$backURL = $this->owner->request->getVar('BackURL'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$authenticator = Injector::inst()->create('SAMLAuthenticator'); |
56
|
|
|
$authenticator->authenticate(["BackURL" => $backURL]); |
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.