You are here

class RouteSubscriber in Lightweight Directory Access Protocol (LDAP) 8.3

Same name and namespace in other branches
  1. 8.4 ldap_authentication/src/Routing/RouteSubscriber.php \Drupal\ldap_authentication\Routing\RouteSubscriber

Class RouteSubscriber.

@package Drupal\ldap_authentication\Routing Listens to the dynamic route events.

Hierarchy

  • class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of RouteSubscriber

1 string reference to 'RouteSubscriber'
ldap_authentication.services.yml in ldap_authentication/ldap_authentication.services.yml
ldap_authentication/ldap_authentication.services.yml
1 service uses RouteSubscriber
ldap_authentication.route_subscriber in ldap_authentication/ldap_authentication.services.yml
Drupal\ldap_authentication\Routing\RouteSubscriber

File

ldap_authentication/src/Routing/RouteSubscriber.php, line 16

Namespace

Drupal\ldap_authentication\Routing
View source
class RouteSubscriber extends RouteSubscriberBase {

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
    if ($route = $collection
      ->get('user.pass')) {
      $route
        ->setRequirement('_custom_access', '\\Drupal\\ldap_authentication\\Routing\\RouteSubscriber::validateResetPasswordAllowed');
    }
  }

  /**
   * Checks whether password reset is allowed.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   Show password or not.
   */
  public static function validateResetPasswordAllowed() {
    $user = \Drupal::currentUser();
    if ($user
      ->isAnonymous()) {
      if (\Drupal::config('ldap_authentication.settings')
        ->get('authenticationMode') == LdapAuthenticationConfiguration::MODE_MIXED) {
        return AccessResult::allowed();
      }

      // Hide reset password for anonymous users if LDAP-only authentication and
      // password updates are disabled, otherwise show.
      if (\Drupal::config('ldap_authentication.settings')
        ->get('passwordOption') == LdapAuthenticationConfiguration::$passwordFieldAllow) {
        return AccessResult::allowed();
      }
      else {
        return AccessResult::forbidden();
      }
    }
    else {
      return AccessResult::forbidden();
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RouteSubscriber::alterRoutes protected function Alters existing routes for a specific collection. Overrides RouteSubscriberBase::alterRoutes
RouteSubscriber::validateResetPasswordAllowed public static function Checks whether password reset is allowed.
RouteSubscriberBase::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to. 5
RouteSubscriberBase::onAlterRoutes public function Delegates the route altering to self::alterRoutes(). 1