|
227 | 227 |
|
228 | 228 | ); |
229 | 229 |
|
| 230 | + |
| 231 | +//////////////////////////////////////////////////////////////////////////////// |
| 232 | +// The "EntraID mock" IdP. |
| 233 | +// |
| 234 | +// This second hosted IdP emulates an EntraID (AzureAD) IdP for the Stepup-AzureMFA GSSP |
| 235 | +// It is served under a second base path (/entra-mock/) under the same hostname. |
| 236 | +// |
| 237 | +// Properties: |
| 238 | +// - No SSO: the IdP uses its own authsource ('entra-mock-userpass', see authsources.php), |
| 239 | +// and the AzureMFA SP is configured with ForceAuthn in saml20-sp-remote.php, so every |
| 240 | +// AuthnRequest at this IdP results in its login page. |
| 241 | +// - No Subject handling is required: EntraID-style AuthnRequests (institutions with |
| 242 | +// is_azure_ad: true) carry no Subject at all and SimpleSAMLphp does not need one. |
| 243 | +// ADFS-style AuthnRequests that do carry a Subject are simply ignored. |
| 244 | +// - AuthnRequests from the AzureMFA SP are signed; a valid signature is required and is |
| 245 | +// validated against the certificate configured for that SP in saml20-sp-remote.php. |
| 246 | +// - Assertions are signed with entra-mock-idp.key; AzureMFA validates them against |
| 247 | +// entra-mock-idp.crt. These key/cert files are not part of this repository, they are |
| 248 | +// provided in the cert dir (mounted from OpenConext-devconf/stepup/ssp in devconf). |
| 249 | +// |
| 250 | +// The institutions.yaml of the AzureMFA service in OpenConext-devconf should point to: |
| 251 | +// entity_id: https://ssp.dev.openconext.local/entra-mock/saml2/idp/metadata.php |
| 252 | +// sso_location: https://ssp.dev.openconext.local/entra-mock/module.php/saml/idp/singleSignOnService |
| 253 | +// certificates: [ entra-mock-idp.crt ] |
| 254 | +// is_azure_ad: true |
| 255 | + |
| 256 | +$entra_mock_authproc = array( |
| 257 | + |
| 258 | + // Generate an unspecified NameID for use by this IdP, using the value of the "NameID" |
| 259 | + // attribute from the authsource as the NameID in the Subject of the SAML Assertion |
| 260 | + 1 => array( |
| 261 | + 'class' => 'saml:AttributeNameID', |
| 262 | + 'attribute' => 'NameID', |
| 263 | + 'identifyingAttribute' => 'NameID', |
| 264 | + 'Format' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified', |
| 265 | + |
| 266 | + // Don't add NameQualifier and SPNameQualifier attributes to the generated NameID |
| 267 | + 'NameQualifier' => FALSE, |
| 268 | + 'SPNameQualifier' => FALSE, |
| 269 | + ), |
| 270 | + |
| 271 | + // Simulate a user cancelling the authentication at the (mock) EntraID (the "cancel" |
| 272 | + // account): send a SAML error response (Responder / AuthnFailed) to the SP (AzureMFA), |
| 273 | + // using the same responder SimpleSAMLphp uses for authentication errors. (A plain |
| 274 | + // "throw" would not work here: with ForceAuthn the authproc runs after the login |
| 275 | + // completed, where an exception would only result in an error page, not a SAML response.) |
| 276 | + 2 => array( |
| 277 | + 'class' => 'core:PHP', |
| 278 | + 'code' => ' |
| 279 | + if (isset($attributes["uid"][0]) && $attributes["uid"][0] === "cancel") { |
| 280 | + \SimpleSAML\Module\saml\IdP\SAML2::handleAuthError( |
| 281 | + new \SimpleSAML\Module\saml\Error( |
| 282 | + \SAML2\Constants::STATUS_RESPONDER, |
| 283 | + \SAML2\Constants::STATUS_AUTHN_FAILED, |
| 284 | + "Authentication cancelled by user" |
| 285 | + ), |
| 286 | + $state |
| 287 | + ); |
| 288 | + } |
| 289 | + ', |
| 290 | + ), |
| 291 | + |
| 292 | + // Remove the NameID attribute from the attributes, so that it is not released as an |
| 293 | + // attribute (it would be renamed to internal-collabPersonId by the AttributeMap below) |
| 294 | + 5 => array( |
| 295 | + 'class' => 'core:AttributeAlter', |
| 296 | + 'subject' => 'NameID', |
| 297 | + 'pattern' => '/.*/', |
| 298 | + '%remove', |
| 299 | + ), |
| 300 | + |
| 301 | + // AzureMFA validates that the mail attribute in the response contains the email |
| 302 | + // address the user registered with. Use the email address generated for the account |
| 303 | + // (eduPersonPrincipalName, i.e. uid@schacHomeOrganization), e.g. jane-a1@institution-a.example.com |
| 304 | + 7 => array( |
| 305 | + 'class' => 'core:PHP', |
| 306 | + 'code' => ' |
| 307 | + if (isset($attributes["eduPersonPrincipalName"][0])) { |
| 308 | + $attributes["mail"] = array($attributes["eduPersonPrincipalName"][0]); |
| 309 | + } |
| 310 | + ', |
| 311 | + ), |
| 312 | + |
| 313 | + // Convert "short" attribute names (uid, mail, ...) to their long urn:mace... equivalent. |
| 314 | + // The map is defined in sspattributemap/Openconext_short_to_urn.php |
| 315 | + 10 => array( |
| 316 | + 'class' => 'core:AttributeMap', |
| 317 | + 'Openconext_short_to_urn' |
| 318 | + ), |
| 319 | + |
| 320 | + // EntraID marks an MFA authentication with this attribute; AzureMFA requires it in the |
| 321 | + // response for institutions with is_azure_ad: true |
| 322 | + 20 => array( |
| 323 | + 'class' => 'core:AttributeAdd', |
| 324 | + 'http://schemas.microsoft.com/claims/authnmethodsreferences' => array('http://schemas.microsoft.com/claims/multipleauthn'), |
| 325 | + ), |
| 326 | +); |
| 327 | + |
| 328 | +$metadata['https://ssp.dev.openconext.local/entra-mock/saml2/idp/metadata.php'] = array( |
| 329 | + // Select this IdP for requests under the /entra-mock/ base path (host + path) |
| 330 | + 'host' => 'ssp.dev.openconext.local/entra-mock', |
| 331 | + |
| 332 | + // Set the endpoints explicitly: 'host' contains a path, so the auto-generated |
| 333 | + // endpoints would end up with the path twice |
| 334 | + 'SingleSignOnService' => 'https://ssp.dev.openconext.local/entra-mock/module.php/saml/idp/singleSignOnService', |
| 335 | + 'SingleSignOnServiceBinding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect', |
| 336 | + 'SingleLogoutService' => 'https://ssp.dev.openconext.local/entra-mock/module.php/saml/idp/singleLogout', |
| 337 | + 'SingleLogoutServiceBinding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect', |
| 338 | + |
| 339 | + 'signature.algorithm' => 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256', |
| 340 | + |
| 341 | + /* X.509 key and certificate of the mock IdP. Relative to the cert directory. |
| 342 | + * These files are not part of this repository; they are provided in the cert dir |
| 343 | + * (mounted from OpenConext-devconf/stepup/ssp in the devconf setup). |
| 344 | + */ |
| 345 | + 'privatekey' => 'entra-mock-idp.key', |
| 346 | + 'certificate' => 'entra-mock-idp.crt', |
| 347 | + |
| 348 | + // Dedicated authsource: no SSO with the main IdP (see authsources.php) |
| 349 | + 'auth' => 'entra-mock-userpass', |
| 350 | + |
| 351 | + // The AzureMFA SP signs its AuthnRequests; require and validate the signature |
| 352 | + 'redirect.validate' => TRUE, |
| 353 | + 'validate.authnrequest' => TRUE, |
| 354 | + |
| 355 | + // Sign the assertion (AzureMFA validates the assertion signature), not the response |
| 356 | + 'saml20.sign.response' => FALSE, |
| 357 | + 'saml20.sign.assertion' => TRUE, |
| 358 | + |
| 359 | + // No artifact binding support |
| 360 | + 'saml20.sendartifact' => FALSE, |
| 361 | + |
| 362 | + 'attributes.NameFormat' => 'urn:oasis:names:tc:SAML:2.0:attrname-format:uri', |
| 363 | + |
| 364 | + // Use an unspecified NameID. The NameID is generated in the authproc above. |
| 365 | + // This is the NameID that will be put in the Subject of the SAML Assertion |
| 366 | + 'NameIDFormat' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified', |
| 367 | + |
| 368 | + 'authproc' => array_merge($entra_mock_authproc, $attribute_authority_authproc), |
| 369 | + |
| 370 | +); |
| 371 | + |
0 commit comments