You are here

class AuthenticationServers in Lightweight Directory Access Protocol (LDAP) 8.4

Authentication serves.

Hierarchy

Expanded class hierarchy of AuthenticationServers

1 file declares its use of AuthenticationServers
LoginValidatorBase.php in ldap_authentication/src/Controller/LoginValidatorBase.php
1 string reference to 'AuthenticationServers'
ldap_authentication.services.yml in ldap_authentication/ldap_authentication.services.yml
ldap_authentication/ldap_authentication.services.yml
1 service uses AuthenticationServers
ldap_authentication.servers in ldap_authentication/ldap_authentication.services.yml
Drupal\ldap_authentication\AuthenticationServers

File

ldap_authentication/src/AuthenticationServers.php, line 13

Namespace

Drupal\ldap_authentication
View source
class AuthenticationServers {

  /**
   * Entity Storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $storage;

  /**
   * Config.
   *
   * @var \Drupal\Core\Config\ImmutableConfig
   */
  protected $config;

  /**
   * Constructs a new AuthenticationServers object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   Entity type manager.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   Config factory.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory) {
    $this->storage = $entity_type_manager
      ->getStorage('ldap_server');
    $this->config = $config_factory
      ->get('ldap_authentication.settings');
  }

  /**
   * Authentication servers available.
   *
   * @return bool
   *   Available.
   */
  public function authenticationServersAvailable() : bool {
    if (empty($this
      ->getAvailableAuthenticationServers())) {
      return FALSE;
    }
    return TRUE;
  }

  /**
   * Get available authentication servers.
   *
   * @return array
   *   Server IDs.
   */
  public function getAvailableAuthenticationServers() : array {

    /** @var array $available_servers */
    $available_servers = $this->storage
      ->getQuery()
      ->condition('status', 1)
      ->execute();
    $result = [];
    foreach ($this->config
      ->get('sids') as $configured_server) {
      if (isset($available_servers[$configured_server])) {
        $result[] = $configured_server;
      }
    }
    return $result;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AuthenticationServers::$config protected property Config.
AuthenticationServers::$storage protected property Entity Storage.
AuthenticationServers::authenticationServersAvailable public function Authentication servers available.
AuthenticationServers::getAvailableAuthenticationServers public function Get available authentication servers.
AuthenticationServers::__construct public function Constructs a new AuthenticationServers object.