You are here

class ShibbolethAuthenticationProvider in Shibboleth Authentication 8.4

Class ShibbolethAuthenticationProvider.

@package Drupal\shib_auth\Authentication\Provider

Hierarchy

Expanded class hierarchy of ShibbolethAuthenticationProvider

1 string reference to 'ShibbolethAuthenticationProvider'
shib_auth.services.yml in ./shib_auth.services.yml
shib_auth.services.yml
1 service uses ShibbolethAuthenticationProvider
authentication.shib_auth in ./shib_auth.services.yml
Drupal\shib_auth\Authentication\Provider\ShibbolethAuthenticationProvider

File

src/Authentication/Provider/ShibbolethAuthenticationProvider.php, line 23
Contains Drupal\shib_auth\Authentication\Provider\ShibbolethAuthenticationProvider.

Namespace

Drupal\shib_auth\Authentication\Provider
View source
class ShibbolethAuthenticationProvider implements AuthenticationProviderInterface {

  /**
   * The config factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * The entity manager.
   *
   * @var \Drupal\Core\Entity\EntityManagerInterface
   */
  protected $entityManager;

  /**
   * Constructs a HTTP basic authentication provider object.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory.
   * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
   *   The entity manager service.
   */
  public function __construct(ConfigFactoryInterface $config_factory, EntityManagerInterface $entity_manager) {
    $this->configFactory = $config_factory;
    $this->entityManager = $entity_manager;
  }

  /**
   * {@inheritdoc}
   */
  public function applies(Request $request) {

    // If Authentication Provider is enabled always apply.
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function authenticate(Request $request) {
    $consumer_ip = $request
      ->getClientIp(TRUE);
    if (in_array($consumer_ip, $ips)) {

      // Return Anonymous user.
      return $this->entityManager
        ->getStorage('user')
        ->load(0);
    }
    else {
      throw new AccessDeniedHttpException();
    }
  }

  /**
   * {@inheritdoc}
   */
  public function cleanup(Request $request) {
  }

  /**
   * {@inheritdoc}
   */
  public function handleException(GetResponseForExceptionEvent $event) {
    $exception = $event
      ->getException();
    if ($exception instanceof AccessDeniedHttpException) {
      $event
        ->setException(new UnauthorizedHttpException('Invalid consumer origin.', $exception));
      return TRUE;
    }
    return FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ShibbolethAuthenticationProvider::$configFactory protected property The config factory.
ShibbolethAuthenticationProvider::$entityManager protected property The entity manager.
ShibbolethAuthenticationProvider::applies public function Checks whether suitable authentication credentials are on the request. Overrides AuthenticationProviderInterface::applies
ShibbolethAuthenticationProvider::authenticate public function Authenticates the user. Overrides AuthenticationProviderInterface::authenticate
ShibbolethAuthenticationProvider::cleanup public function
ShibbolethAuthenticationProvider::handleException public function
ShibbolethAuthenticationProvider::__construct public function Constructs a HTTP basic authentication provider object.