You are here

class RouteSubscriber in Lightweight Directory Access Protocol (LDAP) 8.4

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

Authentication route subscriber.

@package Drupal\ldap_authentication\Routing

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 17

Namespace

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

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) : void {
    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() : AccessResultInterface {
    $config = \Drupal::config('ldap_authentication.settings');
    if (\Drupal::currentUser()
      ->isAnonymous()) {
      if ($config
        ->get('authenticationMode') === 'mixed') {
        return AccessResult::allowed();
      }

      // Hide reset password for anonymous users if LDAP-only authentication and
      // password updates are disabled, otherwise show.
      if ($config
        ->get('passwordOption') === 'allow') {
        return AccessResult::allowed();
      }
    }
    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