You are here

class ApigeeAuthKeyType in Apigee Edge 8

Key type for Apigee Edge authentication credentials.

Plugin annotation


@KeyType(
  id = "apigee_auth",
  label = @Translation("Apigee Edge Authentication"),
  description = @Translation("Key type to use for Apigee Edge authentication credentials."),
  group = "apigee_edge",
  key_value = {
    "plugin" = "apigee_auth_input"
  },
  multivalue = {
    "enabled" = true,
    "fields" = {
      "instance_type" = {
        "label" = @Translation("Instance type"),
        "required" = false
      },
      "auth_type" = {
        "label" = @Translation("Authentication type"),
        "required" = false
      },
      "organization" = {
        "label" = @Translation("Organization"),
        "required" = true
      },
      "username" = {
        "label" = @Translation("Username"),
        "required" = false
      },
      "password" = {
        "label" = @Translation("Password"),
        "required" = false
      },
      "endpoint" = {
        "label" = @Translation("Apigee Edge endpoint"),
        "required" = false
      },
      "authorization_server" = {
        "label" = @Translation("Authorization server"),
        "required" = false
      },
      "client_id" = {
        "label" = @Translation("Client ID"),
        "required" = false
      },
      "client_secret" = {
        "label" = @Translation("Client secret"),
        "required" = false
      },
      "account_json_key" = {
        "label" = @Translation("Account JSON key"),
        "required" = false
      },
      "gcp_hosted" = {
        "label" = @Translation("Use default service account if hosted on GCP"),
        "required" = false
      }
    }
  }
)

Hierarchy

Expanded class hierarchy of ApigeeAuthKeyType

1 file declares its use of ApigeeAuthKeyType
KeyEntityFormEnhancer.php in src/KeyEntityFormEnhancer.php

File

src/Plugin/KeyType/ApigeeAuthKeyType.php, line 94

Namespace

Drupal\apigee_edge\Plugin\KeyType
View source
class ApigeeAuthKeyType extends EdgeKeyTypeBase {

  /**
   * {@inheritdoc}
   */
  public static function generateKeyValue(array $configuration) {
    return '[]';
  }

  /**
   * {@inheritdoc}
   */
  public function validateKeyValue(array $form, FormStateInterface $form_state, $key_value) {
    if (empty($key_value)) {
      return;
    }
    $value = $this
      ->unserialize($key_value);
    if ($value === NULL) {
      $form_state
        ->setError($form, $this
        ->t('The key value does not contain valid JSON: @error', [
        '@error' => json_last_error_msg(),
      ]));
      return;
    }
    foreach ($this
      ->getPluginDefinition()['multivalue']['fields'] as $id => $field) {
      if (isset($field['required']) && !$field['required']) {
        continue;
      }
      $error_element = $form['settings']['input_section']['key_input_settings'][$id] ?? $form;
      if (!isset($value[$id])) {
        $form_state
          ->setError($error_element, $this
          ->t('The key value is missing the field %field.', [
          '%field' => $field['label']
            ->render(),
        ]));
      }
      elseif (empty($value[$id])) {
        $form_state
          ->setError($error_element, $this
          ->t('The key value field %field is empty.', [
          '%field' => $field['label']
            ->render(),
        ]));
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getAuthenticationMethod(KeyInterface $key) : Authentication {
    $values = $key
      ->getKeyValues();
    if ($this
      ->getInstanceType($key) === EdgeKeyTypeInterface::INSTANCE_TYPE_HYBRID) {
      if ($this
        ->useGcpDefaultServiceAccount($key)) {
        return new GceServiceAccountAuthentication(\Drupal::service('apigee_edge.authentication.oauth_token_storage'));
      }
      else {
        $account_key = $this
          ->getAccountKey($key);
        return new HybridAuthentication($account_key['client_email'], $account_key['private_key'], \Drupal::service('apigee_edge.authentication.oauth_token_storage'));
      }
    }
    elseif ($values['auth_type'] === EdgeKeyTypeInterface::EDGE_AUTH_TYPE_OAUTH) {

      // Use Oauth authentication.
      return new OauthAuthentication($this
        ->getUsername($key), $this
        ->getPassword($key), \Drupal::service('apigee_edge.authentication.oauth_token_storage'), NULL, $this
        ->getClientId($key), $this
        ->getClientSecret($key), NULL, $this
        ->getAuthorizationServer($key));
    }
    else {

      // Use basic authentication.
      return new BasicAuth($this
        ->getUsername($key), $this
        ->getPassword($key));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ApigeeAuthKeyType::generateKeyValue public static function Generate a key value of this type using the submitted configuration. Overrides KeyTypeInterface::generateKeyValue
ApigeeAuthKeyType::getAuthenticationMethod public function Gets the authentication method object. Overrides KeyTypeAuthenticationMethodInterface::getAuthenticationMethod
ApigeeAuthKeyType::validateKeyValue public function Allows the Key Type plugin to validate the key value. Overrides KeyTypeInterface::validateKeyValue
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
EdgeKeyTypeBase::getAccountKey public function Return the JSON account key decoded as an array. Overrides EdgeKeyTypeInterface::getAccountKey
EdgeKeyTypeBase::getAuthenticationType public function Gets the authentication type. Overrides EdgeKeyTypeInterface::getAuthenticationType
EdgeKeyTypeBase::getAuthorizationServer public function Gets the authorization server. Overrides EdgeKeyTypeInterface::getAuthorizationServer
EdgeKeyTypeBase::getClientId public function Gets the client ID. Overrides EdgeKeyTypeInterface::getClientId
EdgeKeyTypeBase::getClientSecret public function Gets the client secret. Overrides EdgeKeyTypeInterface::getClientSecret
EdgeKeyTypeBase::getEndpoint public function Gets the API endpoint. Overrides EdgeKeyTypeInterface::getEndpoint
EdgeKeyTypeBase::getEndpointType public function Gets the API endpoint type (default or custom). Overrides EdgeKeyTypeInterface::getEndpointType
EdgeKeyTypeBase::getInstanceType public function Gets the instance type (public, private or hybrid). Overrides EdgeKeyTypeInterface::getInstanceType
EdgeKeyTypeBase::getOrganization public function Gets the API organization. Overrides EdgeKeyTypeInterface::getOrganization
EdgeKeyTypeBase::getPassword public function Gets the API password. Overrides EdgeKeyTypeInterface::getPassword
EdgeKeyTypeBase::getUsername public function Gets the API username. Overrides EdgeKeyTypeInterface::getUsername
EdgeKeyTypeBase::serialize public function Serialize an array of key values into a string. Overrides KeyTypeMultivalueInterface::serialize
EdgeKeyTypeBase::unserialize public function Unserialize a string of key values into an array. Overrides KeyTypeMultivalueInterface::unserialize
EdgeKeyTypeBase::useGcpDefaultServiceAccount public function Return if you should use the Default Service account. Overrides EdgeKeyTypeInterface::useGcpDefaultServiceAccount
EdgeKeyTypeInterface::EDGE_AUTH_TYPE_BASIC constant ID of the basic authentication method.
EdgeKeyTypeInterface::EDGE_AUTH_TYPE_DEFAULT_GCE_SERVICE_ACCOUNT constant
EdgeKeyTypeInterface::EDGE_AUTH_TYPE_JWT constant ID of the JWT authentication method.
EdgeKeyTypeInterface::EDGE_AUTH_TYPE_OAUTH constant ID of the OAuth authentication method.
EdgeKeyTypeInterface::EDGE_ENDPOINT_TYPE_CUSTOM Deprecated constant The endpoint type for custom.
EdgeKeyTypeInterface::EDGE_ENDPOINT_TYPE_DEFAULT Deprecated constant The endpoint type for default.
EdgeKeyTypeInterface::INSTANCE_TYPE_HYBRID public constant Apigee instance on hybrid cloud.
EdgeKeyTypeInterface::INSTANCE_TYPE_PRIVATE public constant Apigee instance on private cloud.
EdgeKeyTypeInterface::INSTANCE_TYPE_PUBLIC public constant Apigee instance on public cloud.
KeyPluginBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
KeyPluginBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 1
KeyPluginBase::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurableInterface::defaultConfiguration 8
KeyPluginBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
KeyPluginBase::getPluginType public function Returns the type of plugin. Overrides KeyPluginInterface::getPluginType
KeyPluginBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
KeyPluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct
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.