You are here

abstract class Base in DRD Agent 4.0.x

Same name in this branch
  1. 4.0.x src/Crypt/Base.php \Drupal\drd_agent\Crypt\Base
  2. 4.0.x src/Agent/Action/Base.php \Drupal\drd_agent\Agent\Action\Base
  3. 4.0.x src/Agent/Remote/Base.php \Drupal\drd_agent\Agent\Remote\Base
  4. 4.0.x src/Agent/Auth/Base.php \Drupal\drd_agent\Agent\Auth\Base
Same name and namespace in other branches
  1. 8.3 src/Agent/Auth/Base.php \Drupal\drd_agent\Agent\Auth\Base

Base class for Remote DRD Auth Methods.

Hierarchy

Expanded class hierarchy of Base

1 file declares its use of Base
Base.php in src/Agent/Action/Base.php

File

src/Agent/Auth/Base.php, line 14

Namespace

Drupal\drd_agent\Agent\Auth
View source
abstract class Base implements BaseInterface {

  /**
   * All the settings of the implementing authentication method.
   *
   * @var array
   */
  protected $storedSettings;

  /**
   * @var \Drupal\Core\Session\AccountInterface
   */
  protected $currentUser;

  /**
   * @var \Drupal\Core\State\StateInterface
   */
  protected $state;

  /**
   * @var \Drupal\user\UserAuthInterface
   */
  protected $userAuth;

  /**
   * Base constructor.
   *
   * @param \Drupal\Core\Session\AccountInterface $current_User
   * @param \Drupal\Core\State\StateInterface $state
   * @param \Drupal\user\UserAuthInterface $user_auth
   */
  public function __construct(AccountInterface $current_User, StateInterface $state, UserAuthInterface $user_auth) {
    $this->currentUser = $current_User;
    $this->state = $state;
    $this->userAuth = $user_auth;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('current_user'), $container
      ->get('state'), $container
      ->get('user.auth'));
  }

  /**
   * {@inheritdoc}
   */
  public static function getMethods(ContainerInterface $container) : array {
    $methods = array(
      'username_password' => 'UsernamePassword',
      'shared_secret' => 'SharedSecret',
    );
    foreach ($methods as $key => $class) {
      $classname = "\\Drupal\\drd_agent\\Agent\\Auth\\{$class}";

      /** @noinspection PhpUndefinedMethodInspection */
      $methods[$key] = $classname::create($container);
    }
    return $methods;
  }

  /**
   * {@inheritdoc}
   */
  public final function validateUuid($uuid) : bool {
    $authorised = $this->state
      ->get('drd_agent.authorised', []);
    if (empty($authorised[$uuid])) {
      return FALSE;
    }
    $this->storedSettings = (array) $authorised[$uuid]['authsetting'];
    return TRUE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Base::$currentUser protected property
Base::$state protected property
Base::$storedSettings protected property All the settings of the implementing authentication method.
Base::$userAuth protected property
Base::create public static function
Base::getMethods public static function Get a list of all implemented authentication methods. Overrides BaseInterface::getMethods
Base::validateUuid final public function Verify if the given UUID is authorised to access this site. Overrides BaseInterface::validateUuid
Base::__construct public function Base constructor.
BaseInterface::validate public function Validate authentication of the current request with the given settings. 2