You are here

public function SamlauthRequestSubscriber::injectSamlConfig in Acquia Cloud Site Factory Connector 8

Same name and namespace in other branches
  1. 8.2 acsf_sso/src/EventSubscriber/SamlauthRequestSubscriber.php \Drupal\acsf_sso\EventSubscriber\SamlauthRequestSubscriber::injectSamlConfig()

Overrides the samlauth config values to use the correct ones.

File

acsf_sso/src/EventSubscriber/SamlauthRequestSubscriber.php, line 17

Class

SamlauthRequestSubscriber
Event subscriber that overrides samlauth config on a request event.

Namespace

Drupal\acsf_sso\EventSubscriber

Code

public function injectSamlConfig() {

  // Do this only when on an acsf environment.
  if (!isset($GLOBALS['gardens_site_settings'])) {
    return;
  }
  $sitegroup = $GLOBALS['gardens_site_settings']['site'];
  $env = $GLOBALS['gardens_site_settings']['env'];
  $site_id = $GLOBALS['gardens_site_settings']['conf']['acsf_site_id'];
  $config_overrides = [];

  // If the environment is already live, we do not need to override
  // all samlauth config because it's already been correctly set in
  // the modules install method and the only thing that could change
  // is the sp_entity_id which we override afterwards.
  if (preg_match('/^\\d*live$/', $env) === 0) {
    $site = AcsfSite::load();
    if (empty($site->saml_keys)) {
      $site
        ->initSamlKeyProperties();
    }
    $config_overrides = [
      'idp_entity_id' => $site->factory_url . '/sso/saml2/idp/metadata.php',
      'idp_single_sign_on_service' => $site->factory_url . '/sso/saml2/idp/SSOService.php',
      'idp_single_log_out_service' => $site->factory_url . '/sso/saml2/idp/SingleLogoutService.php',
      'sp_private_key' => $site->saml_keys['sp_private_key'],
      'sp_x509_certificate' => $site->saml_keys['sp_x509_certificate'],
      'idp_x509_certificate' => $site->saml_keys['idp_x509_certificate'],
    ];
  }
  $config_overrides['sp_entity_id'] = "urn:acquia:acsf:saml:sp:{$sitegroup}:{$env}:{$site_id}";
  $GLOBALS['config']['samlauth.authentication'] = $config_overrides;
}