1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\SAML\Authenticators; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Control\Controller; |
6
|
|
|
use Silverstripe\Control\Director; |
7
|
|
|
use SilverStripe\Control\HTTPRequest; |
8
|
|
|
use SilverStripe\Control\Session; |
9
|
|
|
use SilverStripe\Core\Config\Config; |
10
|
|
|
use SilverStripe\Core\Injector\Injector; |
11
|
|
|
use SilverStripe\Forms\Form; |
12
|
|
|
use SilverStripe\ORM\ValidationResult; |
13
|
|
|
use SilverStripe\SAML\Control\SAMLController; |
14
|
|
|
use SilverStripe\SAML\Helpers\SAMLHelper; |
15
|
|
|
use SilverStripe\SAML\Middleware\SAMLMiddleware; |
16
|
|
|
use SilverStripe\Security\Authenticator; |
17
|
|
|
use SilverStripe\Security\Member; |
18
|
|
|
use SilverStripe\Security\MemberAuthenticator\MemberAuthenticator; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class SAMLAuthenticator |
22
|
|
|
* |
23
|
|
|
* Authenticates the user against a SAML IdP via a single sign-on process. |
24
|
|
|
* It will create a {@link Member} stub record with rudimentary fields (see {@link SAMLController::acs()}) |
25
|
|
|
* if the Member record was not found. |
26
|
|
|
* |
27
|
|
|
* You can either use: |
28
|
|
|
* - just SAMLAuthenticator (which will trigger LDAP sync anyway, via LDAPMemberExtension::memberLoggedIn) |
29
|
|
|
* - just LDAPAuthenticator (syncs explicitly, but no single sign-on via IdP done) |
30
|
|
|
* - both, so people have multiple tabbed options in the login form. |
31
|
|
|
* |
32
|
|
|
* Both authenticators understand and collaborate through the GUID field on the Member. |
33
|
|
|
*/ |
34
|
|
|
class SAMLAuthenticator extends MemberAuthenticator |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
private $name = 'SAML'; |
|
|
|
|
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
|
|
public static function get_name() |
45
|
|
|
{ |
46
|
|
|
return Config::inst()->get(self::class, 'name'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param Controller $controller |
51
|
|
|
* @return SAMLLoginForm |
52
|
|
|
*/ |
53
|
|
|
public static function get_login_form(Controller $controller) |
54
|
|
|
{ |
55
|
|
|
return new SAMLLoginForm($controller, self::class, 'LoginForm'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* This method does nothing, as all authentication via SAML is handled via HTTP redirects (similar to OAuth) which |
60
|
|
|
* are not supported by the Authenticator system. Authentication via SAML is only triggered when a user hits the |
61
|
|
|
* SAMLController->acs() endpoint when returning from the identity provider. |
62
|
|
|
* |
63
|
|
|
* Instead of calling this method, you should use the SAMLLoginForm, or protect your entire site by enabling the |
64
|
|
|
* SAMLMiddleware. |
65
|
|
|
* |
66
|
|
|
* @param array $data |
67
|
|
|
* @param HTTPRequest $request |
68
|
|
|
* @param ValidationResult|null $result |
69
|
|
|
* @return null |
70
|
|
|
* @see SAMLLoginForm |
71
|
|
|
* @see SAMLMiddleware |
72
|
|
|
*/ |
73
|
|
|
public function authenticate(array $data, HTTPRequest $request, ValidationResult &$result = null) |
74
|
|
|
{ |
75
|
|
|
return null; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @inheritdoc |
80
|
|
|
*/ |
81
|
|
|
public function getLoginHandler($link) |
82
|
|
|
{ |
83
|
|
|
return SAMLLoginHandler::create($link, $this); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @inheritdoc |
88
|
|
|
*/ |
89
|
|
|
public function supportedServices() |
90
|
|
|
{ |
91
|
|
|
return Authenticator::LOGIN | Authenticator::LOGOUT; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|