You are here

class SamlauthRequestSubscriber in Acquia Cloud Site Factory Connector 8.2

Same name and namespace in other branches
  1. 8 acsf_sso/src/EventSubscriber/SamlauthRequestSubscriber.php \Drupal\acsf_sso\EventSubscriber\SamlauthRequestSubscriber

Event subscriber that overrides samlauth config on a request event.

Hierarchy

  • class \Drupal\acsf_sso\EventSubscriber\SamlauthRequestSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of SamlauthRequestSubscriber

1 string reference to 'SamlauthRequestSubscriber'
acsf_sso.services.yml in acsf_sso/acsf_sso.services.yml
acsf_sso/acsf_sso.services.yml
1 service uses SamlauthRequestSubscriber
acsf_sso.samlauth_request_subscriber in acsf_sso/acsf_sso.services.yml
Drupal\acsf_sso\EventSubscriber\SamlauthRequestSubscriber

File

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

Namespace

Drupal\acsf_sso\EventSubscriber
View source
class SamlauthRequestSubscriber implements EventSubscriberInterface {

  /**
   * Overrides the samlauth config values to use the correct ones.
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[KernelEvents::REQUEST][] = [
      'injectSamlConfig',
    ];
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SamlauthRequestSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
SamlauthRequestSubscriber::injectSamlConfig public function Overrides the samlauth config values to use the correct ones.