You are here

public function LDAPAuthorizationProvider::sanitizeProposals in Lightweight Directory Access Protocol (LDAP) 8.3

Same name and namespace in other branches
  1. 8.4 ldap_authorization/src/Plugin/authorization/Provider/LDAPAuthorizationProvider.php \Drupal\ldap_authorization\Plugin\authorization\Provider\LDAPAuthorizationProvider::sanitizeProposals()

Sanitize proposals.

Parameters

array $proposals: Raw proposals.

Return value

array Processed proposals.

Overrides ProviderInterface::sanitizeProposals

File

ldap_authorization/src/Plugin/authorization/Provider/LDAPAuthorizationProvider.php, line 238

Class

LDAPAuthorizationProvider
The LDAP authorization provider for authorization module.

Namespace

Drupal\ldap_authorization\Plugin\authorization\Provider

Code

public function sanitizeProposals(array $proposals) {

  // Configure this provider.

  /** @var \Drupal\authorization\Entity\AuthorizationProfile $profile */
  $profile = $this->configuration['profile'];
  $config = $profile
    ->getProviderConfig();
  foreach ($proposals as $key => $authorization_id) {
    if ($config['filter_and_mappings']['use_first_attr_as_groupid']) {
      $attr_parts = Server::ldapExplodeDn($authorization_id, 0);
      if (is_array($attr_parts) && count($attr_parts) > 0) {
        $first_part = explode('=', $attr_parts[0]);
        if (count($first_part) > 1) {

          // @FIXME: Potential bug on trim.
          $authorization_id = ConversionHelper::unescapeDnValue(trim($first_part[1]));
        }
      }
      $new_key = mb_strtolower($authorization_id);
    }
    else {
      $new_key = mb_strtolower($key);
    }
    $proposals[$new_key] = $authorization_id;
    if ($key != $new_key) {
      unset($proposals[$key]);
    }
  }
  return $proposals;
}