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