You are here

class Anonymous in Entity Share 8.3

Provides Anonymous authorization.

Plugin annotation


@ClientAuthorization(
  id = "anonymous",
  label = @Translation("Anonymous"),
)

Hierarchy

Expanded class hierarchy of Anonymous

1 string reference to 'Anonymous'
ChannelForm::getAuthorizedUsersOptions in modules/entity_share_server/src/Form/ChannelForm.php
Helper function.

File

modules/entity_share_client/src/Plugin/ClientAuthorization/Anonymous.php, line 18

Namespace

Drupal\entity_share_client\Plugin\ClientAuthorization
View source
class Anonymous extends ClientAuthorizationPluginBase {

  /**
   * {@inheritdoc}
   */
  public function checkIfAvailable() {
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function getClient($url) {
    $options = [
      'base_uri' => $url . '/',
      'cookies' => TRUE,
      'allow_redirects' => TRUE,
    ];
    $credentials = $this->keyService
      ->getCredentials($this);
    if (!empty($credentials['username']) && !empty($credentials['password'])) {
      $options['auth'] = [
        $credentials['username'],
        $credentials['password'],
      ];
    }
    return $this->httpClientFactory
      ->fromOptions($options);
  }

  /**
   * {@inheritdoc}
   */
  public function getJsonApiClient($url) {
    $options = [
      'base_uri' => $url . '/',
      'headers' => [
        'Content-type' => 'application/vnd.api+json',
      ],
    ];
    $credentials = $this->keyService
      ->getCredentials($this);
    if (!empty($credentials['username']) && !empty($credentials['password'])) {
      $options['auth'] = [
        $credentials['username'],
        $credentials['password'],
      ];
    }
    return $this->httpClientFactory
      ->fromOptions($options);
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildConfigurationForm($form, $form_state);
    $credentials = $this->keyService
      ->getCredentials($this);
    $form['entity_share']['#description'] = $this
      ->t('Leave empty if the server website is not protected via HTTP Password.');
    $form['entity_share']['username'] = [
      '#type' => 'textfield',
      '#required' => FALSE,
      '#title' => $this
        ->t('Username'),
      '#default_value' => $credentials['username'] ?? '',
    ];
    $form['entity_share']['password'] = [
      '#type' => 'password',
      '#required' => FALSE,
      '#title' => $this
        ->t('Password'),
      '#default_value' => $credentials['password'] ?? '',
    ];
    if ($this->keyService
      ->additionalProviders()) {
      $this
        ->expandedProviderOptions($form);
      $form['key']['id']['#key_filters'] = [
        'type' => 'entity_share_basic_auth',
      ];
      $form['key']['id']['#description'] = $this
        ->t('Select the key you have configured to hold the HTTP Password credentials.');
    }
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {

    // To prevent validation from parent::validateConfigurationForm() as
    // credentials is not required.
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Anonymous::buildConfigurationForm public function Form constructor. Overrides ClientAuthorizationPluginBase::buildConfigurationForm
Anonymous::checkIfAvailable public function Returns true if the plugin method is supported. Overrides ClientAuthorizationInterface::checkIfAvailable
Anonymous::getClient public function Prepares a guzzle client for http operations with the supported auth. Overrides ClientAuthorizationInterface::getClient
Anonymous::getJsonApiClient public function Prepares a guzzle client for JSON operations with the supported auth. Overrides ClientAuthorizationInterface::getJsonApiClient
Anonymous::validateConfigurationForm public function Form validation handler. Overrides ClientAuthorizationPluginBase::validateConfigurationForm
ClientAuthorizationInterface::LOCAL_STORAGE_KEY_VALUE_COLLECTION constant The collection ID of for authorization config local storage.
ClientAuthorizationPluginBase::$httpClientFactory protected property Injected HTTP client factory.
ClientAuthorizationPluginBase::$keyService protected property Injected key service.
ClientAuthorizationPluginBase::$keyValueStore protected property The key value store to use.
ClientAuthorizationPluginBase::$uuid protected property Injected UUID service.
ClientAuthorizationPluginBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 1
ClientAuthorizationPluginBase::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurableInterface::defaultConfiguration
ClientAuthorizationPluginBase::expandedProviderOptions protected function Helper method to build the credential provider elements of the form.
ClientAuthorizationPluginBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
ClientAuthorizationPluginBase::getCredentialProvider public function Returns the plugin data if it is set, otherwise returns NULL. Overrides ClientAuthorizationInterface::getCredentialProvider
ClientAuthorizationPluginBase::getLabel public function Gets the plugin label. Overrides ClientAuthorizationInterface::getLabel
ClientAuthorizationPluginBase::getStorageKey public function Returns the plugin data if it is set, otherwise returns NULL. Overrides ClientAuthorizationInterface::getStorageKey
ClientAuthorizationPluginBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
ClientAuthorizationPluginBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm 1
ClientAuthorizationPluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.