[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/joomla/authentication/src/ -> Authentication.php (source)

   1  <?php
   2  /**
   3   * Part of the Joomla Framework Authentication Package
   4   *
   5   * @copyright  Copyright (C) 2005 - 2021 Open Source Matters, Inc. All rights reserved.
   6   * @license    GNU General Public License version 2 or later; see LICENSE
   7   */
   8  
   9  namespace Joomla\Authentication;
  10  
  11  /**
  12   * Joomla Framework Authentication Class
  13   *
  14   * @since  1.0
  15   */
  16  class Authentication
  17  {
  18      /**
  19       * Authentication was successful.
  20       *
  21       * @since  1.0
  22       */
  23      public const SUCCESS = 1;
  24  
  25      /**
  26       * Credentials were provided but they were invalid.
  27       *
  28       * @since  1.0
  29       */
  30      public const INVALID_CREDENTIALS = 2;
  31  
  32      /**
  33       * Credentials were provided but the user did not exist in the credential store.
  34       *
  35       * @since  1.0
  36       */
  37      public const NO_SUCH_USER = 3;
  38  
  39      /**
  40       * There were no credentials found.
  41       *
  42       * @since  1.0
  43       */
  44      public const NO_CREDENTIALS = 4;
  45  
  46      /**
  47       * There were partial credentials found but they were not complete.
  48       *
  49       * @since  1.0
  50       */
  51      public const INCOMPLETE_CREDENTIALS = 5;
  52  
  53      /**
  54       * The array of strategies.
  55       *
  56       * @var    AuthenticationStrategyInterface[]
  57       * @since  1.0
  58       */
  59      private $strategies = [];
  60  
  61      /**
  62       * The array of results.
  63       *
  64       * @var    integer[]
  65       * @since  1.0
  66       */
  67      private $results = [];
  68  
  69      /**
  70       * Register a new strategy
  71       *
  72       * @param   string                           $strategyName  The name to use for the strategy.
  73       * @param   AuthenticationStrategyInterface  $strategy      The authentication strategy object to add.
  74       *
  75       * @return  void
  76       *
  77       * @since   1.0
  78       */
  79  	public function addStrategy($strategyName, AuthenticationStrategyInterface $strategy)
  80      {
  81          $this->strategies[$strategyName] = $strategy;
  82      }
  83  
  84      /**
  85       * Perform authentication
  86       *
  87       * @param   string[]  $strategies  Array of strategies to try - empty to try all strategies.
  88       *
  89       * @return  string|boolean  A string containing a username if authentication is successful, false otherwise.
  90       *
  91       * @since   1.0
  92       * @throws  \RuntimeException
  93       */
  94  	public function authenticate(array $strategies = [])
  95      {
  96          if (empty($strategies))
  97          {
  98              $strategyObjects = $this->strategies;
  99          }
 100          else
 101          {
 102              $strategyObjects = [];
 103  
 104              foreach ($strategies as $strategy)
 105              {
 106                  if (!isset($this->strategies[$strategy]))
 107                  {
 108                      throw new \RuntimeException('Authentication Strategy Not Found');
 109                  }
 110  
 111                  $strategyObjects[$strategy] = $this->strategies[$strategy];
 112              }
 113          }
 114  
 115          if (empty($strategyObjects))
 116          {
 117              throw new \RuntimeException('No strategies have been set');
 118          }
 119  
 120          /** @var AuthenticationStrategyInterface $strategyObject */
 121          foreach ($strategyObjects as $strategy => $strategyObject)
 122          {
 123              $username = $strategyObject->authenticate();
 124  
 125              $this->results[$strategy] = $strategyObject->getResult();
 126  
 127              if (\is_string($username))
 128              {
 129                  return $username;
 130              }
 131          }
 132  
 133          return false;
 134      }
 135  
 136      /**
 137       * Get authentication results.
 138       *
 139       * Use this if you want to get more detailed information about the results of an authentication attempts.
 140       *
 141       * @return  integer[]  An array containing authentication results.
 142       *
 143       * @since   1.0
 144       */
 145  	public function getResults()
 146      {
 147          return $this->results;
 148      }
 149  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer