1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\ActiveDirectory\Services; |
4
|
|
|
|
5
|
|
|
use OneLogin_Saml2_Constants; |
6
|
|
|
use SilverStripe\Core\Object; |
7
|
|
|
use SilverStripe\Control\Director; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class SAMLConfiguration |
11
|
|
|
* |
12
|
|
|
* This object's job is to convert configuration from SilverStripe config system |
13
|
|
|
* into an array that can be consumed by the Onelogin SAML implementation. |
14
|
|
|
* |
15
|
|
|
* The configuration tells the IdP and SP how to establish the circle of trust - i.e. |
16
|
|
|
* how to exchange certificates and which endpoints to use (e.g. see SAMLConfiguration::metadata). |
17
|
|
|
* |
18
|
|
|
* https://syncplicity.zendesk.com/hc/en-us/articles/202392814-Single-sign-on-with-ADFS |
19
|
|
|
* |
20
|
|
|
* @package activedirectory |
21
|
|
|
*/ |
22
|
|
|
class SAMLConfiguration extends Object |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var bool |
26
|
|
|
*/ |
27
|
|
|
private static $strict; |
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var bool |
31
|
|
|
*/ |
32
|
|
|
private static $debug; |
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var array |
36
|
|
|
*/ |
37
|
|
|
private static $SP; |
|
|
|
|
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var array |
41
|
|
|
*/ |
42
|
|
|
private static $IdP; |
|
|
|
|
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return array |
46
|
|
|
*/ |
47
|
|
|
public function asArray() |
48
|
|
|
{ |
49
|
|
|
$conf = []; |
50
|
|
|
|
51
|
|
|
$conf['strict'] = $this->config()->get('strict'); |
52
|
|
|
$conf['debug'] = $this->config()->get('debug'); |
53
|
|
|
|
54
|
|
|
// SERVICE PROVIDER SECTION |
55
|
|
|
$sp = $this->config()->get('SP'); |
56
|
|
|
$spCertPath = Director::is_absolute($sp['x509cert']) |
57
|
|
|
? $sp['x509cert'] |
58
|
|
|
: sprintf('%s/%s', BASE_PATH, $sp['x509cert']); |
59
|
|
|
$spKeyPath = Director::is_absolute($sp['privateKey']) |
60
|
|
|
? $sp['privateKey'] |
61
|
|
|
: sprintf('%s/%s', BASE_PATH, $sp['privateKey']); |
62
|
|
|
|
63
|
|
|
$conf['sp']['entityId'] = $sp['entityId']; |
64
|
|
|
$conf['sp']['assertionConsumerService'] = [ |
65
|
|
|
'url' => $sp['entityId'] . '/saml/acs', |
66
|
|
|
'binding' => OneLogin_Saml2_Constants::BINDING_HTTP_POST |
67
|
|
|
]; |
68
|
|
|
$conf['sp']['NameIDFormat'] = isset($sp['nameIdFormat']) ? $sp['nameIdFormat'] : OneLogin_Saml2_Constants::NAMEID_TRANSIENT; |
69
|
|
|
$conf['sp']['x509cert'] = file_get_contents($spCertPath); |
70
|
|
|
$conf['sp']['privateKey'] = file_get_contents($spKeyPath); |
71
|
|
|
|
72
|
|
|
// IDENTITY PROVIDER SECTION |
73
|
|
|
$idp = $this->config()->get('IdP'); |
74
|
|
|
$conf['idp']['entityId'] = $idp['entityId']; |
75
|
|
|
$conf['idp']['singleSignOnService'] = [ |
76
|
|
|
'url' => $idp['singleSignOnService'], |
77
|
|
|
'binding' => OneLogin_Saml2_Constants::BINDING_HTTP_REDIRECT, |
78
|
|
|
]; |
79
|
|
|
if (isset($idp['singleLogoutService'])) { |
80
|
|
|
$conf['idp']['singleLogoutService'] = [ |
81
|
|
|
'url' => $idp['singleLogoutService'], |
82
|
|
|
'binding' => OneLogin_Saml2_Constants::BINDING_HTTP_REDIRECT, |
83
|
|
|
]; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$idpCertPath = Director::is_absolute($idp['x509cert']) |
87
|
|
|
? $idp['x509cert'] |
88
|
|
|
: sprintf('%s/%s', BASE_PATH, $idp['x509cert']); |
89
|
|
|
$conf['idp']['x509cert'] = file_get_contents($idpCertPath); |
90
|
|
|
|
91
|
|
|
// SECURITY SECTION |
92
|
|
|
$security = $this->config()->get('Security'); |
93
|
|
|
$signatureAlgorithm = $security['signatureAlgorithm']; |
94
|
|
|
|
95
|
|
|
$conf['security'] = [ |
96
|
|
|
/** signatures and encryptions offered */ |
97
|
|
|
// Indicates that the nameID of the <samlp:logoutRequest> sent by this SP will be encrypted. |
98
|
|
|
'nameIdEncrypted' => true, |
99
|
|
|
// Indicates whether the <samlp:AuthnRequest> messages sent by this SP will be signed. [Metadata of the |
100
|
|
|
// SP will offer this info] |
101
|
|
|
'authnRequestsSigned' => true, |
102
|
|
|
// Indicates whether the <samlp:logoutRequest> messages sent by this SP will be signed. |
103
|
|
|
'logoutRequestSigned' => true, |
104
|
|
|
// Indicates whether the <samlp:logoutResponse> messages sent by this SP will be signed. |
105
|
|
|
'logoutResponseSigned' => true, |
106
|
|
|
'signMetadata' => false, |
107
|
|
|
/** signatures and encryptions required **/ |
108
|
|
|
// Indicates a requirement for the <samlp:Response>, <samlp:LogoutRequest> |
109
|
|
|
// and <samlp:LogoutResponse> elements received by this SP to be signed. |
110
|
|
|
'wantMessagesSigned' => false, |
111
|
|
|
// Indicates a requirement for the <saml:Assertion> elements received by |
112
|
|
|
// this SP to be signed. [Metadata of the SP will offer this info] |
113
|
|
|
'wantAssertionsSigned' => true, |
114
|
|
|
// Indicates a requirement for the NameID received by |
115
|
|
|
// this SP to be encrypted. |
116
|
|
|
'wantNameIdEncrypted' => false, |
117
|
|
|
|
118
|
|
|
// Algorithm that the toolkit will use on signing process. Options: |
119
|
|
|
// - 'http://www.w3.org/2000/09/xmldsig#rsa-sha1' |
120
|
|
|
// - 'http://www.w3.org/2000/09/xmldsig#dsa-sha1' |
121
|
|
|
// - 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256' |
122
|
|
|
// - 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha384' |
123
|
|
|
// - 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha512' |
124
|
|
|
'signatureAlgorithm' => $signatureAlgorithm, |
125
|
|
|
|
126
|
|
|
// Authentication context. |
127
|
|
|
// Set to false and no AuthContext will be sent in the AuthNRequest, |
128
|
|
|
// Set true or don't present thi parameter and you will get an AuthContext |
129
|
|
|
// 'exact' 'urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport' |
130
|
|
|
// Set an array with the possible auth context values: |
131
|
|
|
// array ('urn:oasis:names:tc:SAML:2.0:ac:classes:Password', 'urn:oasis:names:tc:SAML:2.0:ac:classes:X509'), |
|
|
|
|
132
|
|
|
'requestedAuthnContext' => [ |
133
|
|
|
'urn:federation:authentication:windows', |
134
|
|
|
'urn:oasis:names:tc:SAML:2.0:ac:classes:Password', |
135
|
|
|
'urn:oasis:names:tc:SAML:2.0:ac:classes:X509', |
136
|
|
|
], |
137
|
|
|
// Indicates if the SP will validate all received xmls. |
138
|
|
|
// (In order to validate the xml, 'strict' and 'wantXMLValidation' must be true). |
139
|
|
|
'wantXMLValidation' => true, |
140
|
|
|
]; |
141
|
|
|
|
142
|
|
|
return $conf; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.